-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(migration): refactor migration process
- Loading branch information
Showing
17 changed files
with
206 additions
and
177 deletions.
There are no files selected for viewing
7 changes: 0 additions & 7 deletions
7
database/migrations/mysql/20241209010100_create_hm_user_table.sql
This file was deleted.
Oops, something went wrong.
File renamed without changes.
8 changes: 0 additions & 8 deletions
8
database/migrations/mysql/20241209010200_create_hm_user_session_table.sql
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
database/migrations/mysql/20241209010300_create_hm_user_settings_table.sql
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
database/migrations/pgsql/20241209010100_create_hm_user_table.sql
This file was deleted.
Oops, something went wrong.
File renamed without changes.
13 changes: 0 additions & 13 deletions
13
database/migrations/pgsql/20241209010200_create_hm_user_session_table.sql
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
database/migrations/pgsql/20241209010300_create_hm_user_settings_table.sql
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
database/migrations/sqlite/20241209010100_create_hm_user_table.sql
This file was deleted.
Oops, something went wrong.
12 changes: 7 additions & 5 deletions
12
...300_add_lock_to_hm_user_session_table.sql → ...qlite/20241209010200_add_lock_columns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
PRAGMA foreign_keys=off; | ||
|
||
CREATE TABLE hm_user_session_new ( | ||
hm_id TEXT PRIMARY KEY, | ||
data BLOB, | ||
date TIMESTAMP, | ||
hm_id TEXT PRIMARY KEY, | ||
data BLOB, | ||
date TIMESTAMP, | ||
hm_version INTEGER DEFAULT 1, | ||
lock INTEGER DEFAULT 0 | ||
); | ||
|
||
INSERT INTO hm_user_session_new (hm_id, data, date, hm_version) | ||
SELECT hm_id, data, date, hm_version | ||
INSERT INTO hm_user_session_new (hm_id, data, date, hm_version, lock) | ||
SELECT hm_id, data, date, 1, 0 | ||
FROM hm_user_session; | ||
|
||
DROP TABLE hm_user_session; | ||
|
||
-- Rename the new table to match the old table name | ||
ALTER TABLE hm_user_session_new RENAME TO hm_user_session; | ||
|
||
-- Re-enable foreign key checks | ||
PRAGMA foreign_keys=on; |
9 changes: 0 additions & 9 deletions
9
database/migrations/sqlite/20241209010200_create_hm_user_session_table.sql
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
database/migrations/sqlite/20241209010300_create_hm_user_settings_table.sql
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
database/migrations/sqlite/20241209040200_add_hm_version_to_hm_user_session_table.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE IF NOT EXISTS hm_user ( | ||
username VARCHAR(255), | ||
hash VARCHAR(255), | ||
PRIMARY KEY (username) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_session ( | ||
hm_id VARCHAR(255), | ||
data LONGBLOB, | ||
date TIMESTAMP, | ||
PRIMARY KEY (hm_id) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_settings ( | ||
username VARCHAR(255), | ||
settings LONGBLOB, | ||
PRIMARY KEY (username) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables | ||
WHERE table_name = 'hm_user') THEN | ||
CREATE TABLE hm_user ( | ||
username VARCHAR(255) PRIMARY KEY, | ||
hash VARCHAR(255) | ||
); | ||
END IF; | ||
END $$; | ||
|
||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables | ||
WHERE table_name = 'hm_user_session') THEN | ||
CREATE TABLE hm_user_session ( | ||
hm_id VARCHAR(255) PRIMARY KEY, | ||
data BYTEA, | ||
date TIMESTAMP | ||
); | ||
END IF; | ||
END $$; | ||
|
||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables | ||
WHERE table_name = 'hm_user_settings') THEN | ||
CREATE TABLE hm_user_settings ( | ||
username VARCHAR(255) PRIMARY KEY, | ||
settings BYTEA | ||
); | ||
END IF; | ||
END $$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE IF NOT EXISTS hm_user ( | ||
username TEXT NOT NULL, | ||
hash TEXT NOT NULL, | ||
PRIMARY KEY (username) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_session ( | ||
hm_id TEXT NOT NULL, | ||
data BLOB, | ||
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (hm_id) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_settings ( | ||
username TEXT NOT NULL, | ||
settings BLOB, | ||
PRIMARY KEY (username) | ||
); |
Oops, something went wrong.