From e30adf8d829e980b04e9167ff9050b8b678c9bcf Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Sun, 17 Aug 2025 22:15:31 -0400 Subject: [PATCH] track migrations, whoops --- .gitignore | 1 - .../migration.sql | 34 +++++++++++++++++++ .../20250809191236_strings/migration.sql | 20 +++++++++++ .../20250809192322_humans/migration.sql | 28 +++++++++++++++ .../migration.sql | 12 +++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 packages/server/db/migrations/20250809034803_strings_are_just_better/migration.sql create mode 100644 packages/server/db/migrations/20250809191236_strings/migration.sql create mode 100644 packages/server/db/migrations/20250809192322_humans/migration.sql create mode 100644 packages/server/db/migrations/20250813041445_names_optional/migration.sql diff --git a/.gitignore b/.gitignore index 7ccf5b7..652716d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .output .vinxi *.db -db # ---> Node # Logs diff --git a/packages/server/db/migrations/20250809034803_strings_are_just_better/migration.sql b/packages/server/db/migrations/20250809034803_strings_are_just_better/migration.sql new file mode 100644 index 0000000..a33e2b2 --- /dev/null +++ b/packages/server/db/migrations/20250809034803_strings_are_just_better/migration.sql @@ -0,0 +1,34 @@ +/* + Warnings: + + - The primary key for the `Game` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `id` on the `Game` table. All the data in the column will be lost. + - You are about to drop the column `gameId` on the `Instance` table. All the data in the column will be lost. + - Added the required column `key` to the `Game` table without a default value. This is not possible if the table is not empty. + - Added the required column `gameKey` to the `Instance` table without a default value. This is not possible if the table is not empty. + +*/ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Game" ( + "key" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "name" TEXT NOT NULL, + "rules" TEXT +); +INSERT INTO "new_Game" ("createdAt", "name", "rules", "updatedAt") SELECT "createdAt", "name", "rules", "updatedAt" FROM "Game"; +DROP TABLE "Game"; +ALTER TABLE "new_Game" RENAME TO "Game"; +CREATE TABLE "new_Instance" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "gameKey" TEXT NOT NULL, + "gameState" JSONB NOT NULL, + CONSTRAINT "Instance_gameKey_fkey" FOREIGN KEY ("gameKey") REFERENCES "Game" ("key") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_Instance" ("gameState", "id") SELECT "gameState", "id" FROM "Instance"; +DROP TABLE "Instance"; +ALTER TABLE "new_Instance" RENAME TO "Instance"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/packages/server/db/migrations/20250809191236_strings/migration.sql b/packages/server/db/migrations/20250809191236_strings/migration.sql new file mode 100644 index 0000000..0701d21 --- /dev/null +++ b/packages/server/db/migrations/20250809191236_strings/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - The primary key for the `Instance` table will be changed. If it partially fails, the table could be left without primary key constraint. + +*/ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Instance" ( + "id" TEXT NOT NULL PRIMARY KEY, + "gameKey" TEXT NOT NULL, + "gameState" JSONB NOT NULL, + CONSTRAINT "Instance_gameKey_fkey" FOREIGN KEY ("gameKey") REFERENCES "Game" ("key") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_Instance" ("gameKey", "gameState", "id") SELECT "gameKey", "gameState", "id" FROM "Instance"; +DROP TABLE "Instance"; +ALTER TABLE "new_Instance" RENAME TO "Instance"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/packages/server/db/migrations/20250809192322_humans/migration.sql b/packages/server/db/migrations/20250809192322_humans/migration.sql new file mode 100644 index 0000000..d7d52cc --- /dev/null +++ b/packages/server/db/migrations/20250809192322_humans/migration.sql @@ -0,0 +1,28 @@ +/* + Warnings: + + - Added the required column `createdByKey` to the `Instance` table without a default value. This is not possible if the table is not empty. + +*/ +-- CreateTable +CREATE TABLE "Human" ( + "key" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL +); + +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Instance" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdByKey" TEXT NOT NULL, + "gameKey" TEXT NOT NULL, + "gameState" JSONB NOT NULL, + CONSTRAINT "Instance_createdByKey_fkey" FOREIGN KEY ("createdByKey") REFERENCES "Human" ("key") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "Instance_gameKey_fkey" FOREIGN KEY ("gameKey") REFERENCES "Game" ("key") ON DELETE RESTRICT ON UPDATE CASCADE +); +INSERT INTO "new_Instance" ("gameKey", "gameState", "id") SELECT "gameKey", "gameState", "id" FROM "Instance"; +DROP TABLE "Instance"; +ALTER TABLE "new_Instance" RENAME TO "Instance"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/packages/server/db/migrations/20250813041445_names_optional/migration.sql b/packages/server/db/migrations/20250813041445_names_optional/migration.sql new file mode 100644 index 0000000..2df6ca0 --- /dev/null +++ b/packages/server/db/migrations/20250813041445_names_optional/migration.sql @@ -0,0 +1,12 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Human" ( + "key" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL DEFAULT '' +); +INSERT INTO "new_Human" ("key", "name") SELECT "key", "name" FROM "Human"; +DROP TABLE "Human"; +ALTER TABLE "new_Human" RENAME TO "Human"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF;