Bug 28786: (QA follow-up) Upgrade atomicupdate to new style
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tue, 21 Dec 2021 15:07:56 +0000 (15:07 +0000)
committerFridolin Somers <fridolin.somers@biblibre.com>
Thu, 21 Apr 2022 06:43:15 +0000 (20:43 -1000)
Test plan:
Run dbrev again.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
installer/data/mysql/atomicupdate/two-fa.perl [deleted file]
installer/data/mysql/atomicupdate/two-fa.pl [new file with mode: 0755]

diff --git a/installer/data/mysql/atomicupdate/two-fa.perl b/installer/data/mysql/atomicupdate/two-fa.perl
deleted file mode 100644 (file)
index f11c0d0..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-$DBversion = 'XXX'; # will be replaced by the RM
-if( CheckVersion( $DBversion ) ) {
-
-    $dbh->do(q{
-        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
-        ('TwoFactorAuthentication', '0', 'NULL', 'Enables two-factor authentication', 'YesNo')
-    });
-
-    if( !column_exists( 'borrowers', 'secret' ) ) {
-      $dbh->do(q{
-          ALTER TABLE borrowers ADD COLUMN `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA' AFTER `password`
-      });
-    }
-
-    if( !column_exists( 'deletedborrowers', 'secret' ) ) {
-      $dbh->do(q{
-          ALTER TABLE deletedborrowers ADD COLUMN `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA' AFTER `password`
-        });
-    }
-
-    if( !column_exists( 'borrowers', 'auth_method' ) ) {
-      $dbh->do(q{
-          ALTER TABLE borrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
-      });
-    }
-
-    if( !column_exists( 'deletedborrowers', 'auth_method' ) ) {
-      $dbh->do(q{
-          ALTER TABLE deletedborrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
-      });
-    }
-
-    NewVersion( $DBversion, 28786, "Add new syspref TwoFactorAuthentication");
-}
diff --git a/installer/data/mysql/atomicupdate/two-fa.pl b/installer/data/mysql/atomicupdate/two-fa.pl
new file mode 100755 (executable)
index 0000000..06fd394
--- /dev/null
@@ -0,0 +1,39 @@
+use Modern::Perl;
+
+return {
+    bug_number => 28786,
+    description => "Add syspref TwoFactorAuthentication, fields secret and auth_method",
+    up => sub {
+        my ($args) = @_;
+        my ($dbh, $out) = @$args{qw(dbh out)};
+
+        $dbh->do(q{
+            INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+            ('TwoFactorAuthentication', '0', 'NULL', 'Enables two-factor authentication', 'YesNo')
+        });
+
+        if( !column_exists( 'borrowers', 'secret' ) ) {
+          $dbh->do(q{
+              ALTER TABLE borrowers ADD COLUMN `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA' AFTER `password`
+          });
+        }
+
+        if( !column_exists( 'deletedborrowers', 'secret' ) ) {
+          $dbh->do(q{
+              ALTER TABLE deletedborrowers ADD COLUMN `secret` MEDIUMTEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Secret for 2FA' AFTER `password`
+            });
+        }
+
+        if( !column_exists( 'borrowers', 'auth_method' ) ) {
+          $dbh->do(q{
+              ALTER TABLE borrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
+          });
+        }
+
+        if( !column_exists( 'deletedborrowers', 'auth_method' ) ) {
+          $dbh->do(q{
+              ALTER TABLE deletedborrowers ADD COLUMN `auth_method` ENUM('password', 'two-factor') NOT NULL DEFAULT 'password' COMMENT 'Authentication method' AFTER `secret`
+          });
+        }
+    },
+};