-
Notifications
You must be signed in to change notification settings - Fork 0
Add seasons, games and teams #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
MathijsR94
wants to merge
3
commits into
main
Choose a base branch
from
feature/seasons
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
prisma/migrations/20250228161049_add_teams_and_game_tracking/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| /* | ||
| Warnings: | ||
| - You are about to drop the column `level` on the `User` table. All the data in the column will be lost. | ||
| - Added the required column `game_id` to the `Match` table without a default value. This is not possible if the table is not empty. | ||
| - Added the required column `updated_at` to the `Match` table without a default value. This is not possible if the table is not empty. | ||
| */ | ||
| -- DropForeignKey | ||
| ALTER TABLE `Match` DROP FOREIGN KEY `Match_challenger_id_fkey`; | ||
|
|
||
| -- DropForeignKey | ||
| ALTER TABLE `Match` DROP FOREIGN KEY `Match_defender_id_fkey`; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE `Match` ADD COLUMN `deleted_at` DATETIME(3) NULL, | ||
| ADD COLUMN `game_id` INTEGER NOT NULL, | ||
| ADD COLUMN `updated_at` DATETIME(3) NOT NULL, | ||
| MODIFY `played_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3); | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE `User` DROP COLUMN `level`; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE `Game` ( | ||
| `id` INTEGER NOT NULL AUTO_INCREMENT, | ||
| `name` VARCHAR(255) NOT NULL, | ||
| `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| `updated_at` DATETIME(3) NOT NULL, | ||
| `deleted_at` DATETIME(3) NULL, | ||
| `min_team_size` INTEGER NOT NULL, | ||
| `max_team_size` INTEGER NOT NULL, | ||
|
|
||
| UNIQUE INDEX `Game_name_key`(`name`), | ||
| INDEX `Game_name_idx`(`name`), | ||
| PRIMARY KEY (`id`) | ||
| ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE `UserGameStats` ( | ||
| `id` INTEGER NOT NULL AUTO_INCREMENT, | ||
| `user_id` INTEGER NOT NULL, | ||
| `game_id` INTEGER NOT NULL, | ||
| `level` INTEGER NOT NULL, | ||
| `created_at` DATETIME(3) NOT NULL, | ||
| `updated_at` DATETIME(3) NOT NULL, | ||
| `deleted_at` DATETIME(3) NULL, | ||
|
|
||
| PRIMARY KEY (`id`) | ||
| ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE `Team` ( | ||
| `id` INTEGER NOT NULL AUTO_INCREMENT, | ||
| `name` VARCHAR(255) NOT NULL, | ||
| `game_id` INTEGER NOT NULL, | ||
| `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| `updated_at` DATETIME(3) NOT NULL, | ||
| `deleted_at` DATETIME(3) NULL, | ||
|
|
||
| INDEX `Team_name_idx`(`name`), | ||
| INDEX `Team_game_id_idx`(`game_id`), | ||
| PRIMARY KEY (`id`) | ||
| ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE `TeamMember` ( | ||
| `id` INTEGER NOT NULL AUTO_INCREMENT, | ||
| `team_id` INTEGER NOT NULL, | ||
| `user_id` INTEGER NOT NULL, | ||
| `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| `updated_at` DATETIME(3) NOT NULL, | ||
| `deleted_at` DATETIME(3) NULL, | ||
|
|
||
| INDEX `TeamMember_team_id_idx`(`team_id`), | ||
| INDEX `TeamMember_user_id_idx`(`user_id`), | ||
| UNIQUE INDEX `TeamMember_team_id_user_id_key`(`team_id`, `user_id`), | ||
| PRIMARY KEY (`id`) | ||
| ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE `Rules` ( | ||
| `id` INTEGER NOT NULL AUTO_INCREMENT, | ||
| `game_id` INTEGER NOT NULL, | ||
| `path` VARCHAR(255) NOT NULL, | ||
| `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| `updated_at` DATETIME(3) NOT NULL, | ||
| `deleted_at` DATETIME(3) NULL, | ||
|
|
||
| INDEX `Rules_game_id_idx`(`game_id`), | ||
| UNIQUE INDEX `Rules_game_id_key`(`game_id`), | ||
| PRIMARY KEY (`id`) | ||
| ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE `Season` ( | ||
| `id` INTEGER NOT NULL AUTO_INCREMENT, | ||
| `name` VARCHAR(191) NOT NULL, | ||
| `game_id` INTEGER NOT NULL, | ||
| `start_date` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| `end_date` DATETIME(3) NULL, | ||
| `active` BOOLEAN NOT NULL DEFAULT true, | ||
| `deleted_at` DATETIME(3) NULL, | ||
| `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| `updated_at` DATETIME(3) NOT NULL, | ||
|
|
||
| INDEX `Season_game_id_idx`(`game_id`), | ||
| PRIMARY KEY (`id`) | ||
| ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX `Match_game_id_idx` ON `Match`(`game_id`); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `UserGameStats` ADD CONSTRAINT `UserGameStats_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `UserGameStats` ADD CONSTRAINT `UserGameStats_game_id_fkey` FOREIGN KEY (`game_id`) REFERENCES `Game`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `Match` ADD CONSTRAINT `Match_game_id_fkey` FOREIGN KEY (`game_id`) REFERENCES `Game`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `Match` ADD CONSTRAINT `Match_challenger_id_fkey` FOREIGN KEY (`challenger_id`) REFERENCES `Team`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `Match` ADD CONSTRAINT `Match_defender_id_fkey` FOREIGN KEY (`defender_id`) REFERENCES `Team`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `Team` ADD CONSTRAINT `Team_game_id_fkey` FOREIGN KEY (`game_id`) REFERENCES `Game`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `TeamMember` ADD CONSTRAINT `TeamMember_team_id_fkey` FOREIGN KEY (`team_id`) REFERENCES `Team`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `TeamMember` ADD CONSTRAINT `TeamMember_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `Rules` ADD CONSTRAINT `Rules_game_id_fkey` FOREIGN KEY (`game_id`) REFERENCES `Game`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `Season` ADD CONSTRAINT `Season_game_id_fkey` FOREIGN KEY (`game_id`) REFERENCES `Game`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- RenameIndex | ||
| ALTER TABLE `Match` RENAME INDEX `Match_challenger_id_fkey` TO `Match_challenger_id_idx`; | ||
|
|
||
| -- RenameIndex | ||
| ALTER TABLE `Match` RENAME INDEX `Match_defender_id_fkey` TO `Match_defender_id_idx`; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,20 +14,115 @@ datasource db { | |||||
| } | ||||||
|
|
||||||
| model User { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| name String @db.VarChar(255) | ||||||
| level Int | ||||||
| challenger_matches Match[] @relation("challenger") | ||||||
| defender_matches Match[] @relation("defender") | ||||||
| id Int @id @default(autoincrement()) | ||||||
| name String @db.VarChar(255) | ||||||
| game_stats UserGameStats[] | ||||||
| teams TeamMember[] | ||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| model Game { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| name String @unique @db.VarChar(255) | ||||||
| matches Match[] | ||||||
| seasons Season[] | ||||||
| teams Team[] | ||||||
| rules Rules? | ||||||
| user_stats UserGameStats[] | ||||||
| created_at DateTime @default(now()) @db.DateTime(3) | ||||||
| updated_at DateTime @updatedAt @db.DateTime(3) | ||||||
| deleted_at DateTime? @db.DateTime(3) | ||||||
| min_team_size Int | ||||||
| max_team_size Int | ||||||
|
|
||||||
| @@index([name]) | ||||||
| } | ||||||
|
|
||||||
| model UserGameStats { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| user_id Int | ||||||
| user User @relation(fields: [user_id], references: [id]) | ||||||
| game_id Int | ||||||
| game Game @relation(fields: [game_id], references: [id]) | ||||||
| level Int | ||||||
| created_at DateTime @db.DateTime(3) | ||||||
| updated_at DateTime @updatedAt @db.DateTime(3) | ||||||
| deleted_at DateTime? @db.DateTime(3) | ||||||
| } | ||||||
|
|
||||||
| model Match { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| challenger User @relation("challenger", fields: [challenger_id], references: [id]) | ||||||
| defender User @relation("defender", fields: [defender_id], references: [id]) | ||||||
| id Int @id @default(autoincrement()) | ||||||
| game_id Int | ||||||
| game Game @relation(fields: [game_id], references: [id]) | ||||||
| challenger_id Int | ||||||
| challenger Team @relation("challenger", fields: [challenger_id], references: [id]) | ||||||
| defender_id Int | ||||||
| defender Team @relation("defender", fields: [defender_id], references: [id]) | ||||||
|
Comment on lines
56
to
+59
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a |
||||||
| score_challenger Int | ||||||
| score_defender Int | ||||||
| played_at DateTime | ||||||
| played_at DateTime @default(now()) | ||||||
| updated_at DateTime @updatedAt @db.DateTime(3) | ||||||
| deleted_at DateTime? @db.DateTime(3) | ||||||
|
|
||||||
| @@index([game_id]) | ||||||
| @@index([challenger_id]) | ||||||
| @@index([defender_id]) | ||||||
| } | ||||||
|
|
||||||
| model Team { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| name String @db.VarChar(255) | ||||||
| members TeamMember[] | ||||||
| matches_as_challenger Match[] @relation("challenger") | ||||||
| matches_as_defender Match[] @relation("defender") | ||||||
| game_id Int | ||||||
| game Game @relation(fields: [game_id], references: [id]) | ||||||
| created_at DateTime @default(now()) @db.DateTime(3) | ||||||
| updated_at DateTime @updatedAt @db.DateTime(3) | ||||||
| deleted_at DateTime? @db.DateTime(3) | ||||||
|
|
||||||
| @@index([name]) | ||||||
| @@index([game_id]) | ||||||
| } | ||||||
|
|
||||||
| model TeamMember { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| team_id Int | ||||||
| team Team @relation(fields: [team_id], references: [id]) | ||||||
| user_id Int | ||||||
| user User @relation(fields: [user_id], references: [id]) | ||||||
| created_at DateTime @default(now()) @db.DateTime(3) | ||||||
| updated_at DateTime @updatedAt @db.DateTime(3) | ||||||
| deleted_at DateTime? @db.DateTime(3) | ||||||
|
|
||||||
| @@unique([team_id, user_id]) | ||||||
| @@index([team_id]) | ||||||
| @@index([user_id]) | ||||||
| } | ||||||
|
|
||||||
| model Rules { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| game_id Int | ||||||
| game Game @relation(fields: [game_id], references: [id]) | ||||||
| path String @db.VarChar(255) | ||||||
| created_at DateTime @default(now()) @db.DateTime(3) | ||||||
| updated_at DateTime @updatedAt @db.DateTime(3) | ||||||
| deleted_at DateTime? @db.DateTime(3) | ||||||
|
|
||||||
| @@unique([game_id]) | ||||||
| @@index([game_id]) | ||||||
| } | ||||||
|
|
||||||
| model Season { | ||||||
| id Int @id @default(autoincrement()) | ||||||
| name String | ||||||
| game_id Int | ||||||
| game Game @relation(fields: [game_id], references: [id]) | ||||||
| start_date DateTime @default(now()) @db.DateTime(3) | ||||||
| end_date DateTime? @db.DateTime(3) | ||||||
| active Boolean @default(true) | ||||||
| deleted_at DateTime? @db.DateTime(3) | ||||||
| created_at DateTime @default(now()) @db.DateTime(3) | ||||||
| updated_at DateTime @updatedAt @db.DateTime(3) | ||||||
|
|
||||||
| @@index([game_id]) | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { Game } from '@prisma/client'; | ||
| import { PrismaClient } from '@prisma/client/extension'; | ||
|
|
||
| export function seedGames(prisma: PrismaClient): Record<string, Promise<Game>> { | ||
| return { | ||
| foosball: prisma.game.create({ | ||
| data: { | ||
| name: 'Foosball', | ||
| min_team_size: 1, | ||
| max_team_size: 2, | ||
| seasons: { | ||
| create: { | ||
| name: `Foosball Season 1`, | ||
| start_date: new Date().toISOString(), | ||
| end_date: new Date( | ||
| new Date().setMonth(new Date().getMonth() + 3), | ||
| ).toISOString(), | ||
| active: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| fifa: prisma.game.create({ | ||
| data: { | ||
| name: 'FIFA', | ||
| min_team_size: 1, | ||
| max_team_size: 2, | ||
| seasons: { | ||
| create: { | ||
| name: `FIFA Season 1`, | ||
| start_date: new Date().toISOString(), | ||
| active: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { PrismaClient } from '@prisma/client'; | ||
| import { seedGames } from './games'; | ||
|
|
||
| async function main() { | ||
| const prisma = new PrismaClient(); | ||
|
|
||
| try { | ||
| console.log('🧼 Cleaning up...'); | ||
|
|
||
| await prisma.$transaction([ | ||
| prisma.season.deleteMany(), | ||
| prisma.game.deleteMany(), | ||
| ]); | ||
|
|
||
| console.log('🌱 Seeding games...'); | ||
| await Promise.all(Object.values(seedGames(prisma))); | ||
|
|
||
| console.log('✅ Seeding complete!'); | ||
| } catch (error) { | ||
| console.error('❌ Error seeding data:', error); | ||
| throw error; | ||
| } finally { | ||
| await prisma.$disconnect(); | ||
| } | ||
| } | ||
|
|
||
| main().catch(() => process.exit(1)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, make the relationship many-to-many that way you could make a Season that involves multiple games?