Rework migrations for MySQL

This commit is contained in:
Emil Madsen
2019-05-20 21:12:41 +02:00
parent 85c8a01f4a
commit ab95a69dc8
22 changed files with 154 additions and 321 deletions

View File

@@ -1,15 +1,15 @@
CREATE TABLE twofactor (
uuid TEXT NOT NULL PRIMARY KEY,
user_uuid TEXT NOT NULL REFERENCES users (uuid),
type INTEGER NOT NULL,
uuid VARCHAR(40) NOT NULL PRIMARY KEY,
user_uuid VARCHAR(40) NOT NULL REFERENCES users (uuid),
atype INTEGER NOT NULL,
enabled BOOLEAN NOT NULL,
data TEXT NOT NULL,
UNIQUE (user_uuid, type)
UNIQUE (user_uuid, atype)
);
INSERT INTO twofactor (uuid, user_uuid, type, enabled, data)
SELECT lower(hex(randomblob(16))) , uuid, 0, 1, u.totp_secret FROM users u where u.totp_secret IS NOT NULL;
INSERT INTO twofactor (uuid, user_uuid, atype, enabled, data)
SELECT UUID(), uuid, 0, 1, u.totp_secret FROM users u where u.totp_secret IS NOT NULL;
UPDATE users SET totp_secret = NULL; -- Instead of recreating the table, just leave the columns empty
UPDATE users SET totp_secret = NULL; -- Instead of recreating the table, just leave the columns empty