summaryrefslogtreecommitdiffstats
path: root/sql/_common/upgrade/3-4/002-convert_users.pl
blob: 9631345cf413be992d2c9f1f35f110982e069130 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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.";
    })