From 46645142127e6e29193b55212011e68b5821c920 Mon Sep 17 00:00:00 2001 From: nehalist Date: Sun, 21 Jan 2024 20:26:19 +0100 Subject: [PATCH] feat: add teamsize column --- drizzle/0009_far_blob.sql | 1 + drizzle/meta/0009_snapshot.json | 667 ++++++++++++++++++++++++++++++++ drizzle/meta/_journal.json | 7 + src/db/index.ts | 6 +- src/db/schema.ts | 1 + src/lib/session.ts | 1 - 6 files changed, 680 insertions(+), 3 deletions(-) create mode 100644 drizzle/0009_far_blob.sql create mode 100644 drizzle/meta/0009_snapshot.json diff --git a/drizzle/0009_far_blob.sql b/drizzle/0009_far_blob.sql new file mode 100644 index 0000000..8db43a9 --- /dev/null +++ b/drizzle/0009_far_blob.sql @@ -0,0 +1 @@ +ALTER TABLE "team" ADD COLUMN "teamsize" integer DEFAULT 1 NOT NULL; \ No newline at end of file diff --git a/drizzle/meta/0009_snapshot.json b/drizzle/meta/0009_snapshot.json new file mode 100644 index 0000000..8027d55 --- /dev/null +++ b/drizzle/meta/0009_snapshot.json @@ -0,0 +1,667 @@ +{ + "id": "604fced3-0dbd-4351-a126-db61e9c439c6", + "prevId": "6131aaa8-6484-475b-ac43-e95b051646d3", + "version": "5", + "dialect": "pg", + "tables": { + "account": { + "name": "account", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "session_state": { + "name": "session_state", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_userId_user_id_fk": { + "name": "account_userId_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "account_provider_providerAccountId_pk": { + "name": "account_provider_providerAccountId_pk", + "columns": [ + "provider", + "providerAccountId" + ] + } + }, + "uniqueConstraints": {} + }, + "feedback": { + "name": "feedback", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "feedback_userId_user_id_fk": { + "name": "feedback_userId_user_id_fk", + "tableFrom": "feedback", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "league": { + "name": "league", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "game": { + "name": "game", + "type": "game", + "primaryKey": false, + "notNull": true, + "default": "'custom'" + }, + "maxScorePerMatch": { + "name": "maxScorePerMatch", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "allowDraws": { + "name": "allowDraws", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "defaultRating": { + "name": "defaultRating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1000 + }, + "ratingSystem": { + "name": "ratingSystem", + "type": "ratingSystem", + "primaryKey": false, + "notNull": true, + "default": "'unknown'" + }, + "ratingSystemParameters": { + "name": "ratingSystemParameters", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{}'::json" + }, + "leagueStatus": { + "name": "leagueStatus", + "type": "leagueStatus", + "primaryKey": false, + "notNull": false, + "default": "'active'" + }, + "inviteCode": { + "name": "inviteCode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "substr(md5(random()::text), 0, 25)" + }, + "ownerId": { + "name": "ownerId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "league_ownerId_user_id_fk": { + "name": "league_ownerId_user_id_fk", + "tableFrom": "league", + "tableTo": "user", + "columnsFrom": [ + "ownerId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "league_inviteCode_unique": { + "name": "league_inviteCode_unique", + "nullsNotDistinct": false, + "columns": [ + "inviteCode" + ] + } + } + }, + "matches": { + "name": "matches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "leagueId": { + "name": "leagueId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "matches_leagueId_league_id_fk": { + "name": "matches_leagueId_league_id_fk", + "tableFrom": "matches", + "tableTo": "league", + "columnsFrom": [ + "leagueId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "session": { + "name": "session", + "schema": "", + "columns": { + "sessionToken": { + "name": "sessionToken", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "session_userId_user_id_fk": { + "name": "session_userId_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "team_member": { + "name": "team_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "teamId": { + "name": "teamId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "team_member_teamId_team_id_fk": { + "name": "team_member_teamId_team_id_fk", + "tableFrom": "team_member", + "tableTo": "team", + "columnsFrom": [ + "teamId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "team_member_userId_user_id_fk": { + "name": "team_member_userId_user_id_fk", + "tableFrom": "team_member", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "team_member_teamId_userId_unique": { + "name": "team_member_teamId_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "teamId", + "userId" + ] + } + } + }, + "team": { + "name": "team", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "leagueId": { + "name": "leagueId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "teamsize": { + "name": "teamsize", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "team_leagueId_league_id_fk": { + "name": "team_leagueId_league_id_fk", + "tableFrom": "team", + "tableTo": "league", + "columnsFrom": [ + "leagueId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "firstName": { + "name": "firstName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "role", + "primaryKey": false, + "notNull": true, + "default": "'user'" + }, + "emailVerified": { + "name": "emailVerified", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "selectedLeagueId": { + "name": "selectedLeagueId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "maxLeagues": { + "name": "maxLeagues", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10 + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "verificationToken": { + "name": "verificationToken", + "schema": "", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "verificationToken_identifier_token_pk": { + "name": "verificationToken_identifier_token_pk", + "columns": [ + "identifier", + "token" + ] + } + }, + "uniqueConstraints": {} + } + }, + "enums": { + "game": { + "name": "game", + "values": { + "custom": "custom", + "foosball": "foosball", + "badminton": "badminton", + "chess": "chess", + "pool": "pool", + "table-tennis": "table-tennis", + "sixty-six": "sixty-six" + } + }, + "leagueStatus": { + "name": "leagueStatus", + "values": { + "active": "active", + "finished": "finished" + } + }, + "ratingSystem": { + "name": "ratingSystem", + "values": { + "unknown": "unknown", + "elo": "elo", + "glicko2": "glicko2" + } + }, + "role": { + "name": "role", + "values": { + "user": "user", + "admin": "admin" + } + } + }, + "schemas": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index fe22a6c..bc6682a 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1704567971636, "tag": "0008_purple_darkstar", "breakpoints": true + }, + { + "idx": 9, + "version": "5", + "when": 1705864512208, + "tag": "0009_far_blob", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/db/index.ts b/src/db/index.ts index 952d716..23a1a86 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -9,11 +9,13 @@ declare global { let db: PostgresJsDatabase; +export const client = postgres(`${process.env.DATABASE_URL}`); + if (process.env.NODE_ENV === "production") { - db = drizzle(postgres(`${process.env.DATABASE_URL}`), { schema }); + db = drizzle(client, { schema }); } else { if (!global.db) { - global.db = drizzle(postgres(`${process.env.DATABASE_URL}`), { schema }); + global.db = drizzle(client, { schema }); } db = global.db; diff --git a/src/db/schema.ts b/src/db/schema.ts index db8e6a2..c6d637d 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -85,6 +85,7 @@ export const teams = pgTable("team", { leagueId: text("leagueId") .notNull() .references(() => leagues.id, { onDelete: "cascade" }), + teamSize: integer("teamsize").notNull().default(1), createdAt: timestamp("createdAt", { mode: "date" }).notNull().defaultNow(), }); diff --git a/src/lib/session.ts b/src/lib/session.ts index 043d8db..1d624b3 100644 --- a/src/lib/session.ts +++ b/src/lib/session.ts @@ -13,4 +13,3 @@ export async function getCurrentUser(): Promise { where: (users, { eq }) => eq(users.email, session.user.email!), }); } -