migrate5.pl 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env perl
  2. # Password reset code
  3. use v5.36;
  4. use re '/aa';
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use Trog::SQLite;
  8. =head1 SYNOPSIS
  9. Password reset code.
  10. Adds the contact_email column to the auth database's user table, without which
  11. there is nowhere to send a password reset to.
  12. =head2 USAGE
  13. bin/migrate5.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 contact email and so can't reset their own
  19. password until one is set. Fix that with bin/tcms-useradd --contact_email.
  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 contact_email TEXT DEFAULT NULL;");