-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database): implement database migrations
- Loading branch information
Showing
15 changed files
with
198 additions
and
114 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
database/migrations/mysql/20241209010100_create_hm_user_table.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DROP TABLE IF EXISTS hm_user; | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user ( | ||
username VARCHAR(255), | ||
hash VARCHAR(255), | ||
PRIMARY KEY (username) | ||
); |
8 changes: 8 additions & 0 deletions
8
database/migrations/mysql/20241209010200_create_hm_user_session_table.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
DROP TABLE IF EXISTS hm_user_session; | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_session ( | ||
hm_id VARCHAR(255), | ||
data LONGBLOB, | ||
date TIMESTAMP, | ||
PRIMARY KEY (hm_id) | ||
); |
7 changes: 7 additions & 0 deletions
7
database/migrations/mysql/20241209010300_create_hm_user_settings_table.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DROP TABLE IF EXISTS hm_user_settings; | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_settings ( | ||
username VARCHAR(255), | ||
settings LONGBLOB, | ||
PRIMARY KEY (username) | ||
); |
1 change: 1 addition & 0 deletions
1
database/migrations/mysql/20241209040200_add_hm_version_to_hm_user_session_table.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE hm_user_session ADD COLUMN hm_version INT DEFAULT 1; |
12 changes: 12 additions & 0 deletions
12
database/migrations/pgsql/20241209010100_create_hm_user_table.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DROP TABLE IF EXISTS hm_user; | ||
|
||
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 $$; |
13 changes: 13 additions & 0 deletions
13
database/migrations/pgsql/20241209010200_create_hm_user_session_table.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DROP TABLE IF EXISTS hm_user_session; | ||
|
||
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 $$; |
12 changes: 12 additions & 0 deletions
12
database/migrations/pgsql/20241209010300_create_hm_user_settings_table.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DROP TABLE IF EXISTS hm_user_settings; | ||
|
||
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 $$; |
12 changes: 12 additions & 0 deletions
12
database/migrations/pgsql/20241209040200_add_hm_version_to_hm_user_session_table.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.columns | ||
WHERE table_name = 'hm_user_session' | ||
AND column_name = 'hm_version' | ||
) THEN | ||
ALTER TABLE hm_user_session | ||
ADD COLUMN hm_version INT DEFAULT 1; | ||
END IF; | ||
END $$; |
7 changes: 7 additions & 0 deletions
7
database/migrations/sqlite/20241209010100_create_hm_user_table.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DROP TABLE IF EXISTS hm_user; | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user ( | ||
username TEXT NOT NULL, | ||
hash TEXT NOT NULL, | ||
PRIMARY KEY (username) | ||
); |
9 changes: 9 additions & 0 deletions
9
database/migrations/sqlite/20241209010200_create_hm_user_session_table.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
DROP TABLE IF EXISTS hm_user_session; | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_session ( | ||
hm_id TEXT NOT NULL, | ||
data BLOB, | ||
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
PRIMARY KEY (hm_id) | ||
); | ||
|
7 changes: 7 additions & 0 deletions
7
database/migrations/sqlite/20241209010300_create_hm_user_settings_table.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DROP TABLE IF EXISTS hm_user_settings; | ||
|
||
CREATE TABLE IF NOT EXISTS hm_user_settings ( | ||
username TEXT NOT NULL, | ||
settings BLOB, | ||
PRIMARY KEY (username) | ||
); |
18 changes: 18 additions & 0 deletions
18
database/migrations/sqlite/20241209040200_add_hm_version_to_hm_user_session_table.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
PRAGMA foreign_keys=off; | ||
|
||
CREATE TABLE hm_user_session_new ( | ||
hm_id TEXT NOT NULL, | ||
data BLOB, | ||
date TIMESTAMP, | ||
hm_version INTEGER DEFAULT 1, | ||
PRIMARY KEY (hm_id) | ||
); | ||
|
||
INSERT INTO hm_user_session_new (hm_id, data, date) | ||
SELECT hm_id, data, date | ||
FROM hm_user_session; | ||
|
||
DROP TABLE hm_user_session; | ||
ALTER TABLE hm_user_session_new RENAME TO hm_user_session; | ||
|
||
PRAGMA foreign_keys=on; |
19 changes: 19 additions & 0 deletions
19
database/migrations/sqlite/20241209040300_add_lock_to_hm_user_session_table.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
PRAGMA foreign_keys=off; | ||
|
||
CREATE TABLE hm_user_session_new ( | ||
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 | ||
FROM hm_user_session; | ||
|
||
DROP TABLE hm_user_session; | ||
|
||
ALTER TABLE hm_user_session_new RENAME TO hm_user_session; | ||
|
||
PRAGMA foreign_keys=on; |
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