|
| 1 | +DROP INDEX IF EXISTS passwords_unique; |
| 2 | + |
| 3 | +CREATE TABLE IF NOT EXISTS users_migration ( |
| 4 | + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
| 5 | + email TEXT NOT NULL UNIQUE, |
| 6 | + password TEXT NOT NULL |
| 7 | +); |
| 8 | +INSERT INTO users_migration ( |
| 9 | + id, |
| 10 | + email, |
| 11 | + password |
| 12 | +) SELECT id, email, password FROM users; |
| 13 | +DROP TABLE users; |
| 14 | +ALTER TABLE users_migration RENAME TO users; |
| 15 | + |
| 16 | +CREATE TABLE IF NOT EXISTS tokens_migration ( |
| 17 | + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
| 18 | + user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 19 | + token TEXT NOT NULL UNIQUE, |
| 20 | + created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 21 | + modified DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP |
| 22 | +); |
| 23 | +INSERT INTO tokens_migration ( |
| 24 | + id, |
| 25 | + user_id, |
| 26 | + token, |
| 27 | + created, |
| 28 | + modified |
| 29 | +) SELECT id, user_id, token, created, modified FROM tokens; |
| 30 | +DROP TABLE tokens; |
| 31 | +ALTER TABLE tokens_migration RENAME TO tokens; |
| 32 | + |
| 33 | +CREATE TABLE IF NOT EXISTS passwords_migration ( |
| 34 | + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
| 35 | + user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 36 | + login TEXT NOT NULL, |
| 37 | + site TEXT NOT NULL, |
| 38 | + uppercase BOOLEAN NOT NULL DEFAULT TRUE, |
| 39 | + symbols BOOLEAN NOT NULL DEFAULT TRUE, |
| 40 | + lowercase BOOLEAN NOT NULL DEFAULT TRUE, |
| 41 | + numbers BOOLEAN NOT NULL DEFAULT TRUE, |
| 42 | + counter INTEGER NOT NULL DEFAULT 1, |
| 43 | + version INTEGER NOT NULL DEFAULT 2, |
| 44 | + length INTEGER NOT NULL DEFAULT 16, |
| 45 | + created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 46 | + modified DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP |
| 47 | +); |
| 48 | +INSERT INTO passwords_migration ( |
| 49 | + id, |
| 50 | + user_id, |
| 51 | + login, |
| 52 | + site, |
| 53 | + uppercase, |
| 54 | + symbols, |
| 55 | + lowercase, |
| 56 | + numbers, |
| 57 | + counter, |
| 58 | + version, |
| 59 | + length, |
| 60 | + created, |
| 61 | + modified |
| 62 | +) SELECT id, user_id, login, site, uppercase, symbols, lowercase, numbers, counter, version, length, created, modified FROM passwords; |
| 63 | +DROP TABLE passwords; |
| 64 | +ALTER TABLE passwords_migration RENAME TO passwords; |
| 65 | + |
| 66 | +CREATE UNIQUE INDEX IF NOT EXISTS passwords_unique ON passwords (user_id, login, site); |
0 commit comments