diff --git a/package.json b/package.json index 61c2592..4a9aae2 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,8 @@ }, "scripts": { "dev": "yarn run build && node ./bin/run.js", - "build": "shx rm -rf dist && tsc -b", + "build": "tsc -b", "lint": "eslint . --ext .ts", - "postpack": "shx rm -f oclif.manifest.json", "posttest": "yarn lint", "prepack": "yarn build && oclif manifest && yarn run docs", "prepare": "yarn build", diff --git a/prisma/migrations/20231209201853_remove_editable/migration.sql b/prisma/migrations/20231209201853_remove_editable/migration.sql new file mode 100644 index 0000000..2e530a7 --- /dev/null +++ b/prisma/migrations/20231209201853_remove_editable/migration.sql @@ -0,0 +1,36 @@ +/* + Warnings: + + - You are about to drop the column `editable` on the `Connection` table. All the data in the column will be lost. + +*/ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Connection" ( + "alias" TEXT NOT NULL PRIMARY KEY, + "created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "description" TEXT, + "connectionString" TEXT NOT NULL, + "driver" TEXT NOT NULL +); +INSERT INTO "new_Connection" ("alias", "connectionString", "created", "description", "driver", "updated") SELECT "alias", "connectionString", "created", "description", "driver", "updated" FROM "Connection"; +DROP TABLE "Connection"; +ALTER TABLE "new_Connection" RENAME TO "Connection"; +CREATE UNIQUE INDEX "Connection_alias_key" ON "Connection"("alias"); +CREATE TABLE "new_History" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "lastUsed" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "count" INTEGER NOT NULL DEFAULT 1, + "query" TEXT NOT NULL, + "connectionAlias" TEXT NOT NULL, + "success" BOOLEAN NOT NULL, + CONSTRAINT "History_connectionAlias_fkey" FOREIGN KEY ("connectionAlias") REFERENCES "Connection" ("alias") ON DELETE CASCADE ON UPDATE CASCADE +); +INSERT INTO "new_History" ("connectionAlias", "count", "created", "id", "lastUsed", "query", "success") SELECT "connectionAlias", "count", "created", "id", "lastUsed", "query", "success" FROM "History"; +DROP TABLE "History"; +ALTER TABLE "new_History" RENAME TO "History"; +CREATE UNIQUE INDEX "History_query_connectionAlias_key" ON "History"("query", "connectionAlias"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7e4f7d2..1bffbff 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -14,7 +14,6 @@ model Connection { alias String @id @unique created DateTime @default(now()) updated DateTime @default(now()) - editable Boolean @default(true) description String? connectionString String @@ -32,7 +31,7 @@ model History { count Int @default(1) query String - connection Connection @relation(fields: [connectionAlias], references: [alias]) + connection Connection @relation(fields: [connectionAlias], references: [alias], onDelete: Cascade) connectionAlias String success Boolean diff --git a/src/commands/connection/delete.ts b/src/commands/connection/delete.ts index ec61c21..333f764 100644 --- a/src/commands/connection/delete.ts +++ b/src/commands/connection/delete.ts @@ -28,7 +28,6 @@ export default class Delete extends AppCommand { const result = await this.sqlqdb.connection.delete({ where: { alias, - editable: false, }, })