summaryrefslogtreecommitdiffstats
path: root/sql/_common/upgrade
diff options
context:
space:
mode:
authorLibravatarJanik Kleinhoff <ilbelkyr@shalture.org>2017-05-08 02:06:38 +0000
committerLibravatarJanik Kleinhoff <ilbelkyr@shalture.org>2017-05-08 02:25:18 +0000
commit7342c7f0e19e15ab3c7ba2133a56393c15989f08 (patch)
tree5e00a9c2a3164bd49d18ded9263f1ea7ae99d7f6 /sql/_common/upgrade
parent62d8fcde1c6dc5be2f535f6fcffa1afd838b62bd (diff)
Move users to DB
Summary: This will automatically take care of migrating the users from users.json; you may delete that file. Note that this removes htpasswd support. We now store (hashed) user passwords in the database. See T19 for rationale. Test Plan: Run this on a testnet for a while, try to break it. Reviewers: ilbelkyr, #antispammeta Reviewed By: ilbelkyr, #antispammeta Tags: #antispammeta, #database Differential Revision: https://dev.antispammeta.net/D2
Diffstat (limited to 'sql/_common/upgrade')
-rw-r--r--sql/_common/upgrade/3-4/002-convert_users.pl31
1 files changed, 31 insertions, 0 deletions
diff --git a/sql/_common/upgrade/3-4/002-convert_users.pl b/sql/_common/upgrade/3-4/002-convert_users.pl
new file mode 100644
index 0000000..9631345
--- /dev/null
+++ b/sql/_common/upgrade/3-4/002-convert_users.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+use v5.20;
+use warnings;
+
+use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers 'schema_from_schema_loader';
+use Authen::Passphrase::RejectAll;
+
+schema_from_schema_loader({ naming => 'v4' }, sub {
+ my ($schema, $versions) = @_;
+
+ while (my ($name, $user) = each %{ $::users->{person} }) {
+ my %flags;
+ for my $flag (split(//, $user->{flags})) {
+ $flags{$flag} = 1;
+ }
+ $schema->resultset('Users')->create({
+ name => $name,
+ # We don't have the manually adjusted schema, so we need to
+ # pass the raw value for the passphrase column
+ passphrase => Authen::Passphrase::RejectAll->new->as_rfc2307,
+ flag_secret => $flags{s} // 0,
+ flag_admin => $flags{a} // 0,
+ flag_hilights => $flags{h} // 0,
+ flag_debug => $flags{d} // 0,
+ flag_plugin => $flags{p} // 0,
+ });
+ }
+
+ say "NOTE: The data from users.json has been moved to the database.\n"
+ . "You may remove users.json now, although keeping a backup is strongly recommended.";
+ })