Skip to content

Commit

Permalink
refactor(migration): refactor migration process
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow243 committed Jan 8, 2025
1 parent cd0b746 commit 4f169ca
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 177 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions database/migrations/pgsql/20241209010100_create_hm_user_table.sql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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;

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 18 additions & 0 deletions database/mysql_schema.sql
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)
);
33 changes: 33 additions & 0 deletions database/pgsql_schema.sql
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 $$;
18 changes: 18 additions & 0 deletions database/sqlite_schema.sql
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)
);
Loading

0 comments on commit 4f169ca

Please sign in to comment.