Project import generated by Copybara.
GitOrigin-RevId: 63746295f1a5ab5a619056791995793d65529e62
diff --git a/upgradescripts/1_upgradebaixes2history.php b/upgradescripts/1_upgradebaixes2history.php
new file mode 100644
index 0000000..f06c01b
--- /dev/null
+++ b/upgradescripts/1_upgradebaixes2history.php
@@ -0,0 +1,51 @@
+<?php
+// @description: Program used to upgrade the database after the implementation of issue #23.
+
+require_once(__DIR__."/../core.php");
+
+if (php_sapi_name() != "cli") {
+ security::notFound();
+ exit();
+}
+
+echo "=========================\n";
+echo "upgradebaixes2history.php\n";
+echo "=========================\n\n";
+
+// Check whether the database was already upgraded
+$prequery = mysqli_query($con, "SHOW COLUMNS FROM workers LIKE 'hidden'");
+if (!mysqli_num_rows($prequery)) {
+ die("[fatal error] The database was already upgraded.\n");
+}
+
+echo "[info] Adding new database schema...\n";
+if (!mysqli_query($con, "CREATE TABLE workhistory (
+ id INT NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY(id),
+ worker INT NOT NULL,
+ INDEX(worker),
+ day INT NOT NULL,
+ status INT NOT NULL
+)")) die("[fatal error] Couldn't add new database.\n");
+
+echo "[info] Transfering affiliation information from the workers table to the workhistory table...\n";
+$query = mysqli_query($con, "SELECT * FROM workers");
+
+if ($query === false) exit();
+
+while ($worker = mysqli_fetch_assoc($query)) {
+ $sid = (int)$worker["id"];
+ $sday = (int)$worker["lastupdated"];
+ $sstatus = (int)($worker["hidden"] == "1" ? (workers::AFFILIATION_STATUS_AUTO_NOTWORKING) : (workers::AFFILIATION_STATUS_AUTO_WORKING));
+ $sql = "INSERT INTO workhistory (worker, day, status) VALUES ($sid, $sday, $sstatus)";
+ if (!mysqli_query($con, $sql)) {
+ echo "[error] Failed to upgrade ".$worker["id"]."\n";
+ }
+}
+
+echo "[info] Removing the 'hidden' and 'lastupdated' columns from the 'workers' table, and the 'baixa' column from the 'people' table...\n";
+if (!mysqli_query($con, "ALTER TABLE workers DROP hidden")) echo "[error] Failed to remove 'hidden' column from 'workers' table.\n";
+if (!mysqli_query($con, "ALTER TABLE workers DROP lastupdated")) echo "[error] Failed to remove 'lastupdated' column from 'workers' table.\n";
+if (!mysqli_query($con, "ALTER TABLE people DROP baixa")) echo "[error] Failed to remove 'baixa' column from 'people' table.\n";
+
+echo "[info] Done\n";
diff --git a/upgradescripts/2_ratelimitingsignin.php b/upgradescripts/2_ratelimitingsignin.php
new file mode 100644
index 0000000..5b469e5
--- /dev/null
+++ b/upgradescripts/2_ratelimitingsignin.php
@@ -0,0 +1,27 @@
+<?php
+// @description: Program used to upgrade the database after the implementation of issue #39.
+
+require_once(__DIR__."/../core.php");
+
+if (php_sapi_name() != "cli") {
+ security::notFound();
+ exit();
+}
+
+echo "========================\n";
+echo "2_ratelimitingsignin.php\n";
+echo "========================\n\n";
+
+echo "[info] Adding new database schema...\n";
+if (!mysqli_query($con, "CREATE TABLE signinattempts (
+ username VARCHAR(100) NOT NULL,
+ KEY username (username),
+ remoteip VARBINARY(16) NOT NULL,
+ KEY remoteip (remoteip),
+ remoteipblock VARBINARY(16) NOT NULL,
+ KEY remoteipblock (remoteipblock),
+ signinattempttime DATETIME NOT NULL,
+ KEY signinattempttime (signinattempttime)
+)")) die("[fatal error] Couldn't add new database: ".mysqli_error($con)."\n");
+
+echo "[info] Done\n";
diff --git a/upgradescripts/3_peoplednibugfix.php b/upgradescripts/3_peoplednibugfix.php
new file mode 100644
index 0000000..975f57e
--- /dev/null
+++ b/upgradescripts/3_peoplednibugfix.php
@@ -0,0 +1,18 @@
+<?php
+// @description: Program used to upgrade the database to fix a bug which didn't let multiple users have an empty DNI.
+
+require_once(__DIR__."/../core.php");
+
+if (php_sapi_name() != "cli") {
+ security::notFound();
+ exit();
+}
+
+echo "=====================\n";
+echo "3_peoplednibugfix.php\n";
+echo "=====================\n\n";
+
+echo "[info] Removing unique index for field dni in table people...\n";
+if (!mysqli_query($con, "ALTER TABLE people DROP INDEX dni")) die("[fatal error] Couldn't delete index: ".mysqli_error($con)."\n");
+
+echo "[info] Done\n";