Skip to content

Commit

Permalink
🐛 fix issue deleting connections
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelvalley committed Dec 9, 2023
1 parent b06854a commit 6e40325
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 36 additions & 0 deletions prisma/migrations/20231209201853_remove_editable/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 1 addition & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/commands/connection/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default class Delete extends AppCommand {
const result = await this.sqlqdb.connection.delete({
where: {
alias,
editable: false,
},
})

Expand Down

0 comments on commit 6e40325

Please sign in to comment.