migrate4.pl 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env perl
  2. # Migrate to 2FA
  3. use strict;
  4. use warnings;
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use Trog::SQLite;
  8. =head1 SYNOPSIS
  9. Migrate to 2FA.
  10. Adds the totp_secret column to the auth database's user table, which is where
  11. Trog::Auth::totp() stores a user's TOTP secret once they enroll.
  12. =head2 USAGE
  13. bin/migrate4.pl
  14. Run from the tCMS root, as the schema and database paths are relative to it.
  15. =head2 CAVEATS
  16. Historical, and not idempotent -- SQLite will refuse a second ALTER TABLE for a
  17. column which already exists, so re-running it dies rather than doing nothing.
  18. Existing users end up with a NULL secret, which is to say 2FA off, and can
  19. enroll whenever they like.
  20. =cut
  21. sub _dbh {
  22. my $file = 'schema/auth.schema';
  23. my $dbname = "config/auth.db";
  24. return Trog::SQLite::dbh( $file, $dbname );
  25. }
  26. my $dbh = _dbh();
  27. $dbh->do("ALTER TABLE user ADD COLUMN totp_secret TEXT DEFAULT NULL;");