Skip to content

Commit 8e63a4f

Browse files
committed
sql migratiosn
1 parent d535b3b commit 8e63a4f

File tree

6 files changed

+142
-0
lines changed

6 files changed

+142
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- CreateTable
2+
CREATE TABLE "Users" (
3+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
4+
"email" TEXT NOT NULL,
5+
"username" TEXT,
6+
"password" TEXT NOT NULL,
7+
"isAdmin" BOOLEAN NOT NULL DEFAULT false,
8+
"description" TEXT DEFAULT 'No About Me'
9+
);
10+
11+
-- CreateTable
12+
CREATE TABLE "Session" (
13+
"id" TEXT NOT NULL PRIMARY KEY,
14+
"session_id" TEXT NOT NULL,
15+
"data" TEXT NOT NULL,
16+
"expires" DATETIME NOT NULL,
17+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
18+
"updatedAt" DATETIME NOT NULL
19+
);
20+
21+
-- CreateTable
22+
CREATE TABLE "Server" (
23+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
24+
"name" TEXT NOT NULL,
25+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
26+
"ownerId" INTEGER NOT NULL,
27+
"nodeId" INTEGER NOT NULL,
28+
CONSTRAINT "Server_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "Users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
29+
CONSTRAINT "Server_nodeId_fkey" FOREIGN KEY ("nodeId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
30+
);
31+
32+
-- CreateTable
33+
CREATE TABLE "Node" (
34+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
35+
"name" TEXT NOT NULL,
36+
"ram" INTEGER NOT NULL DEFAULT 0,
37+
"cpu" INTEGER NOT NULL DEFAULT 0,
38+
"disk" INTEGER NOT NULL DEFAULT 0,
39+
"address" TEXT NOT NULL DEFAULT '127.0.0.1',
40+
"port" INTEGER NOT NULL DEFAULT 3001,
41+
"key" TEXT NOT NULL,
42+
"apiKey" TEXT NOT NULL DEFAULT '',
43+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
44+
);
45+
46+
-- CreateIndex
47+
CREATE UNIQUE INDEX "Users_email_key" ON "Users"("email");
48+
49+
-- CreateIndex
50+
CREATE UNIQUE INDEX "Session_session_id_key" ON "Session"("session_id");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- CreateTable
2+
CREATE TABLE "Magic_links" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"email" TEXT,
5+
"username" TEXT,
6+
"isAdmin" BOOLEAN NOT NULL DEFAULT false
7+
);
8+
9+
-- CreateIndex
10+
CREATE UNIQUE INDEX "Magic_links_email_key" ON "Magic_links"("email");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `Magic_links` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- DropTable
8+
PRAGMA foreign_keys=off;
9+
DROP TABLE "Magic_links";
10+
PRAGMA foreign_keys=on;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Warnings:
3+
4+
- The required column `UUID` was added to the `Server` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
5+
6+
*/
7+
-- RedefineTables
8+
PRAGMA defer_foreign_keys=ON;
9+
PRAGMA foreign_keys=OFF;
10+
CREATE TABLE "new_Server" (
11+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
12+
"UUID" TEXT NOT NULL,
13+
"name" TEXT NOT NULL,
14+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
15+
"ownerId" INTEGER NOT NULL,
16+
"nodeId" INTEGER NOT NULL,
17+
CONSTRAINT "Server_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "Users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
18+
CONSTRAINT "Server_nodeId_fkey" FOREIGN KEY ("nodeId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
19+
);
20+
INSERT INTO "new_Server" ("createdAt", "id", "name", "nodeId", "ownerId") SELECT "createdAt", "id", "name", "nodeId", "ownerId" FROM "Server";
21+
DROP TABLE "Server";
22+
ALTER TABLE "new_Server" RENAME TO "Server";
23+
CREATE UNIQUE INDEX "Server_UUID_key" ON "Server"("UUID");
24+
PRAGMA foreign_keys=ON;
25+
PRAGMA defer_foreign_keys=OFF;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Warnings:
3+
4+
- Added the required column `Ports` to the `Server` table without a default value. This is not possible if the table is not empty.
5+
6+
*/
7+
-- RedefineTables
8+
PRAGMA defer_foreign_keys=ON;
9+
PRAGMA foreign_keys=OFF;
10+
CREATE TABLE "new_Server" (
11+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
12+
"UUID" TEXT NOT NULL,
13+
"name" TEXT NOT NULL,
14+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
15+
"Ports" TEXT NOT NULL,
16+
"ownerId" INTEGER NOT NULL,
17+
"nodeId" INTEGER NOT NULL,
18+
CONSTRAINT "Server_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "Users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
19+
CONSTRAINT "Server_nodeId_fkey" FOREIGN KEY ("nodeId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
20+
);
21+
INSERT INTO "new_Server" ("UUID", "createdAt", "id", "name", "nodeId", "ownerId") SELECT "UUID", "createdAt", "id", "name", "nodeId", "ownerId" FROM "Server";
22+
DROP TABLE "Server";
23+
ALTER TABLE "new_Server" RENAME TO "Server";
24+
CREATE UNIQUE INDEX "Server_UUID_key" ON "Server"("UUID");
25+
PRAGMA foreign_keys=ON;
26+
PRAGMA defer_foreign_keys=OFF;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- RedefineTables
2+
PRAGMA defer_foreign_keys=ON;
3+
PRAGMA foreign_keys=OFF;
4+
CREATE TABLE "new_Server" (
5+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
6+
"UUID" TEXT NOT NULL,
7+
"name" TEXT NOT NULL,
8+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
9+
"Ports" TEXT NOT NULL,
10+
"Suspended" BOOLEAN NOT NULL DEFAULT false,
11+
"ownerId" INTEGER NOT NULL,
12+
"nodeId" INTEGER NOT NULL,
13+
CONSTRAINT "Server_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "Users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
14+
CONSTRAINT "Server_nodeId_fkey" FOREIGN KEY ("nodeId") REFERENCES "Node" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
15+
);
16+
INSERT INTO "new_Server" ("Ports", "UUID", "createdAt", "id", "name", "nodeId", "ownerId") SELECT "Ports", "UUID", "createdAt", "id", "name", "nodeId", "ownerId" FROM "Server";
17+
DROP TABLE "Server";
18+
ALTER TABLE "new_Server" RENAME TO "Server";
19+
CREATE UNIQUE INDEX "Server_UUID_key" ON "Server"("UUID");
20+
PRAGMA foreign_keys=ON;
21+
PRAGMA defer_foreign_keys=OFF;

0 commit comments

Comments
 (0)