Skip to content

Commit

Permalink
Fixed Database migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Wavesonics committed Sep 20, 2024
1 parent 482a214 commit 8a3827a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sqldelight {
packageName.set("com.darkrockstudios.apps.hammer.database")
//dialect("app.cash.sqldelight:sqlite-3-35-dialect:$sqldelight_version")
version = 2
schemaOutputDirectory.set(project.file("build/generated/sqldelight"))
}
}
}
Expand Down
Binary file modified server/src/main/sqldelight/1.db
Binary file not shown.
38 changes: 22 additions & 16 deletions server/src/main/sqldelight/migrations/1.sqm
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
CREATE TABLE tmp_account (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
email TEXT UNIQUE NOT NULL,
salt TEXT NOT NULL,
password_hash TEXT NOT NULL,
created TEXT DEFAULT (datetime('now')) NOT NULL,
is_admin INTEGER DEFAULT FALSE NOT NULL,
last_sync TEXT DEFAULT (datetime('now')) NOT NULL
);

INSERT INTO tmp_account (id, email, salt, password_hash, created, is_admin)
SELECT id, email, salt, password_hash, created, isAdmin FROM account;

DROP TABLE account;
ALTER TABLE tmp_account RENAME TO account;

ALTER TABLE authToken RENAME TO auth_token;
ALTER TABLE whiteList RENAME TO white_list;

CREATE TABLE project (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
uuid TEXT NOT NULL,
Expand All @@ -11,6 +28,10 @@ CREATE TABLE project (
FOREIGN KEY(user_id) REFERENCES account(id),
UNIQUE(name, user_id)
);

CREATE UNIQUE INDEX user_project_name_lookup
ON project(user_id, name);

CREATE TABLE story_entity (
user_id INTEGER NOT NULL,
project_id INTEGER NOT NULL,
Expand All @@ -27,19 +48,4 @@ CREATE TABLE deleted_project (
name TEXT NOT NULL,
uuid TEXT NOT NULL,
FOREIGN KEY(user_id) REFERENCES account(id)
);


CREATE TABLE account_temp (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
email TEXT UNIQUE NOT NULL,
salt TEXT NOT NULL,
password_hash TEXT NOT NULL,
created TEXT NOT NULL,
is_admin INTEGER AS kotlin.Boolean DEFAULT FALSE NOT NULL,
last_sync TEXT DEFAULT (datetime('now')) NOT NULL
);
INSERT INTO account_temp (id, email, salt, password_hash, created, is_admin)
SELECT id, email, salt, password_hash, created, isAdmin FROM account;
DROP TABLE account;
ALTER TABLE account_temp RENAME TO account;
);

0 comments on commit 8a3827a

Please sign in to comment.