From f836a0a3cd6c4a30594e84465cc17b1f2fce91ae Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Wed, 4 Jan 2023 15:58:15 +0100 Subject: [PATCH] chore: add db migration --- .../20230104145733_v0_5_1/migration.sql | 23 +++++++++++++++++++ backend/test/system/newman-system-tests.json | 21 +++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 backend/prisma/migrations/20230104145733_v0_5_1/migration.sql diff --git a/backend/prisma/migrations/20230104145733_v0_5_1/migration.sql b/backend/prisma/migrations/20230104145733_v0_5_1/migration.sql new file mode 100644 index 00000000..a4d3ac49 --- /dev/null +++ b/backend/prisma/migrations/20230104145733_v0_5_1/migration.sql @@ -0,0 +1,23 @@ +/* + Warnings: + + - The primary key for the `RefreshToken` table will be changed. If it partially fails, the table could be left without primary key constraint. + - The required column `id` was added to the `RefreshToken` 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. + +*/ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_RefreshToken" ( + "id" TEXT NOT NULL PRIMARY KEY, + "token" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "expiresAt" DATETIME NOT NULL, + "userId" TEXT NOT NULL, + CONSTRAINT "RefreshToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); +INSERT INTO "new_RefreshToken" ("createdAt", "expiresAt", "token", "userId") SELECT "createdAt", "expiresAt", "token", "userId" FROM "RefreshToken"; +DROP TABLE "RefreshToken"; +ALTER TABLE "new_RefreshToken" RENAME TO "RefreshToken"; +CREATE UNIQUE INDEX "RefreshToken_token_key" ON "RefreshToken"("token"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/backend/test/system/newman-system-tests.json b/backend/test/system/newman-system-tests.json index c6058c4d..b333479e 100644 --- a/backend/test/system/newman-system-tests.json +++ b/backend/test/system/newman-system-tests.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "84a95987-2997-429a-aba6-d38289b0b76a", + "_postman_id": "4b16228d-41ef-4c6b-8a0b-294a30a4cfc2", "name": "Pingvin Share Testing", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", "_exporter_id": "17822132" @@ -18,12 +18,12 @@ "exec": [ "if(pm.response.to.have.status(201)){", " const token = pm.response.json()[\"accessToken\"]", - " pm.collectionVariables.set(\"USER_AUTH_TOKEN\", token)", - "", " // Get user id", " const jwtPayload = JSON.parse(atob(token.split('.')[1]));", " const userId = jwtPayload[\"sub\"]", " pm.collectionVariables.set(\"USER_ID\", userId)", + "", + " pm.collectionVariables.set(\"COOKIES\", pm.response.headers.get(\"Set-Cookie\"))", "}", "" ], @@ -80,6 +80,7 @@ " pm.expect(responseBody).to.have.property(\"accessToken\")", " pm.expect(responseBody).to.have.property(\"refreshToken\")", "});", + "", "" ], "type": "text/javascript" @@ -97,7 +98,7 @@ ], "body": { "mode": "raw", - "raw": "{\n \"email\": \"system2@test.org\",\n \"username\": \"system.test2\",\n \"password\": \"N44HcHgeuAvfCT\"\n}", + "raw": "{\n \"email\": \"system2@test.org\",\n \"username\": \"system2.test\",\n \"password\": \"N44HcHgeuAvfCT\"\n}", "options": { "raw": { "language": "json" @@ -1556,23 +1557,13 @@ ] } ], - "auth": { - "type": "bearer", - "bearer": [ - { - "key": "token", - "value": "{{USER_AUTH_TOKEN}}", - "type": "string" - } - ] - }, "event": [ { "listen": "prerequest", "script": { "type": "text/javascript", "exec": [ - "" + "pm.request.addHeader(\"Cookie\", pm.collectionVariables.get(\"COOKIES\"))" ] } },