diff --git a/bun.lockb b/bun.lockb index 051c499..fcf582a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/drizzle.config.ts b/drizzle.config.ts new file mode 100644 index 0000000..6aca453 --- /dev/null +++ b/drizzle.config.ts @@ -0,0 +1,13 @@ +import 'dotenv/config' +import { defineConfig } from 'drizzle-kit'; + +export default defineConfig({ + dialect: 'sqlite', + out: './src/lib/drizzle', + schema: "./src/lib/drizzle/schema/*.ts", + dbCredentials: { + url: 'file:../yagami-db/dev.db' + }, + verbose: true, + strict: true +}) \ No newline at end of file diff --git a/package.json b/package.json index fb13055..2bd76cc 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,11 @@ "build": "tsc", "dev": "bun --watch src/index.ts", "test": "jest", + "generate:dbml": "bun src/lib/drizzle/dbml.ts", + "generate": "drizzle-kit generate", + "migrate": "drizzle-kit migrate", "format": "prettier . --write", - "studio": "prisma studio", + "studio": "drizzle-kit studio", "lint": "eslint ." }, "keywords": [], @@ -22,22 +25,22 @@ "@typescript-eslint/eslint-plugin": "^6.5.0", "@typescript-eslint/parser": "^6.5.0", "bun-types": "^1.0.2", + "drizzle-dbml-generator": "^0.6.1", + "drizzle-kit": "^0.22.1", "eslint": "^8.48.0", - "nodemon": "^3.0.1", "prettier": "^3.0.3", "prettier-plugin-prisma": "^5.0.0", - "prisma-dbml-generator": "^0.10.0", "ts-node": "^10.9.1", "typescript": "^5.2.2" }, "dependencies": { - "@elysiajs/swagger": "^0.7.1", - "@prisma/client": "5.3.1", + "@libsql/client": "^0.6.2", "dotenv": "^16.3.1", - "elysia": "^0.7.3", - "elysia-autoroutes": "^0.2.2", + "drizzle-graphql": "^0.8.2", + "drizzle-orm": "^0.31.0", "express": "^4.18.2", "express-ws": "^5.0.2", - "prisma": "^5.2.0" + "graphql": "^16.8.1", + "ruru": "^2.0.0-beta.11" } -} +} \ No newline at end of file diff --git a/prisma/dbml/schema.dbml b/prisma/dbml/schema.dbml deleted file mode 100644 index 5607a1b..0000000 --- a/prisma/dbml/schema.dbml +++ /dev/null @@ -1,511 +0,0 @@ -//// ------------------------------------------------------ -//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) -//// ------------------------------------------------------ - -Table Global { - id Int [pk, increment] - ties Int [not null, default: 0] -} - -Table OsuBadge { - id Int [pk, increment] - awarded_at DateTime [not null] - description String [not null] - image_url String [not null] - url String [not null] - users User [not null] -} - -Table UserTitle { - id Int [pk, increment] - awarded_at DateTime [not null] - name String [not null] - description String [not null] - image_url String [not null] - url String [not null] - users User [not null] -} - -Table User { - id Int [pk] - username String [not null] - country_code String [not null] - country_name String [not null] - cover_url String [not null] - ranked_score BigInt [not null] - play_count Int [not null] - total_score BigInt [not null] - pp_rank Int [not null] - level Int [not null] - level_progress Int [not null] - hit_accuracy Float [not null] - pp Float [not null] - osu_token OsuOauth - discord_accounts DiscordAccount [not null] - twitch_accounts TwitchAccount [not null] - in_teams UserInTeam [not null] - osu_badges OsuBadge [not null] - titles UserTitle [not null] - host_of Tournament [not null] - sessions UserSession [not null] - invites TeamInvite [not null] - scores Score [not null] -} - -Table DiscordAccount { - user User [not null] - osu_id Int [not null] - id String [pk] - avatar String [not null] - discriminator String [not null] - flags Int [not null] - username String [not null] - token DiscordOauth -} - -Table TwitchAccount { - user User [not null] - osu_id Int [not null] - id Int [pk] - username String [not null] - requests_enabled Boolean [not null, default: false] - req_require_live Boolean [not null, default: false] - req_require_category Boolean [not null, default: false] - tournaments Tournament [not null] - token TwitchOauth -} - -Table OsuOauth { - user_id Int [pk] - last_update DateTime [default: `now()`, not null] - access_token String [not null] - expires_in Int [not null] - refresh_token String [not null] - token_type String [not null] - user User [not null] -} - -Table DiscordOauth { - user_id String [pk] - last_update DateTime [default: `now()`, not null] - access_token String [not null] - expires_in Int [not null] - refresh_token String [not null] - token_type String [not null] - scope String [not null] - user DiscordAccount [not null] -} - -Table TwitchOauth { - user_id Int [pk] - last_update DateTime [default: `now()`, not null] - access_token String [not null] - expires_at BigInt [not null] - refresh_token String [not null] - token_type String [not null] - user TwitchAccount [not null] -} - -Table UserSession { - id String [pk] - user User [not null] - osu_id Int [not null] - created_at DateTime [default: `now()`, not null] - last_used DateTime [default: `now()`, not null] - device String - browser String - os String -} - -Table Guild { - guild_id String [pk] - change_nickname Boolean [not null] - linked_role String - player_role String - match_results_channel String - manager_admin_disabled Boolean [not null, default: false] - tournaments Tournament [not null] - active_tournament Int -} - -Table Tournament { - id Int [pk, increment] - acronym String [not null] - name String [not null] - color String [not null] - banner_url String [not null] - description String [not null] - icon_url String [not null] - allow_registrations Boolean [not null] - rounds Round [not null] - guild Guild - guild_id String - private Boolean [not null, default: false] - teams Team [not null] - twitch_account_id Int - twitch_channel TwitchAccount - mod_multipliers ModMultiplier [not null] - hosts User [not null] - settings TournamentSettings -} - -Table TournamentSettings { - id Int [pk, increment] - force_nf Boolean [not null] - score_mode Int [not null] - team_mode Int [not null] - team_size Int [not null] - x_v_x_mode Int [not null] - fm_mods Int [not null, default: 1] - double_pick Int [not null, default: 1] - double_ban Int [not null, default: 1] - for_tournament Tournament - tournament_id Int [unique] - for_match Match - match_id Int [unique] -} - -Table ModMultiplier { - id Int [pk, increment] - tournament Tournament [not null] - tournament_id Int [not null] - mod_string String [not null] - match_exactly Boolean [not null, default: false] - multiplier Float [not null] -} - -Table Round { - id Int [pk, increment] - acronym String [not null] - name String [not null] - is_qualifier Boolean [not null, default: false] - matches Match [not null] - tournament Tournament [not null] - tournament_id Int [not null] - mappools Mappool [not null] - settings RoundSettings -} - -Table RoundSettings { - id Int [pk, increment] - bans Int [not null] - best_of Int [not null] - protects Int [not null] - for_round Round - round_id Int [unique] - for_match Match - match_id Int [unique] -} - -Table Mappool { - id Int [pk, increment] - name String [not null] - description String - map_in_pools MapInPool [not null] - public Boolean [not null, default: false] - rounds Round [not null] - in_matches MappoolInMatch [not null] -} - -Table TeamInvite { - invitee_user_id Int [not null] - invitee User [not null] - team_id Int [not null] - team Team [not null] - - indexes { - (invitee_user_id, team_id) [pk] - } -} - -Table MapInPool { - identifier String [not null] - mods String [not null] - data Map - map_id Int - mod_priority Int [not null, default: 0] - map_order Int - mappool Mappool [not null] - mappool_id Int [not null] - in_matches MapInMatch [not null] - - indexes { - (identifier, mappool_id) [pk] - } -} - -Table Map { - id Int [pk] - beatmapset_id Int [not null] - star_rating Float [not null] - status String [not null] - total_length Int [not null] - diff_mapper_user_id Int [not null] - difficulty_name String [not null] - max_combo Int [not null] - aim_difficulty Float [not null] - approach_rate Float [not null] - flashlight_difficulty Float [not null] - overall_difficulty Float [not null] - slider_factor Float [not null] - speed_difficulty Float [not null] - star_rating_dt Float - star_rating_hr Float - star_rating_ez Float - star_rating_ht Float - bpm Float [not null] - count_circles Int [not null] - count_sliders Int [not null] - count_spinners Int [not null] - circle_size Float [not null] - hp_drain Float [not null] - hit_length Int [not null] - last_updated DateTime [not null] - url String [not null] - artist String [not null] - artist_unicode String [not null] - cover_url String [not null] - cover_2x_url String [not null] - card_url String [not null] - card_2x_url String [not null] - list_url String [not null] - list_2x_url String [not null] - slim_cover_url String [not null] - slim_cover_2x_url String [not null] - preview_url String [not null] - title String [not null] - title_unicode String [not null] - set_mapper_user_id Int [not null] - available Boolean [not null] - fetch_time DateTime [default: `now()`, not null] - in_pools MapInPool [not null] -} - -Table Team { - id Int [pk, increment] - name String [not null] - icon_url String [not null] - color String [not null] - members UserInTeam [not null] - tournament Tournament [not null] - tournament_id Int [not null] - scrim Boolean [not null, default: false] - timezone Int - in_matches TeamInMatch [not null] - in_qualifier_matches TeamInQualifierMatch [not null] - invited_users TeamInvite [not null] - scores TeamScore [not null] -} - -Table UserInTeam { - osu_id Int [not null] - user User [not null] - team Team [not null] - team_id Int [not null] - member_order Int [not null, default: 0] - - indexes { - (osu_id, team_id) [pk] - } -} - -Table Match { - id Int [pk, increment] - teams TeamInMatch [not null] - start_time DateTime - message_id String - channel_id String - mp_link String - waiting_on Int - round Round - round_id Int - map_history MapInMatch [not null] - state Int [not null] - scrim Boolean [not null, default: false] - tournament_settings TournamentSettings - round_settings RoundSettings - mappools MappoolInMatch [not null] -} - -Table TeamInMatch { - match_id Int [not null] - team_id Int [not null] - match Match [not null] - team Team [not null] - score Int [not null] - roll Int - pick_order Int - ban_order Int - aborts Int [not null, default: 0] - faults Int [not null, default: 0] - warmed_up Boolean [not null, default: false] - bans MapInMatch [not null] - wins MapInMatch [not null] - picks MapInMatch [not null] - protects MapInMatch [not null] - winner Boolean - - indexes { - (team_id, match_id) [pk] - } -} - -Table MapInMatch { - map MapInPool [not null] - match Match [not null] - match_id Int [not null] - map_identifier String [not null] - pool_id Int [not null] - scores Score [not null] - team_scores TeamScore [not null] - protected_by TeamInMatch - protected_by_id Int - banned_by TeamInMatch - banned_by_id Int - picked_by TeamInMatch - picked_by_id Int - pick_number Int - pick_team_number Int - won_by TeamInMatch - won_by_id Int - qualifier QualifierMatch - qualifier_id Int - - indexes { - (map_identifier, match_id) [pk] - } -} - -Table Score { - id Int [pk, increment] - score Float [not null] - mods String [not null, default: ''] - map MapInMatch [not null] - map_identifier String [not null] - match_id Int [not null] - user User [not null] - user_id Int [not null] - scores_for TeamScore - team_score_id Int -} - -Table TeamScore { - id Int [pk, increment] - score Float [not null] - freemod Boolean [not null, default: false] - map MapInMatch [not null] - map_identifier String [not null] - match_id Int [not null] - team Team [not null] - team_id Int [not null] - player_scores Score [not null] -} - -Table MappoolInMatch { - mappool Mappool [not null] - match Match [not null] - mappool_id Int [not null] - match_id Int [not null] - - indexes { - (mappool_id, match_id) [pk] - } -} - -Table QualifierMatch { - id Int [pk, increment] - teams TeamInQualifierMatch [not null] - map_index Int [not null, default: 0] - map_list MapInMatch [not null] -} - -Table TeamInQualifierMatch { - team Team [not null] - team_id Int [not null] - match QualifierMatch [not null] - match_id Int [not null] - - indexes { - (team_id, match_id) [pk] - } -} - -Ref: DiscordAccount.osu_id > User.id - -Ref: TwitchAccount.osu_id > User.id - -Ref: OsuOauth.user_id - User.id - -Ref: DiscordOauth.user_id - DiscordAccount.id - -Ref: TwitchOauth.user_id - TwitchAccount.id - -Ref: UserSession.osu_id > User.id - -Ref: Tournament.guild_id > Guild.guild_id - -Ref: Tournament.twitch_account_id > TwitchAccount.id - -Ref: TournamentSettings.tournament_id - Tournament.id - -Ref: TournamentSettings.match_id - Match.id - -Ref: ModMultiplier.tournament_id > Tournament.id - -Ref: Round.tournament_id > Tournament.id [delete: Cascade] - -Ref: RoundSettings.round_id - Round.id - -Ref: RoundSettings.match_id - Match.id - -Ref: TeamInvite.invitee_user_id > User.id - -Ref: TeamInvite.team_id > Team.id [delete: Cascade] - -Ref: MapInPool.map_id > Map.id - -Ref: MapInPool.mappool_id > Mappool.id [delete: Cascade] - -Ref: Team.tournament_id > Tournament.id [delete: Cascade] - -Ref: UserInTeam.osu_id > User.id - -Ref: UserInTeam.team_id > Team.id [delete: Cascade] - -Ref: Match.round_id > Round.id - -Ref: TeamInMatch.match_id > Match.id [delete: Cascade] - -Ref: TeamInMatch.team_id > Team.id [delete: Cascade] - -Ref: MapInMatch.(map_identifier, pool_id) > MapInPool.(identifier, mappool_id) [delete: Cascade] - -Ref: MapInMatch.match_id > Match.id [delete: Cascade] - -Ref: MapInMatch.(match_id, protected_by_id) > TeamInMatch.(match_id, team_id) - -Ref: MapInMatch.(match_id, banned_by_id) > TeamInMatch.(match_id, team_id) - -Ref: MapInMatch.(match_id, picked_by_id) > TeamInMatch.(match_id, team_id) - -Ref: MapInMatch.(match_id, won_by_id) > TeamInMatch.(match_id, team_id) - -Ref: MapInMatch.qualifier_id > QualifierMatch.id - -Ref: Score.(map_identifier, match_id) > MapInMatch.(map_identifier, match_id) - -Ref: Score.user_id > User.id - -Ref: Score.team_score_id > TeamScore.id - -Ref: TeamScore.(map_identifier, match_id) > MapInMatch.(map_identifier, match_id) - -Ref: TeamScore.team_id > Team.id - -Ref: MappoolInMatch.mappool_id > Mappool.id - -Ref: MappoolInMatch.match_id > Match.id - -Ref: TeamInQualifierMatch.team_id > Team.id - -Ref: TeamInQualifierMatch.match_id > QualifierMatch.id \ No newline at end of file diff --git a/prisma/migrations/20220928204222_first/migration.sql b/prisma/migrations/20220928204222_first/migration.sql deleted file mode 100644 index 928b986..0000000 --- a/prisma/migrations/20220928204222_first/migration.sql +++ /dev/null @@ -1,373 +0,0 @@ --- CreateTable -CREATE TABLE "Global" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "ties" INTEGER NOT NULL DEFAULT 0 -); - --- CreateTable -CREATE TABLE "OsuBadge" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "awarded_at" DATETIME NOT NULL, - "description" TEXT NOT NULL, - "image_url" TEXT NOT NULL, - "url" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "UserWithOsuBadge" ( - "userId" INTEGER NOT NULL, - "badgeId" INTEGER NOT NULL, - - PRIMARY KEY ("userId", "badgeId"), - CONSTRAINT "UserWithOsuBadge_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserWithOsuBadge_badgeId_fkey" FOREIGN KEY ("badgeId") REFERENCES "OsuBadge" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "CustomBadge" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "awarded_at" DATETIME NOT NULL, - "name" TEXT NOT NULL, - "description" TEXT NOT NULL, - "image_url" TEXT NOT NULL, - "url" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "UserWithCustomBadge" ( - "userId" INTEGER NOT NULL, - "badgeId" INTEGER NOT NULL, - - PRIMARY KEY ("userId", "badgeId"), - CONSTRAINT "UserWithCustomBadge_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserWithCustomBadge_badgeId_fkey" FOREIGN KEY ("badgeId") REFERENCES "CustomBadge" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "UsersHostingTournament" ( - "userId" INTEGER NOT NULL, - "tourney" INTEGER NOT NULL, - - PRIMARY KEY ("userId", "tourney"), - CONSTRAINT "UsersHostingTournament_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UsersHostingTournament_tourney_fkey" FOREIGN KEY ("tourney") REFERENCES "Tournament" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "User" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "username" TEXT NOT NULL, - "country_code" TEXT NOT NULL, - "country_name" TEXT NOT NULL, - "cover_url" TEXT NOT NULL, - "ranked_score" BIGINT NOT NULL, - "play_count" INTEGER NOT NULL, - "total_score" BIGINT NOT NULL, - "pp_rank" INTEGER NOT NULL, - "level" INTEGER NOT NULL, - "level_progress" INTEGER NOT NULL, - "hit_accuracy" REAL NOT NULL, - "pp" REAL NOT NULL, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_in" INTEGER NOT NULL, - "refresh_token" TEXT NOT NULL, - "type" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "DiscordAccount" ( - "osuId" INTEGER NOT NULL, - "id" TEXT NOT NULL PRIMARY KEY, - "avatar" TEXT NOT NULL, - "discriminator" TEXT NOT NULL, - "flags" INTEGER NOT NULL, - "username" TEXT NOT NULL, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_in" INTEGER NOT NULL, - "refresh_token" TEXT NOT NULL, - "type" TEXT NOT NULL, - "scope" TEXT NOT NULL, - CONSTRAINT "DiscordAccount_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "UserSession" ( - "id" TEXT NOT NULL PRIMARY KEY, - "osuId" INTEGER NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "UserSession_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "Guild" ( - "guild_id" TEXT NOT NULL PRIMARY KEY, - "change_nickname" BOOLEAN NOT NULL, - "linked_role" TEXT, - "player_role" TEXT, - "match_results_channel" TEXT, - "manager_admin_disabled" BOOLEAN NOT NULL DEFAULT false, - "active_tournament" INTEGER -); - --- CreateTable -CREATE TABLE "Tournament" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "acronym" TEXT NOT NULL, - "name" TEXT NOT NULL, - "color" TEXT NOT NULL, - "banner_url" TEXT NOT NULL, - "description" TEXT NOT NULL, - "force_nf" BOOLEAN NOT NULL, - "icon_url" TEXT NOT NULL, - "score_mode" INTEGER NOT NULL, - "team_mode" INTEGER NOT NULL, - "team_size" INTEGER NOT NULL, - "x_v_x_mode" INTEGER NOT NULL, - "allow_registrations" BOOLEAN NOT NULL, - "Guild_id" TEXT, - "delete_warning" BOOLEAN, - "fm_mods" INTEGER NOT NULL DEFAULT 1, - "double_pick" INTEGER NOT NULL DEFAULT 1, - "double_ban" INTEGER NOT NULL DEFAULT 1, - "private" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "Tournament_Guild_id_fkey" FOREIGN KEY ("Guild_id") REFERENCES "Guild" ("guild_id") ON DELETE SET NULL ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "ModMultiplier" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "tournament_id" INTEGER NOT NULL, - "modString" TEXT NOT NULL, - "matchExactly" BOOLEAN NOT NULL DEFAULT false, - "multiplier" REAL NOT NULL, - CONSTRAINT "ModMultiplier_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "Round" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "acronym" TEXT NOT NULL, - "name" TEXT NOT NULL, - "bans" INTEGER NOT NULL, - "best_of" INTEGER NOT NULL, - "delete_warning" TEXT, - "show_mappool" BOOLEAN NOT NULL, - "tournamentId" INTEGER NOT NULL, - "mappoolId" INTEGER, - CONSTRAINT "Round_tournamentId_fkey" FOREIGN KEY ("tournamentId") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "Round_mappoolId_fkey" FOREIGN KEY ("mappoolId") REFERENCES "Mappool" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "Mappool" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "global" BOOLEAN NOT NULL DEFAULT false, - "tournament_name" TEXT, - "tournament_acronym" TEXT, - "tournament_iteration" TEXT, - "round_name" TEXT, - "round_acronym" TEXT -); - --- CreateTable -CREATE TABLE "MapInPool" ( - "identifier" TEXT NOT NULL, - "mods" TEXT NOT NULL, - "mapId" TEXT NOT NULL, - "modPriority" INTEGER NOT NULL DEFAULT 0, - "mappoolId" INTEGER NOT NULL, - - PRIMARY KEY ("identifier", "mappoolId"), - CONSTRAINT "MapInPool_mapId_fkey" FOREIGN KEY ("mapId") REFERENCES "Map" ("beatmap_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInPool_mappoolId_fkey" FOREIGN KEY ("mappoolId") REFERENCES "Mappool" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "Map" ( - "beatmap_id" TEXT NOT NULL PRIMARY KEY, - "fetch_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "approved" TEXT, - "approved_date" DATETIME, - "artist" TEXT, - "artist_unicode" TEXT, - "audio_unavailable" TEXT, - "beatmapset_id" TEXT, - "bpm" TEXT, - "count_normal" TEXT, - "count_slider" TEXT, - "count_spinner" TEXT, - "creator" TEXT, - "creator_id" TEXT, - "diff_aim" TEXT, - "diff_speed" TEXT, - "diff_approach" TEXT, - "diff_drain" TEXT, - "diff_overall" TEXT, - "diff_size" TEXT, - "difficultyrating" TEXT, - "download_unavailable" TEXT, - "favourite_count" TEXT, - "file_md5" TEXT, - "genre_id" TEXT, - "hit_length" TEXT, - "language_id" TEXT, - "last_update" DATETIME, - "max_combo" TEXT, - "mode" TEXT, - "packs" TEXT, - "passcount" TEXT, - "playcount" TEXT, - "rating" TEXT, - "source" TEXT, - "storyboard" TEXT, - "submit_date" DATETIME, - "tags" TEXT, - "title" TEXT, - "title_unicode" TEXT, - "total_length" TEXT, - "version" TEXT, - "video" TEXT -); - --- CreateTable -CREATE TABLE "Team" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "name" TEXT NOT NULL, - "icon_url" TEXT NOT NULL, - "color" TEXT NOT NULL, - "tournamentId" INTEGER NOT NULL, - "scrim" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "Team_tournamentId_fkey" FOREIGN KEY ("tournamentId") REFERENCES "Tournament" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "UserInTeam" ( - "osuId" INTEGER NOT NULL, - "teamId" INTEGER NOT NULL, - "member_order" INTEGER NOT NULL DEFAULT 0, - "delete_warning" BOOLEAN, - - PRIMARY KEY ("osuId", "teamId"), - CONSTRAINT "UserInTeam_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserInTeam_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "Match" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "start_time" DATETIME, - "message_id" TEXT, - "channel_id" TEXT, - "mp_link" TEXT, - "waiting_on" INTEGER, - "roundId" INTEGER, - "state" INTEGER NOT NULL, - "scrim" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "Match_roundId_fkey" FOREIGN KEY ("roundId") REFERENCES "Round" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "ScrimSettings" ( - "matchId" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "bans" INTEGER NOT NULL, - "best_of" INTEGER NOT NULL, - CONSTRAINT "ScrimSettings_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "Match" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "TeamInMatch" ( - "matchId" INTEGER NOT NULL, - "teamId" INTEGER NOT NULL, - "score" INTEGER NOT NULL, - "roll" INTEGER, - "pick_order" INTEGER, - "ban_order" INTEGER, - "aborts" INTEGER NOT NULL DEFAULT 0, - "faults" INTEGER NOT NULL DEFAULT 0, - "warmed_up" BOOLEAN NOT NULL DEFAULT false, - "winner" BOOLEAN, - - PRIMARY KEY ("teamId", "matchId"), - CONSTRAINT "TeamInMatch_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "Match" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "TeamInMatch_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "MapInMatch" ( - "matchId" INTEGER NOT NULL, - "mapIdentifier" TEXT NOT NULL, - "poolId" INTEGER NOT NULL, - "bannedByTeamId" INTEGER, - "bannedByMatchId" INTEGER, - "pickedByTeamId" INTEGER, - "pickedByMatchId" INTEGER, - "pickNumber" INTEGER, - "pickTeamNumber" INTEGER, - "wonByTeamId" INTEGER, - "wonByMatchId" INTEGER, - - PRIMARY KEY ("mapIdentifier", "matchId"), - CONSTRAINT "MapInMatch_mapIdentifier_poolId_fkey" FOREIGN KEY ("mapIdentifier", "poolId") REFERENCES "MapInPool" ("identifier", "mappoolId") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "Match" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_bannedByMatchId_bannedByTeamId_fkey" FOREIGN KEY ("bannedByMatchId", "bannedByTeamId") REFERENCES "TeamInMatch" ("matchId", "teamId") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_pickedByMatchId_pickedByTeamId_fkey" FOREIGN KEY ("pickedByMatchId", "pickedByTeamId") REFERENCES "TeamInMatch" ("matchId", "teamId") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_wonByMatchId_wonByTeamId_fkey" FOREIGN KEY ("wonByMatchId", "wonByTeamId") REFERENCES "TeamInMatch" ("matchId", "teamId") ON DELETE SET NULL ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "QualifierRound" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "mappoolId" INTEGER NOT NULL, - CONSTRAINT "QualifierRound_mappoolId_fkey" FOREIGN KEY ("mappoolId") REFERENCES "Mappool" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "QualifierMatch" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "map_index" INTEGER NOT NULL DEFAULT 0 -); - --- CreateTable -CREATE TABLE "TeamInQualifierMatch" ( - "teamId" INTEGER NOT NULL, - "matchId" INTEGER NOT NULL, - - PRIMARY KEY ("teamId", "matchId"), - CONSTRAINT "TeamInQualifierMatch_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TeamInQualifierMatch_matchId_fkey" FOREIGN KEY ("matchId") REFERENCES "QualifierMatch" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "AutoHostRotate" ( - "osuId" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "mp_link" TEXT NOT NULL, - "min_stars" REAL, - "max_stars" REAL, - "min_length" INTEGER, - "max_length" INTEGER, - "min_rank" INTEGER, - "max_rank" INTEGER, - "currentHostId" INTEGER, - CONSTRAINT "AutoHostRotate_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "AutoHostRotate_currentHostId_fkey" FOREIGN KEY ("currentHostId") REFERENCES "AutoHostRotatePlayer" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "AutoHostRotatePlayer" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "username" TEXT NOT NULL, - "rank" INTEGER NOT NULL, - "lobbyId" INTEGER NOT NULL, - CONSTRAINT "AutoHostRotatePlayer_lobbyId_fkey" FOREIGN KEY ("lobbyId") REFERENCES "AutoHostRotate" ("osuId") ON DELETE CASCADE ON UPDATE CASCADE -); - --- CreateIndex -CREATE UNIQUE INDEX "Round_mappoolId_key" ON "Round"("mappoolId"); - --- CreateIndex -CREATE UNIQUE INDEX "QualifierRound_mappoolId_key" ON "QualifierRound"("mappoolId"); - --- CreateIndex -CREATE UNIQUE INDEX "AutoHostRotate_currentHostId_key" ON "AutoHostRotate"("currentHostId"); diff --git a/prisma/migrations/20221012211922_/migration.sql b/prisma/migrations/20221012211922_/migration.sql deleted file mode 100644 index 48d5103..0000000 --- a/prisma/migrations/20221012211922_/migration.sql +++ /dev/null @@ -1,9 +0,0 @@ --- CreateTable -CREATE TABLE "TeamInvite" ( - "inviteeUserId" INTEGER NOT NULL, - "teamId" INTEGER NOT NULL, - - PRIMARY KEY ("inviteeUserId", "teamId"), - CONSTRAINT "TeamInvite_inviteeUserId_fkey" FOREIGN KEY ("inviteeUserId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TeamInvite_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); diff --git a/prisma/migrations/20221012213724_/migration.sql b/prisma/migrations/20221012213724_/migration.sql deleted file mode 100644 index 48dc3f7..0000000 --- a/prisma/migrations/20221012213724_/migration.sql +++ /dev/null @@ -1,15 +0,0 @@ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_UsersHostingTournament" ( - "userId" INTEGER NOT NULL, - "tourney" INTEGER NOT NULL, - - PRIMARY KEY ("userId", "tourney"), - CONSTRAINT "UsersHostingTournament_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "UsersHostingTournament_tourney_fkey" FOREIGN KEY ("tourney") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_UsersHostingTournament" ("tourney", "userId") SELECT "tourney", "userId" FROM "UsersHostingTournament"; -DROP TABLE "UsersHostingTournament"; -ALTER TABLE "new_UsersHostingTournament" RENAME TO "UsersHostingTournament"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221012215423_/migration.sql b/prisma/migrations/20221012215423_/migration.sql deleted file mode 100644 index a3812ec..0000000 --- a/prisma/migrations/20221012215423_/migration.sql +++ /dev/null @@ -1,54 +0,0 @@ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_MapInPool" ( - "identifier" TEXT NOT NULL, - "mods" TEXT NOT NULL, - "mapId" TEXT NOT NULL, - "modPriority" INTEGER NOT NULL DEFAULT 0, - "mappoolId" INTEGER NOT NULL, - - PRIMARY KEY ("identifier", "mappoolId"), - CONSTRAINT "MapInPool_mapId_fkey" FOREIGN KEY ("mapId") REFERENCES "Map" ("beatmap_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInPool_mappoolId_fkey" FOREIGN KEY ("mappoolId") REFERENCES "Mappool" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_MapInPool" ("identifier", "mapId", "mappoolId", "modPriority", "mods") SELECT "identifier", "mapId", "mappoolId", "modPriority", "mods" FROM "MapInPool"; -DROP TABLE "MapInPool"; -ALTER TABLE "new_MapInPool" RENAME TO "MapInPool"; -CREATE TABLE "new_UserInTeam" ( - "osuId" INTEGER NOT NULL, - "teamId" INTEGER NOT NULL, - "member_order" INTEGER NOT NULL DEFAULT 0, - "delete_warning" BOOLEAN, - - PRIMARY KEY ("osuId", "teamId"), - CONSTRAINT "UserInTeam_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserInTeam_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_UserInTeam" ("delete_warning", "member_order", "osuId", "teamId") SELECT "delete_warning", "member_order", "osuId", "teamId" FROM "UserInTeam"; -DROP TABLE "UserInTeam"; -ALTER TABLE "new_UserInTeam" RENAME TO "UserInTeam"; -CREATE TABLE "new_Team" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "name" TEXT NOT NULL, - "icon_url" TEXT NOT NULL, - "color" TEXT NOT NULL, - "tournamentId" INTEGER NOT NULL, - "scrim" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "Team_tournamentId_fkey" FOREIGN KEY ("tournamentId") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_Team" ("color", "icon_url", "id", "name", "scrim", "tournamentId") SELECT "color", "icon_url", "id", "name", "scrim", "tournamentId" FROM "Team"; -DROP TABLE "Team"; -ALTER TABLE "new_Team" RENAME TO "Team"; -CREATE TABLE "new_TeamInvite" ( - "inviteeUserId" INTEGER NOT NULL, - "teamId" INTEGER NOT NULL, - - PRIMARY KEY ("inviteeUserId", "teamId"), - CONSTRAINT "TeamInvite_inviteeUserId_fkey" FOREIGN KEY ("inviteeUserId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TeamInvite_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_TeamInvite" ("inviteeUserId", "teamId") SELECT "inviteeUserId", "teamId" FROM "TeamInvite"; -DROP TABLE "TeamInvite"; -ALTER TABLE "new_TeamInvite" RENAME TO "TeamInvite"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221012220939_/migration.sql b/prisma/migrations/20221012220939_/migration.sql deleted file mode 100644 index 395a4b1..0000000 --- a/prisma/migrations/20221012220939_/migration.sql +++ /dev/null @@ -1,16 +0,0 @@ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_UserSession" ( - "id" TEXT NOT NULL PRIMARY KEY, - "osuId" INTEGER NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "lastUsed" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "device" TEXT, - "browser" TEXT, - CONSTRAINT "UserSession_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_UserSession" ("createdAt", "id", "osuId") SELECT "createdAt", "id", "osuId" FROM "UserSession"; -DROP TABLE "UserSession"; -ALTER TABLE "new_UserSession" RENAME TO "UserSession"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221012221504_/migration.sql b/prisma/migrations/20221012221504_/migration.sql deleted file mode 100644 index 75cfda6..0000000 --- a/prisma/migrations/20221012221504_/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "UserSession" ADD COLUMN "os" TEXT; diff --git a/prisma/migrations/20221018201142_/migration.sql b/prisma/migrations/20221018201142_/migration.sql deleted file mode 100644 index 997abf8..0000000 --- a/prisma/migrations/20221018201142_/migration.sql +++ /dev/null @@ -1,75 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `access_token` on the `User` table. All the data in the column will be lost. - - You are about to drop the column `expires_in` on the `User` table. All the data in the column will be lost. - - You are about to drop the column `last_update` on the `User` table. All the data in the column will be lost. - - You are about to drop the column `refresh_token` on the `User` table. All the data in the column will be lost. - - You are about to drop the column `type` on the `User` table. All the data in the column will be lost. - - You are about to drop the column `access_token` on the `DiscordAccount` table. All the data in the column will be lost. - - You are about to drop the column `expires_in` on the `DiscordAccount` table. All the data in the column will be lost. - - You are about to drop the column `last_update` on the `DiscordAccount` table. All the data in the column will be lost. - - You are about to drop the column `refresh_token` on the `DiscordAccount` table. All the data in the column will be lost. - - You are about to drop the column `scope` on the `DiscordAccount` table. All the data in the column will be lost. - - You are about to drop the column `type` on the `DiscordAccount` table. All the data in the column will be lost. - -*/ --- CreateTable -CREATE TABLE "OsuOauth" ( - "userId" INTEGER NOT NULL PRIMARY KEY, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_in" INTEGER NOT NULL, - "refresh_token" TEXT NOT NULL, - "token_type" TEXT NOT NULL, - CONSTRAINT "OsuOauth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "OsuOauth" ("userId", "last_update", "access_token", "expires_in", "refresh_token", "token_type") SELECT "id", "last_update", "access_token", "expires_in", "refresh_token", "type" FROM "User"; - --- CreateTable -CREATE TABLE "DiscordOauth" ( - "userId" TEXT NOT NULL PRIMARY KEY, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_in" INTEGER NOT NULL, - "refresh_token" TEXT NOT NULL, - "token_type" TEXT NOT NULL, - "scope" TEXT NOT NULL, - CONSTRAINT "DiscordOauth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "DiscordAccount" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "DiscordOauth" ("userId", "last_update", "access_token", "expires_in", "refresh_token", "token_type", "scope") SELECT "id", "last_update", "access_token", "expires_in", "refresh_token", "type", "SCOPE" FROM "DiscordAccount"; - --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_User" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "username" TEXT NOT NULL, - "country_code" TEXT NOT NULL, - "country_name" TEXT NOT NULL, - "cover_url" TEXT NOT NULL, - "ranked_score" BIGINT NOT NULL, - "play_count" INTEGER NOT NULL, - "total_score" BIGINT NOT NULL, - "pp_rank" INTEGER NOT NULL, - "level" INTEGER NOT NULL, - "level_progress" INTEGER NOT NULL, - "hit_accuracy" REAL NOT NULL, - "pp" REAL NOT NULL -); -INSERT INTO "new_User" ("country_code", "country_name", "cover_url", "hit_accuracy", "id", "level", "level_progress", "play_count", "pp", "pp_rank", "ranked_score", "total_score", "username") SELECT "country_code", "country_name", "cover_url", "hit_accuracy", "id", "level", "level_progress", "play_count", "pp", "pp_rank", "ranked_score", "total_score", "username" FROM "User"; -DROP TABLE "User"; -ALTER TABLE "new_User" RENAME TO "User"; -CREATE TABLE "new_DiscordAccount" ( - "osuId" INTEGER NOT NULL, - "id" TEXT NOT NULL PRIMARY KEY, - "avatar" TEXT NOT NULL, - "discriminator" TEXT NOT NULL, - "flags" INTEGER NOT NULL, - "username" TEXT NOT NULL, - CONSTRAINT "DiscordAccount_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_DiscordAccount" ("avatar", "discriminator", "flags", "id", "osuId", "username") SELECT "avatar", "discriminator", "flags", "id", "osuId", "username" FROM "DiscordAccount"; -DROP TABLE "DiscordAccount"; -ALTER TABLE "new_DiscordAccount" RENAME TO "DiscordAccount"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221229003239_twitch/migration.sql b/prisma/migrations/20221229003239_twitch/migration.sql deleted file mode 100644 index e291700..0000000 --- a/prisma/migrations/20221229003239_twitch/migration.sql +++ /dev/null @@ -1,51 +0,0 @@ --- CreateTable -CREATE TABLE "TwitchAccount" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "username" TEXT NOT NULL, - "requests_enabled" BOOLEAN NOT NULL DEFAULT false, - "req_require_live" BOOLEAN NOT NULL DEFAULT false, - "req_require_category" BOOLEAN NOT NULL DEFAULT false -); - --- CreateTable -CREATE TABLE "TwitchOauth" ( - "userId" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_at" INTEGER NOT NULL, - "refresh_token" TEXT NOT NULL, - "token_type" TEXT NOT NULL, - CONSTRAINT "TwitchOauth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "TwitchAccount" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_Tournament" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "acronym" TEXT NOT NULL, - "name" TEXT NOT NULL, - "color" TEXT NOT NULL, - "banner_url" TEXT NOT NULL, - "description" TEXT NOT NULL, - "force_nf" BOOLEAN NOT NULL, - "icon_url" TEXT NOT NULL, - "score_mode" INTEGER NOT NULL, - "team_mode" INTEGER NOT NULL, - "team_size" INTEGER NOT NULL, - "x_v_x_mode" INTEGER NOT NULL, - "allow_registrations" BOOLEAN NOT NULL, - "Guild_id" TEXT, - "delete_warning" BOOLEAN, - "fm_mods" INTEGER NOT NULL DEFAULT 1, - "double_pick" INTEGER NOT NULL DEFAULT 1, - "double_ban" INTEGER NOT NULL DEFAULT 1, - "private" BOOLEAN NOT NULL DEFAULT false, - "twitchAccountId" INTEGER, - CONSTRAINT "Tournament_Guild_id_fkey" FOREIGN KEY ("Guild_id") REFERENCES "Guild" ("guild_id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "Tournament_twitchAccountId_fkey" FOREIGN KEY ("twitchAccountId") REFERENCES "TwitchAccount" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_Tournament" ("Guild_id", "acronym", "allow_registrations", "banner_url", "color", "delete_warning", "description", "double_ban", "double_pick", "fm_mods", "force_nf", "icon_url", "id", "name", "private", "score_mode", "team_mode", "team_size", "x_v_x_mode") SELECT "Guild_id", "acronym", "allow_registrations", "banner_url", "color", "delete_warning", "description", "double_ban", "double_pick", "fm_mods", "force_nf", "icon_url", "id", "name", "private", "score_mode", "team_mode", "team_size", "x_v_x_mode" FROM "Tournament"; -DROP TABLE "Tournament"; -ALTER TABLE "new_Tournament" RENAME TO "Tournament"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221229015055_bigint/migration.sql b/prisma/migrations/20221229015055_bigint/migration.sql deleted file mode 100644 index 0ee994c..0000000 --- a/prisma/migrations/20221229015055_bigint/migration.sql +++ /dev/null @@ -1,22 +0,0 @@ -/* - Warnings: - - - You are about to alter the column `expires_at` on the `TwitchOauth` table. The data in that column could be lost. The data in that column will be cast from `Int` to `BigInt`. - -*/ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_TwitchOauth" ( - "userId" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_at" BIGINT NOT NULL, - "refresh_token" TEXT NOT NULL, - "token_type" TEXT NOT NULL, - CONSTRAINT "TwitchOauth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "TwitchAccount" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_TwitchOauth" ("access_token", "expires_at", "last_update", "refresh_token", "token_type", "userId") SELECT "access_token", "expires_at", "last_update", "refresh_token", "token_type", "userId" FROM "TwitchOauth"; -DROP TABLE "TwitchOauth"; -ALTER TABLE "new_TwitchOauth" RENAME TO "TwitchOauth"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20221229022311_user/migration.sql b/prisma/migrations/20221229022311_user/migration.sql deleted file mode 100644 index 02c88ad..0000000 --- a/prisma/migrations/20221229022311_user/migration.sql +++ /dev/null @@ -1,22 +0,0 @@ -/* - Warnings: - - - Added the required column `osuId` to the `TwitchAccount` table without a default value. This is not possible if the table is not empty. - -*/ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_TwitchAccount" ( - "osuId" INTEGER NOT NULL, - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "username" TEXT NOT NULL, - "requests_enabled" BOOLEAN NOT NULL DEFAULT false, - "req_require_live" BOOLEAN NOT NULL DEFAULT false, - "req_require_category" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "TwitchAccount_osuId_fkey" FOREIGN KEY ("osuId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_TwitchAccount" ("id", "req_require_category", "req_require_live", "requests_enabled", "username") SELECT "id", "req_require_category", "req_require_live", "requests_enabled", "username" FROM "TwitchAccount"; -DROP TABLE "TwitchAccount"; -ALTER TABLE "new_TwitchAccount" RENAME TO "TwitchAccount"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20230828090847_optional_map_mapinpool/migration.sql b/prisma/migrations/20230828090847_optional_map_mapinpool/migration.sql deleted file mode 100644 index 96a5143..0000000 --- a/prisma/migrations/20230828090847_optional_map_mapinpool/migration.sql +++ /dev/null @@ -1,18 +0,0 @@ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_MapInPool" ( - "identifier" TEXT NOT NULL, - "mods" TEXT NOT NULL, - "mapId" TEXT, - "modPriority" INTEGER NOT NULL DEFAULT 0, - "mappoolId" INTEGER NOT NULL, - - PRIMARY KEY ("identifier", "mappoolId"), - CONSTRAINT "MapInPool_mapId_fkey" FOREIGN KEY ("mapId") REFERENCES "Map" ("beatmap_id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "MapInPool_mappoolId_fkey" FOREIGN KEY ("mappoolId") REFERENCES "Mappool" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_MapInPool" ("identifier", "mapId", "mappoolId", "modPriority", "mods") SELECT "identifier", "mapId", "mappoolId", "modPriority", "mods" FROM "MapInPool"; -DROP TABLE "MapInPool"; -ALTER TABLE "new_MapInPool" RENAME TO "MapInPool"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/20231219172607_snake_case/migration.sql b/prisma/migrations/20231219172607_snake_case/migration.sql deleted file mode 100644 index 61c0c24..0000000 --- a/prisma/migrations/20231219172607_snake_case/migration.sql +++ /dev/null @@ -1,594 +0,0 @@ -/* - Warnings: - - - You are about to drop the `QualifierRound` table. If the table is not empty, all the data it contains will be lost. - - The primary key for the `OsuOauth` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `userId` on the `OsuOauth` table. All the data in the column will be lost. - - You are about to drop the column `osuId` on the `DiscordAccount` table. All the data in the column will be lost. - - You are about to drop the column `osuId` on the `TwitchAccount` table. All the data in the column will be lost. - - The primary key for the `TwitchOauth` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `userId` on the `TwitchOauth` table. All the data in the column will be lost. - - The primary key for the `DiscordOauth` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `userId` on the `DiscordOauth` table. All the data in the column will be lost. - - You are about to drop the column `lobbyId` on the `AutoHostRotatePlayer` table. All the data in the column will be lost. - - You are about to drop the column `matchExactly` on the `ModMultiplier` table. All the data in the column will be lost. - - You are about to drop the column `modString` on the `ModMultiplier` table. All the data in the column will be lost. - - The primary key for the `MapInMatch` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `bannedByMatchId` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `bannedByTeamId` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `mapIdentifier` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `matchId` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `pickNumber` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `pickTeamNumber` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `pickedByMatchId` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `pickedByTeamId` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `poolId` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `wonByMatchId` on the `MapInMatch` table. All the data in the column will be lost. - - You are about to drop the column `wonByTeamId` on the `MapInMatch` table. All the data in the column will be lost. - - The primary key for the `TeamInMatch` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `matchId` on the `TeamInMatch` table. All the data in the column will be lost. - - You are about to drop the column `teamId` on the `TeamInMatch` table. All the data in the column will be lost. - - The primary key for the `AutoHostRotate` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `currentHostId` on the `AutoHostRotate` table. All the data in the column will be lost. - - You are about to drop the column `osuId` on the `AutoHostRotate` table. All the data in the column will be lost. - - The primary key for the `ScrimSettings` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `matchId` on the `ScrimSettings` table. All the data in the column will be lost. - - You are about to drop the column `global` on the `Mappool` table. All the data in the column will be lost. - - You are about to drop the column `round_acronym` on the `Mappool` table. All the data in the column will be lost. - - You are about to drop the column `round_name` on the `Mappool` table. All the data in the column will be lost. - - You are about to drop the column `tournament_acronym` on the `Mappool` table. All the data in the column will be lost. - - You are about to drop the column `tournament_iteration` on the `Mappool` table. All the data in the column will be lost. - - You are about to drop the column `tournament_name` on the `Mappool` table. All the data in the column will be lost. - - You are about to drop the column `roundId` on the `Match` table. All the data in the column will be lost. - - The primary key for the `UserInTeam` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `osuId` on the `UserInTeam` table. All the data in the column will be lost. - - You are about to drop the column `teamId` on the `UserInTeam` table. All the data in the column will be lost. - - The primary key for the `TeamInvite` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `inviteeUserId` on the `TeamInvite` table. All the data in the column will be lost. - - You are about to drop the column `teamId` on the `TeamInvite` table. All the data in the column will be lost. - - You are about to drop the column `Guild_id` on the `Tournament` table. All the data in the column will be lost. - - You are about to drop the column `twitchAccountId` on the `Tournament` table. All the data in the column will be lost. - - The primary key for the `Map` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `approved` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `approved_date` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `audio_unavailable` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `beatmap_id` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `count_normal` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `count_slider` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `count_spinner` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `creator` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `creator_id` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `diff_aim` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `diff_approach` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `diff_drain` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `diff_overall` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `diff_size` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `diff_speed` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `difficultyrating` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `download_unavailable` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `favourite_count` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `file_md5` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `genre_id` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `language_id` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `last_update` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `mode` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `packs` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `passcount` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `playcount` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `rating` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `source` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `storyboard` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `submit_date` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `tags` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `version` on the `Map` table. All the data in the column will be lost. - - You are about to drop the column `video` on the `Map` table. All the data in the column will be lost. - - You are about to alter the column `beatmapset_id` on the `Map` table. The data in that column could be lost. The data in that column will be cast from `String` to `Int`. - - You are about to alter the column `bpm` on the `Map` table. The data in that column could be lost. The data in that column will be cast from `String` to `Float`. - - You are about to alter the column `hit_length` on the `Map` table. The data in that column could be lost. The data in that column will be cast from `String` to `Int`. - - You are about to alter the column `max_combo` on the `Map` table. The data in that column could be lost. The data in that column will be cast from `String` to `Int`. - - You are about to alter the column `total_length` on the `Map` table. The data in that column could be lost. The data in that column will be cast from `String` to `Int`. - - You are about to drop the column `createdAt` on the `UserSession` table. All the data in the column will be lost. - - You are about to drop the column `lastUsed` on the `UserSession` table. All the data in the column will be lost. - - You are about to drop the column `osuId` on the `UserSession` table. All the data in the column will be lost. - - You are about to drop the column `tournamentId` on the `Team` table. All the data in the column will be lost. - - The primary key for the `UserWithCustomBadge` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `badgeId` on the `UserWithCustomBadge` table. All the data in the column will be lost. - - You are about to drop the column `userId` on the `UserWithCustomBadge` table. All the data in the column will be lost. - - The primary key for the `UserWithOsuBadge` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `badgeId` on the `UserWithOsuBadge` table. All the data in the column will be lost. - - You are about to drop the column `userId` on the `UserWithOsuBadge` table. All the data in the column will be lost. - - You are about to drop the column `mappoolId` on the `Round` table. All the data in the column will be lost. - - You are about to drop the column `show_mappool` on the `Round` table. All the data in the column will be lost. - - You are about to drop the column `tournamentId` on the `Round` table. All the data in the column will be lost. - - The primary key for the `UsersHostingTournament` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `tourney` on the `UsersHostingTournament` table. All the data in the column will be lost. - - You are about to drop the column `userId` on the `UsersHostingTournament` table. All the data in the column will be lost. - - The primary key for the `MapInPool` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `mapId` on the `MapInPool` table. All the data in the column will be lost. - - You are about to drop the column `mappoolId` on the `MapInPool` table. All the data in the column will be lost. - - You are about to drop the column `modPriority` on the `MapInPool` table. All the data in the column will be lost. - - The primary key for the `TeamInQualifierMatch` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `matchId` on the `TeamInQualifierMatch` table. All the data in the column will be lost. - - You are about to drop the column `teamId` on the `TeamInQualifierMatch` table. All the data in the column will be lost. - - Added the required column `user_id` to the `OsuOauth` table without a default value. This is not possible if the table is not empty. - - Added the required column `osu_id` to the `DiscordAccount` table without a default value. This is not possible if the table is not empty. - - Added the required column `osu_id` to the `TwitchAccount` table without a default value. This is not possible if the table is not empty. - - Added the required column `user_id` to the `TwitchOauth` table without a default value. This is not possible if the table is not empty. - - Added the required column `user_id` to the `DiscordOauth` table without a default value. This is not possible if the table is not empty. - - Added the required column `lobby_id` to the `AutoHostRotatePlayer` table without a default value. This is not possible if the table is not empty. - - Added the required column `mod_string` to the `ModMultiplier` table without a default value. This is not possible if the table is not empty. - - Added the required column `map_identifier` to the `MapInMatch` table without a default value. This is not possible if the table is not empty. - - Added the required column `match_id` to the `MapInMatch` table without a default value. This is not possible if the table is not empty. - - Added the required column `pool_id` to the `MapInMatch` table without a default value. This is not possible if the table is not empty. - - Added the required column `match_id` to the `TeamInMatch` table without a default value. This is not possible if the table is not empty. - - Added the required column `team_id` to the `TeamInMatch` table without a default value. This is not possible if the table is not empty. - - Added the required column `osu_id` to the `AutoHostRotate` table without a default value. This is not possible if the table is not empty. - - Added the required column `match_id` to the `ScrimSettings` table without a default value. This is not possible if the table is not empty. - - Added the required column `name` to the `Mappool` table without a default value. This is not possible if the table is not empty. - - Added the required column `osu_id` to the `UserInTeam` table without a default value. This is not possible if the table is not empty. - - Added the required column `team_id` to the `UserInTeam` table without a default value. This is not possible if the table is not empty. - - Added the required column `invitee_user_id` to the `TeamInvite` table without a default value. This is not possible if the table is not empty. - - Added the required column `team_id` to the `TeamInvite` table without a default value. This is not possible if the table is not empty. - - Added the required column `aim_difficulty` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `approach_rate` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `available` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `card_2x_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `card_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `circle_size` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `count_circles` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `count_sliders` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `count_spinners` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `cover_2x_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `cover_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `diff_mapper_user_id` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `difficulty_name` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `flashlight_difficulty` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `hp_drain` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `id` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `last_updated` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `list_2x_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `list_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `overall_difficulty` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `preview_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `set_mapper_user_id` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `slider_factor` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `slim_cover_2x_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `slim_cover_url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `speed_difficulty` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `star_rating` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `status` to the `Map` table without a default value. This is not possible if the table is not empty. - - Added the required column `url` to the `Map` table without a default value. This is not possible if the table is not empty. - - Made the column `artist` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `artist_unicode` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `beatmapset_id` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `bpm` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `hit_length` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `max_combo` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `title` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `title_unicode` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Made the column `total_length` on table `Map` required. This step will fail if there are existing NULL values in that column. - - Added the required column `osu_id` to the `UserSession` table without a default value. This is not possible if the table is not empty. - - Added the required column `tournament_id` to the `Team` table without a default value. This is not possible if the table is not empty. - - Added the required column `badge_id` to the `UserWithCustomBadge` table without a default value. This is not possible if the table is not empty. - - Added the required column `user_id` to the `UserWithCustomBadge` table without a default value. This is not possible if the table is not empty. - - Added the required column `badge_id` to the `UserWithOsuBadge` table without a default value. This is not possible if the table is not empty. - - Added the required column `user_id` to the `UserWithOsuBadge` table without a default value. This is not possible if the table is not empty. - - Added the required column `tournament_id` to the `Round` table without a default value. This is not possible if the table is not empty. - - Added the required column `tournament_id` to the `UsersHostingTournament` table without a default value. This is not possible if the table is not empty. - - Added the required column `user_id` to the `UsersHostingTournament` table without a default value. This is not possible if the table is not empty. - - Added the required column `mappool_id` to the `MapInPool` table without a default value. This is not possible if the table is not empty. - - Added the required column `match_id` to the `TeamInQualifierMatch` table without a default value. This is not possible if the table is not empty. - - Added the required column `team_id` to the `TeamInQualifierMatch` table without a default value. This is not possible if the table is not empty. - -*/ --- DropIndex -DROP INDEX "QualifierRound_mappoolId_key"; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "QualifierRound"; -PRAGMA foreign_keys=on; - --- CreateTable -CREATE TABLE "MappoolInRound" ( - "round_id" INTEGER NOT NULL, - "mappool_id" INTEGER NOT NULL, - - PRIMARY KEY ("round_id", "mappool_id"), - CONSTRAINT "MappoolInRound_round_id_fkey" FOREIGN KEY ("round_id") REFERENCES "Round" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "MappoolInRound_mappool_id_fkey" FOREIGN KEY ("mappool_id") REFERENCES "Mappool" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "_MappoolToRound" ( - "A" INTEGER NOT NULL, - "B" INTEGER NOT NULL, - CONSTRAINT "_MappoolToRound_A_fkey" FOREIGN KEY ("A") REFERENCES "Mappool" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "_MappoolToRound_B_fkey" FOREIGN KEY ("B") REFERENCES "Round" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "_MapToMappool" ( - "A" INTEGER NOT NULL, - "B" INTEGER NOT NULL, - CONSTRAINT "_MapToMappool_A_fkey" FOREIGN KEY ("A") REFERENCES "Map" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "_MapToMappool_B_fkey" FOREIGN KEY ("B") REFERENCES "Mappool" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); - --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_OsuOauth" ( - "user_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_in" INTEGER NOT NULL, - "refresh_token" TEXT NOT NULL, - "token_type" TEXT NOT NULL, - CONSTRAINT "OsuOauth_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_OsuOauth" ("user_id", "access_token", "expires_in", "last_update", "refresh_token", "token_type") SELECT "userId", "access_token", "expires_in", "last_update", "refresh_token", "token_type" FROM "OsuOauth"; -DROP TABLE "OsuOauth"; -ALTER TABLE "new_OsuOauth" RENAME TO "OsuOauth"; -CREATE TABLE "new_DiscordAccount" ( - "osu_id" INTEGER NOT NULL, - "id" TEXT NOT NULL PRIMARY KEY, - "avatar" TEXT NOT NULL, - "discriminator" TEXT NOT NULL, - "flags" INTEGER NOT NULL, - "username" TEXT NOT NULL, - CONSTRAINT "DiscordAccount_osu_id_fkey" FOREIGN KEY ("osu_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_DiscordAccount" ("osu_id", "avatar", "discriminator", "flags", "id", "username") SELECT "osuId", "avatar", "discriminator", "flags", "id", "username" FROM "DiscordAccount"; -DROP TABLE "DiscordAccount"; -ALTER TABLE "new_DiscordAccount" RENAME TO "DiscordAccount"; -CREATE TABLE "new_TwitchAccount" ( - "osu_id" INTEGER NOT NULL, - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "username" TEXT NOT NULL, - "requests_enabled" BOOLEAN NOT NULL DEFAULT false, - "req_require_live" BOOLEAN NOT NULL DEFAULT false, - "req_require_category" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "TwitchAccount_osu_id_fkey" FOREIGN KEY ("osu_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_TwitchAccount" ("osu_id", "id", "req_require_category", "req_require_live", "requests_enabled", "username") SELECT "osuId", "id", "req_require_category", "req_require_live", "requests_enabled", "username" FROM "TwitchAccount"; -DROP TABLE "TwitchAccount"; -ALTER TABLE "new_TwitchAccount" RENAME TO "TwitchAccount"; -CREATE TABLE "new_TwitchOauth" ( - "user_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_at" BIGINT NOT NULL, - "refresh_token" TEXT NOT NULL, - "token_type" TEXT NOT NULL, - CONSTRAINT "TwitchOauth_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "TwitchAccount" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_TwitchOauth" ("user_id", "access_token", "expires_at", "last_update", "refresh_token", "token_type") SELECT "userId", "access_token", "expires_at", "last_update", "refresh_token", "token_type" FROM "TwitchOauth"; -DROP TABLE "TwitchOauth"; -ALTER TABLE "new_TwitchOauth" RENAME TO "TwitchOauth"; -CREATE TABLE "new_DiscordOauth" ( - "user_id" TEXT NOT NULL PRIMARY KEY, - "last_update" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "access_token" TEXT NOT NULL, - "expires_in" INTEGER NOT NULL, - "refresh_token" TEXT NOT NULL, - "token_type" TEXT NOT NULL, - "scope" TEXT NOT NULL, - CONSTRAINT "DiscordOauth_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "DiscordAccount" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_DiscordOauth" ("user_id", "access_token", "expires_in", "last_update", "refresh_token", "scope", "token_type") SELECT "userId", "access_token", "expires_in", "last_update", "refresh_token", "scope", "token_type" FROM "DiscordOauth"; -DROP TABLE "DiscordOauth"; -ALTER TABLE "new_DiscordOauth" RENAME TO "DiscordOauth"; -CREATE TABLE "new_AutoHostRotatePlayer" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "username" TEXT NOT NULL, - "rank" INTEGER NOT NULL, - "lobby_id" INTEGER NOT NULL, - CONSTRAINT "AutoHostRotatePlayer_lobby_id_fkey" FOREIGN KEY ("lobby_id") REFERENCES "AutoHostRotate" ("osu_id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_AutoHostRotatePlayer" ("id", "rank", "username", "lobby_id") SELECT "id", "rank", "username", "lobbyId" FROM "AutoHostRotatePlayer"; -DROP TABLE "AutoHostRotatePlayer"; -ALTER TABLE "new_AutoHostRotatePlayer" RENAME TO "AutoHostRotatePlayer"; -CREATE TABLE "new_ModMultiplier" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "tournament_id" INTEGER NOT NULL, - "mod_string" TEXT NOT NULL, - "match_exactly" BOOLEAN NOT NULL DEFAULT false, - "multiplier" REAL NOT NULL, - CONSTRAINT "ModMultiplier_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_ModMultiplier" ("id", "multiplier", "tournament_id", "mod_string", "match_exactly") SELECT "id", "multiplier", "tournamentId", "modString", "matchExactly" FROM "ModMultiplier"; -DROP TABLE "ModMultiplier"; -ALTER TABLE "new_ModMultiplier" RENAME TO "ModMultiplier"; -CREATE TABLE "new_MapInMatch" ( - "match_id" INTEGER NOT NULL, - "map_identifier" TEXT NOT NULL, - "pool_id" INTEGER NOT NULL, - "banned_by_id" INTEGER, - "picked_by_id" INTEGER, - "pick_number" INTEGER, - "pick_team_number" INTEGER, - "won_by_id" INTEGER, - - PRIMARY KEY ("map_identifier", "match_id"), - CONSTRAINT "MapInMatch_map_identifier_pool_id_fkey" FOREIGN KEY ("map_identifier", "pool_id") REFERENCES "MapInPool" ("identifier", "mappool_id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_banned_by_id_fkey" FOREIGN KEY ("match_id", "banned_by_id") REFERENCES "TeamInMatch" ("match_id", "team_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_picked_by_id_fkey" FOREIGN KEY ("match_id", "picked_by_id") REFERENCES "TeamInMatch" ("match_id", "team_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_won_by_id_fkey" FOREIGN KEY ("match_id", "won_by_id") REFERENCES "TeamInMatch" ("match_id", "team_id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_MapInMatch" ("map_identifier", "match_id", "pool_id", "banned_by_id", "picked_by_id", "pick_number", "pick_team_number", "won_by_id") SELECT "mapIdentifier", "matchId", "poolId", "bannedByTeamId", "pickedByTeamId", "pickNumber", "pickTeamNumber", "wonByTeamId" FROM "MapInMatch"; -DROP TABLE "MapInMatch"; -ALTER TABLE "new_MapInMatch" RENAME TO "MapInMatch"; -CREATE TABLE "new_TeamInMatch" ( - "match_id" INTEGER NOT NULL, - "team_id" INTEGER NOT NULL, - "score" INTEGER NOT NULL, - "roll" INTEGER, - "pick_order" INTEGER, - "ban_order" INTEGER, - "aborts" INTEGER NOT NULL DEFAULT 0, - "faults" INTEGER NOT NULL DEFAULT 0, - "warmed_up" BOOLEAN NOT NULL DEFAULT false, - "winner" BOOLEAN, - - PRIMARY KEY ("team_id", "match_id"), - CONSTRAINT "TeamInMatch_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "TeamInMatch_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_TeamInMatch" ("team_id", "match_id", "aborts", "ban_order", "faults", "pick_order", "roll", "score", "warmed_up", "winner") SELECT "teamId", "matchId", "aborts", "ban_order", "faults", "pick_order", "roll", "score", "warmed_up", "winner" FROM "TeamInMatch"; -DROP TABLE "TeamInMatch"; -ALTER TABLE "new_TeamInMatch" RENAME TO "TeamInMatch"; -CREATE TABLE "new_AutoHostRotate" ( - "osu_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "mp_link" TEXT NOT NULL, - "min_stars" REAL, - "max_stars" REAL, - "min_length" INTEGER, - "max_length" INTEGER, - "min_rank" INTEGER, - "max_rank" INTEGER, - "current_host_id" INTEGER, - CONSTRAINT "AutoHostRotate_osu_id_fkey" FOREIGN KEY ("osu_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "AutoHostRotate_current_host_id_fkey" FOREIGN KEY ("current_host_id") REFERENCES "AutoHostRotatePlayer" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_AutoHostRotate" ("osu_id", "max_length", "max_rank", "max_stars", "min_length", "min_rank", "min_stars", "mp_link", "current_host_id") SELECT "osuId", "max_length", "max_rank", "max_stars", "min_length", "min_rank", "min_stars", "mp_link", "current_host_id" FROM "AutoHostRotate"; -DROP TABLE "AutoHostRotate"; -ALTER TABLE "new_AutoHostRotate" RENAME TO "AutoHostRotate"; -CREATE UNIQUE INDEX "AutoHostRotate_current_host_id_key" ON "AutoHostRotate"("current_host_id"); -CREATE TABLE "new_ScrimSettings" ( - "match_id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "bans" INTEGER NOT NULL, - "best_of" INTEGER NOT NULL, - CONSTRAINT "ScrimSettings_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_ScrimSettings" ("match_id", "bans", "best_of") SELECT "matchId", "bans", "best_of" FROM "ScrimSettings"; -DROP TABLE "ScrimSettings"; -ALTER TABLE "new_ScrimSettings" RENAME TO "ScrimSettings"; -CREATE TABLE "new_Mappool" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "name" TEXT NOT NULL DEFAULT "New Mappool", - "description" TEXT, - "public" BOOLEAN NOT NULL DEFAULT false -); -INSERT INTO "new_Mappool" ("id", "public") SELECT "id", "global" FROM "Mappool"; -DROP TABLE "Mappool"; -ALTER TABLE "new_Mappool" RENAME TO "Mappool"; -CREATE TABLE "new_Match" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "start_time" DATETIME, - "message_id" TEXT, - "channel_id" TEXT, - "mp_link" TEXT, - "waiting_on" INTEGER, - "round_id" INTEGER, - "state" INTEGER NOT NULL, - "scrim" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "Match_round_id_fkey" FOREIGN KEY ("round_id") REFERENCES "Round" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_Match" ("round_id", "channel_id", "id", "message_id", "mp_link", "scrim", "start_time", "state", "waiting_on") SELECT "roundId", "channel_id", "id", "message_id", "mp_link", "scrim", "start_time", "state", "waiting_on" FROM "Match"; -DROP TABLE "Match"; -ALTER TABLE "new_Match" RENAME TO "Match"; -CREATE TABLE "new_UserInTeam" ( - "osu_id" INTEGER NOT NULL, - "team_id" INTEGER NOT NULL, - "member_order" INTEGER NOT NULL DEFAULT 0, - "delete_warning" BOOLEAN, - - PRIMARY KEY ("osu_id", "team_id"), - CONSTRAINT "UserInTeam_osu_id_fkey" FOREIGN KEY ("osu_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserInTeam_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_UserInTeam" ("osu_id", "team_id", "delete_warning", "member_order") SELECT "osuId", "teamId", "delete_warning", "member_order" FROM "UserInTeam"; -DROP TABLE "UserInTeam"; -ALTER TABLE "new_UserInTeam" RENAME TO "UserInTeam"; -CREATE TABLE "new_TeamInvite" ( - "invitee_user_id" INTEGER NOT NULL, - "team_id" INTEGER NOT NULL, - - PRIMARY KEY ("invitee_user_id", "team_id"), - CONSTRAINT "TeamInvite_invitee_user_id_fkey" FOREIGN KEY ("invitee_user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TeamInvite_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_TeamInvite" ("invitee_user_id", "team_id") SELECT "inviteeUserId", "teamId" FROM "TeamInvite"; -DROP TABLE "TeamInvite"; -ALTER TABLE "new_TeamInvite" RENAME TO "TeamInvite"; -CREATE TABLE "new_Tournament" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "acronym" TEXT NOT NULL, - "name" TEXT NOT NULL, - "color" TEXT NOT NULL, - "banner_url" TEXT NOT NULL, - "description" TEXT NOT NULL, - "force_nf" BOOLEAN NOT NULL, - "icon_url" TEXT NOT NULL, - "score_mode" INTEGER NOT NULL, - "team_mode" INTEGER NOT NULL, - "team_size" INTEGER NOT NULL, - "x_v_x_mode" INTEGER NOT NULL, - "allow_registrations" BOOLEAN NOT NULL, - "guild_id" TEXT, - "delete_warning" BOOLEAN, - "fm_mods" INTEGER NOT NULL DEFAULT 1, - "double_pick" INTEGER NOT NULL DEFAULT 1, - "double_ban" INTEGER NOT NULL DEFAULT 1, - "private" BOOLEAN NOT NULL DEFAULT false, - "twitch_account_id" INTEGER, - CONSTRAINT "Tournament_guild_id_fkey" FOREIGN KEY ("guild_id") REFERENCES "Guild" ("guild_id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "Tournament_twitch_account_id_fkey" FOREIGN KEY ("twitch_account_id") REFERENCES "TwitchAccount" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_Tournament" ("guild_id", "twitch_account_id", "acronym", "allow_registrations", "banner_url", "color", "delete_warning", "description", "double_ban", "double_pick", "fm_mods", "force_nf", "icon_url", "id", "name", "private", "score_mode", "team_mode", "team_size", "x_v_x_mode") SELECT "Guild_id", "twitchAccountId", "acronym", "allow_registrations", "banner_url", "color", "delete_warning", "description", "double_ban", "double_pick", "fm_mods", "force_nf", "icon_url", "id", "name", "private", "score_mode", "team_mode", "team_size", "x_v_x_mode" FROM "Tournament"; -DROP TABLE "Tournament"; -ALTER TABLE "new_Tournament" RENAME TO "Tournament"; -CREATE TABLE "new_Map" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "beatmapset_id" INTEGER NOT NULL, - "star_rating" REAL NOT NULL, - "status" TEXT NOT NULL, - "total_length" INTEGER NOT NULL, - "diff_mapper_user_id" INTEGER NOT NULL, - "difficulty_name" TEXT NOT NULL, - "max_combo" INTEGER NOT NULL, - "aim_difficulty" REAL NOT NULL, - "approach_rate" REAL NOT NULL, - "flashlight_difficulty" REAL NOT NULL, - "overall_difficulty" REAL NOT NULL, - "slider_factor" REAL NOT NULL, - "speed_difficulty" REAL NOT NULL, - "bpm" REAL NOT NULL, - "count_circles" INTEGER NOT NULL, - "count_sliders" INTEGER NOT NULL, - "count_spinners" INTEGER NOT NULL, - "circle_size" REAL NOT NULL, - "hp_drain" REAL NOT NULL, - "hit_length" INTEGER NOT NULL, - "last_updated" DATETIME NOT NULL, - "url" TEXT NOT NULL, - "artist" TEXT NOT NULL, - "artist_unicode" TEXT NOT NULL, - "cover_url" TEXT NOT NULL, - "cover_2x_url" TEXT NOT NULL, - "card_url" TEXT NOT NULL, - "card_2x_url" TEXT NOT NULL, - "list_url" TEXT NOT NULL, - "list_2x_url" TEXT NOT NULL, - "slim_cover_url" TEXT NOT NULL, - "slim_cover_2x_url" TEXT NOT NULL, - "preview_url" TEXT NOT NULL, - "title" TEXT NOT NULL, - "title_unicode" TEXT NOT NULL, - "set_mapper_user_id" INTEGER NOT NULL, - "available" BOOLEAN NOT NULL, - "fetch_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP -); -DROP TABLE "Map"; -ALTER TABLE "new_Map" RENAME TO "Map"; -CREATE TABLE "new_UserSession" ( - "id" TEXT NOT NULL PRIMARY KEY, - "osu_id" INTEGER NOT NULL, - "created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "last_used" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "device" TEXT, - "browser" TEXT, - "os" TEXT, - CONSTRAINT "UserSession_osu_id_fkey" FOREIGN KEY ("osu_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_UserSession" ("osu_id", "created_at", "last_used", "browser", "device", "id", "os") SELECT "osuId", "createdAt", "lastUsed", "browser", "device", "id", "os" FROM "UserSession"; -DROP TABLE "UserSession"; -ALTER TABLE "new_UserSession" RENAME TO "UserSession"; -CREATE TABLE "new_Team" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "name" TEXT NOT NULL, - "icon_url" TEXT NOT NULL, - "color" TEXT NOT NULL, - "tournament_id" INTEGER NOT NULL, - "scrim" BOOLEAN NOT NULL DEFAULT false, - CONSTRAINT "Team_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_Team" ("color", "icon_url", "id", "name", "scrim", "tournament_id") SELECT "color", "icon_url", "id", "name", "scrim", "tournamentId" FROM "Team"; -DROP TABLE "Team"; -ALTER TABLE "new_Team" RENAME TO "Team"; -CREATE TABLE "new_UserWithCustomBadge" ( - "user_id" INTEGER NOT NULL, - "badge_id" INTEGER NOT NULL, - - PRIMARY KEY ("user_id", "badge_id"), - CONSTRAINT "UserWithCustomBadge_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserWithCustomBadge_badge_id_fkey" FOREIGN KEY ("badge_id") REFERENCES "CustomBadge" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_UserWithCustomBadge" ("user_id", "badge_id") SELECT "userId", "badgeId" FROM "UserWithCustomBadge"; -DROP TABLE "UserWithCustomBadge"; -ALTER TABLE "new_UserWithCustomBadge" RENAME TO "UserWithCustomBadge"; -CREATE TABLE "new_UserWithOsuBadge" ( - "user_id" INTEGER NOT NULL, - "badge_id" INTEGER NOT NULL, - - PRIMARY KEY ("user_id", "badge_id"), - CONSTRAINT "UserWithOsuBadge_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserWithOsuBadge_badge_id_fkey" FOREIGN KEY ("badge_id") REFERENCES "OsuBadge" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_UserWithOsuBadge" ("user_id", "badge_id") SELECT "userId", "badgeId" FROM "UserWithOsuBadge"; -DROP TABLE "UserWithOsuBadge"; -ALTER TABLE "new_UserWithOsuBadge" RENAME TO "UserWithOsuBadge"; -CREATE TABLE "new_Round" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "acronym" TEXT NOT NULL, - "name" TEXT NOT NULL, - "is_qualifier" BOOLEAN NOT NULL DEFAULT false, - "bans" INTEGER NOT NULL, - "best_of" INTEGER NOT NULL, - "delete_warning" TEXT, - "tournament_id" INTEGER NOT NULL, - CONSTRAINT "Round_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_Round" ("acronym", "bans", "best_of", "delete_warning", "id", "name", "tournament_id") SELECT "acronym", "bans", "best_of", "delete_warning", "id", "name", "tournamentId" FROM "Round"; -DROP TABLE "Round"; -ALTER TABLE "new_Round" RENAME TO "Round"; -CREATE TABLE "new_UsersHostingTournament" ( - "user_id" INTEGER NOT NULL, - "tournament_id" INTEGER NOT NULL, - - PRIMARY KEY ("user_id", "tournament_id"), - CONSTRAINT "UsersHostingTournament_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "UsersHostingTournament_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_UsersHostingTournament" ("user_id", "tournament_id") SELECT "userId", "tourney" FROM "UsersHostingTournament"; -DROP TABLE "UsersHostingTournament"; -ALTER TABLE "new_UsersHostingTournament" RENAME TO "UsersHostingTournament"; -CREATE TABLE "new_MapInPool" ( - "identifier" TEXT NOT NULL, - "mods" TEXT NOT NULL, - "map_id" INTEGER, - "mod_priority" INTEGER NOT NULL DEFAULT 0, - "mappool_id" INTEGER NOT NULL, - - PRIMARY KEY ("identifier", "mappool_id"), - CONSTRAINT "MapInPool_map_id_fkey" FOREIGN KEY ("map_id") REFERENCES "Map" ("id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "MapInPool_mappool_id_fkey" FOREIGN KEY ("mappool_id") REFERENCES "Mappool" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_MapInPool" ("identifier", "mods", "map_id", "mod_priority", "mappool_id") SELECT "identifier", "mods", "mapId", "modPriority", "mappoolId" FROM "MapInPool"; -DROP TABLE "MapInPool"; -ALTER TABLE "new_MapInPool" RENAME TO "MapInPool"; -CREATE TABLE "new_TeamInQualifierMatch" ( - "team_id" INTEGER NOT NULL, - "match_id" INTEGER NOT NULL, - - PRIMARY KEY ("team_id", "match_id"), - CONSTRAINT "TeamInQualifierMatch_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TeamInQualifierMatch_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "QualifierMatch" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -DROP TABLE "TeamInQualifierMatch"; -ALTER TABLE "new_TeamInQualifierMatch" RENAME TO "TeamInQualifierMatch"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; - --- CreateIndex -CREATE UNIQUE INDEX "_MappoolToRound_AB_unique" ON "_MappoolToRound"("A", "B"); - --- CreateIndex -CREATE INDEX "_MappoolToRound_B_index" ON "_MappoolToRound"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_MapToMappool_AB_unique" ON "_MapToMappool"("A", "B"); - --- CreateIndex -CREATE INDEX "_MapToMappool_B_index" ON "_MapToMappool"("B"); diff --git a/prisma/migrations/20231220001634_move_settings/migration.sql b/prisma/migrations/20231220001634_move_settings/migration.sql deleted file mode 100644 index e2c0a41..0000000 --- a/prisma/migrations/20231220001634_move_settings/migration.sql +++ /dev/null @@ -1,285 +0,0 @@ -/* - Warnings: - - - You are about to drop the `AutoHostRotate` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `AutoHostRotatePlayer` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `CustomBadge` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `MappoolInRound` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `ScrimSettings` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `UserWithCustomBadge` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `UserWithOsuBadge` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `UsersHostingTournament` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `_MapToMappool` table. If the table is not empty, all the data it contains will be lost. - -*/ --- DropIndex -DROP INDEX "AutoHostRotate_current_host_id_key"; - --- DropIndex -DROP INDEX "_MapToMappool_B_index"; - --- DropIndex -DROP INDEX "_MapToMappool_AB_unique"; - --- AlterTable -ALTER TABLE "Map" ADD COLUMN "star_rating_dt" REAL; -ALTER TABLE "Map" ADD COLUMN "star_rating_ez" REAL; -ALTER TABLE "Map" ADD COLUMN "star_rating_hr" REAL; -ALTER TABLE "Map" ADD COLUMN "star_rating_ht" REAL; - --- AlterTable -ALTER TABLE "MapInPool" ADD COLUMN "map_order" INTEGER; - --- AlterTable -ALTER TABLE "Team" ADD COLUMN "timezone" INTEGER; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "AutoHostRotate"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "AutoHostRotatePlayer"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "CustomBadge"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "MappoolInRound"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "ScrimSettings"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "UserWithCustomBadge"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "UserWithOsuBadge"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "UsersHostingTournament"; -PRAGMA foreign_keys=on; - --- DropTable -PRAGMA foreign_keys=off; -DROP TABLE "_MapToMappool"; -PRAGMA foreign_keys=on; - --- CreateTable -CREATE TABLE "UserTitle" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "awarded_at" DATETIME NOT NULL, - "name" TEXT NOT NULL, - "description" TEXT NOT NULL, - "image_url" TEXT NOT NULL, - "url" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "TournamentSettings" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "force_nf" BOOLEAN NOT NULL, - "score_mode" INTEGER NOT NULL, - "team_mode" INTEGER NOT NULL, - "team_size" INTEGER NOT NULL, - "x_v_x_mode" INTEGER NOT NULL, - "fm_mods" INTEGER NOT NULL DEFAULT 1, - "double_pick" INTEGER NOT NULL DEFAULT 1, - "double_ban" INTEGER NOT NULL DEFAULT 1, - "tournament_id" INTEGER, - "match_id" INTEGER, - CONSTRAINT "TournamentSettings_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TournamentSettings_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "TournamentSettings" ("force_nf", "score_mode", "team_mode", "team_size", "x_v_x_mode", "fm_mods", "double_pick", "double_ban", "tournament_id") SELECT "force_nf", "score_mode", "team_mode", "team_size", "x_v_x_mode", "fm_mods", "double_pick", "double_ban", "id" FROM "Tournament"; - --- CreateTable -CREATE TABLE "RoundSettings" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "bans" INTEGER NOT NULL, - "best_of" INTEGER NOT NULL, - "protects" INTEGER NOT NULL DEFAULT 0, - "round_id" INTEGER, - "match_id" INTEGER, - CONSTRAINT "RoundSettings_round_id_fkey" FOREIGN KEY ("round_id") REFERENCES "Round" ("id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "RoundSettings_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "RoundSettings" ("bans", "best_of", "round_id") SELECT "bans", "best_of", "id" FROM "Round"; - --- CreateTable -CREATE TABLE "Score" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "score" REAL NOT NULL, - "map_identifier" TEXT NOT NULL, - "match_id" INTEGER NOT NULL, - "user_id" INTEGER NOT NULL, - CONSTRAINT "Score_map_identifier_match_id_fkey" FOREIGN KEY ("map_identifier", "match_id") REFERENCES "MapInMatch" ("map_identifier", "match_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "Score_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "TeamScore" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "score" REAL NOT NULL, - "map_identifier" TEXT NOT NULL, - "match_id" INTEGER NOT NULL, - "team_id" INTEGER NOT NULL, - CONSTRAINT "TeamScore_map_identifier_match_id_fkey" FOREIGN KEY ("map_identifier", "match_id") REFERENCES "MapInMatch" ("map_identifier", "match_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TeamScore_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "MappoolInMatch" ( - "mappool_id" INTEGER NOT NULL, - "match_id" INTEGER NOT NULL, - - PRIMARY KEY ("mappool_id", "match_id"), - CONSTRAINT "MappoolInMatch_mappool_id_fkey" FOREIGN KEY ("mappool_id") REFERENCES "Mappool" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MappoolInMatch_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "_OsuBadgeToUser" ( - "A" INTEGER NOT NULL, - "B" INTEGER NOT NULL, - CONSTRAINT "_OsuBadgeToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "OsuBadge" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "_OsuBadgeToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "_UserToUserTitle" ( - "A" INTEGER NOT NULL, - "B" INTEGER NOT NULL, - CONSTRAINT "_UserToUserTitle_A_fkey" FOREIGN KEY ("A") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "_UserToUserTitle_B_fkey" FOREIGN KEY ("B") REFERENCES "UserTitle" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "_TournamentToUser" ( - "A" INTEGER NOT NULL, - "B" INTEGER NOT NULL, - CONSTRAINT "_TournamentToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "_TournamentToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); - --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_UserInTeam" ( - "osu_id" INTEGER NOT NULL, - "team_id" INTEGER NOT NULL, - "member_order" INTEGER NOT NULL DEFAULT 0, - - PRIMARY KEY ("osu_id", "team_id"), - CONSTRAINT "UserInTeam_osu_id_fkey" FOREIGN KEY ("osu_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserInTeam_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_UserInTeam" ("member_order", "osu_id", "team_id") SELECT "member_order", "osu_id", "team_id" FROM "UserInTeam"; -DROP TABLE "UserInTeam"; -ALTER TABLE "new_UserInTeam" RENAME TO "UserInTeam"; -CREATE TABLE "new_MapInMatch" ( - "match_id" INTEGER NOT NULL, - "map_identifier" TEXT NOT NULL, - "pool_id" INTEGER NOT NULL, - "protected_by_id" INTEGER, - "banned_by_id" INTEGER, - "picked_by_id" INTEGER, - "pick_number" INTEGER, - "pick_team_number" INTEGER, - "won_by_id" INTEGER, - "qualifier_id" INTEGER, - - PRIMARY KEY ("map_identifier", "match_id"), - CONSTRAINT "MapInMatch_map_identifier_pool_id_fkey" FOREIGN KEY ("map_identifier", "pool_id") REFERENCES "MapInPool" ("identifier", "mappool_id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_protected_by_id_fkey" FOREIGN KEY ("match_id", "protected_by_id") REFERENCES "TeamInMatch" ("match_id", "team_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_banned_by_id_fkey" FOREIGN KEY ("match_id", "banned_by_id") REFERENCES "TeamInMatch" ("match_id", "team_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_picked_by_id_fkey" FOREIGN KEY ("match_id", "picked_by_id") REFERENCES "TeamInMatch" ("match_id", "team_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_match_id_won_by_id_fkey" FOREIGN KEY ("match_id", "won_by_id") REFERENCES "TeamInMatch" ("match_id", "team_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "MapInMatch_qualifier_id_fkey" FOREIGN KEY ("qualifier_id") REFERENCES "QualifierMatch" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_MapInMatch" ("banned_by_id", "map_identifier", "match_id", "pick_number", "pick_team_number", "picked_by_id", "pool_id", "won_by_id") SELECT "banned_by_id", "map_identifier", "match_id", "pick_number", "pick_team_number", "picked_by_id", "pool_id", "won_by_id" FROM "MapInMatch"; -DROP TABLE "MapInMatch"; -ALTER TABLE "new_MapInMatch" RENAME TO "MapInMatch"; -CREATE TABLE "new_Mappool" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "name" TEXT NOT NULL, - "description" TEXT, - "public" BOOLEAN NOT NULL DEFAULT false -); -INSERT INTO "new_Mappool" ("description", "id", "name", "public") SELECT "description", "id", "name", "public" FROM "Mappool"; -DROP TABLE "Mappool"; -ALTER TABLE "new_Mappool" RENAME TO "Mappool"; -CREATE TABLE "new_Round" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "acronym" TEXT NOT NULL, - "name" TEXT NOT NULL, - "is_qualifier" BOOLEAN NOT NULL DEFAULT false, - "tournament_id" INTEGER NOT NULL, - CONSTRAINT "Round_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE CASCADE ON UPDATE CASCADE -); -INSERT INTO "new_Round" ("acronym", "id", "is_qualifier", "name", "tournament_id") SELECT "acronym", "id", "is_qualifier", "name", "tournament_id" FROM "Round"; -DROP TABLE "Round"; -ALTER TABLE "new_Round" RENAME TO "Round"; -CREATE TABLE "new_Tournament" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "acronym" TEXT NOT NULL, - "name" TEXT NOT NULL, - "color" TEXT NOT NULL, - "banner_url" TEXT NOT NULL, - "description" TEXT NOT NULL, - "icon_url" TEXT NOT NULL, - "allow_registrations" BOOLEAN NOT NULL, - "guild_id" TEXT, - "private" BOOLEAN NOT NULL DEFAULT false, - "twitch_account_id" INTEGER, - CONSTRAINT "Tournament_guild_id_fkey" FOREIGN KEY ("guild_id") REFERENCES "Guild" ("guild_id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "Tournament_twitch_account_id_fkey" FOREIGN KEY ("twitch_account_id") REFERENCES "TwitchAccount" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_Tournament" ("acronym", "allow_registrations", "banner_url", "color", "description", "guild_id", "icon_url", "id", "name", "private", "twitch_account_id") SELECT "acronym", "allow_registrations", "banner_url", "color", "description", "guild_id", "icon_url", "id", "name", "private", "twitch_account_id" FROM "Tournament"; -DROP TABLE "Tournament"; -ALTER TABLE "new_Tournament" RENAME TO "Tournament"; -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; - --- CreateIndex -CREATE UNIQUE INDEX "TournamentSettings_tournament_id_key" ON "TournamentSettings"("tournament_id"); - --- CreateIndex -CREATE UNIQUE INDEX "TournamentSettings_match_id_key" ON "TournamentSettings"("match_id"); - --- CreateIndex -CREATE UNIQUE INDEX "RoundSettings_round_id_key" ON "RoundSettings"("round_id"); - --- CreateIndex -CREATE UNIQUE INDEX "RoundSettings_match_id_key" ON "RoundSettings"("match_id"); - --- CreateIndex -CREATE UNIQUE INDEX "_OsuBadgeToUser_AB_unique" ON "_OsuBadgeToUser"("A", "B"); - --- CreateIndex -CREATE INDEX "_OsuBadgeToUser_B_index" ON "_OsuBadgeToUser"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_UserToUserTitle_AB_unique" ON "_UserToUserTitle"("A", "B"); - --- CreateIndex -CREATE INDEX "_UserToUserTitle_B_index" ON "_UserToUserTitle"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_TournamentToUser_AB_unique" ON "_TournamentToUser"("A", "B"); - --- CreateIndex -CREATE INDEX "_TournamentToUser_B_index" ON "_TournamentToUser"("B"); diff --git a/prisma/migrations/20231220005120_score_improvements/migration.sql b/prisma/migrations/20231220005120_score_improvements/migration.sql deleted file mode 100644 index 7268da8..0000000 --- a/prisma/migrations/20231220005120_score_improvements/migration.sql +++ /dev/null @@ -1,67 +0,0 @@ --- RedefineTables -PRAGMA foreign_keys=OFF; -CREATE TABLE "new_Score" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "score" REAL NOT NULL, - "mods" TEXT NOT NULL DEFAULT '', - "map_identifier" TEXT NOT NULL, - "match_id" INTEGER NOT NULL, - "user_id" INTEGER NOT NULL, - "team_score_id" INTEGER, - CONSTRAINT "Score_map_identifier_match_id_fkey" FOREIGN KEY ("map_identifier", "match_id") REFERENCES "MapInMatch" ("map_identifier", "match_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "Score_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "Score_team_score_id_fkey" FOREIGN KEY ("team_score_id") REFERENCES "TeamScore" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_Score" ("id", "map_identifier", "match_id", "score", "user_id") SELECT "id", "map_identifier", "match_id", "score", "user_id" FROM "Score"; -DROP TABLE "Score"; -ALTER TABLE "new_Score" RENAME TO "Score"; -CREATE TABLE "new_TournamentSettings" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "force_nf" BOOLEAN NOT NULL, - "score_mode" INTEGER NOT NULL, - "team_mode" INTEGER NOT NULL, - "team_size" INTEGER NOT NULL, - "x_v_x_mode" INTEGER NOT NULL, - "fm_mods" INTEGER NOT NULL DEFAULT 1, - "double_pick" INTEGER NOT NULL DEFAULT 1, - "double_ban" INTEGER NOT NULL DEFAULT 1, - "tournament_id" INTEGER, - "match_id" INTEGER, - CONSTRAINT "TournamentSettings_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament" ("id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "TournamentSettings_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_TournamentSettings" ("double_ban", "double_pick", "fm_mods", "force_nf", "id", "match_id", "score_mode", "team_mode", "team_size", "tournament_id", "x_v_x_mode") SELECT "double_ban", "double_pick", "fm_mods", "force_nf", "id", "match_id", "score_mode", "team_mode", "team_size", "tournament_id", "x_v_x_mode" FROM "TournamentSettings"; -DROP TABLE "TournamentSettings"; -ALTER TABLE "new_TournamentSettings" RENAME TO "TournamentSettings"; -CREATE UNIQUE INDEX "TournamentSettings_tournament_id_key" ON "TournamentSettings"("tournament_id"); -CREATE UNIQUE INDEX "TournamentSettings_match_id_key" ON "TournamentSettings"("match_id"); -CREATE TABLE "new_TeamScore" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "score" REAL NOT NULL, - "freemod" BOOLEAN NOT NULL DEFAULT false, - "map_identifier" TEXT NOT NULL, - "match_id" INTEGER NOT NULL, - "team_id" INTEGER NOT NULL, - CONSTRAINT "TeamScore_map_identifier_match_id_fkey" FOREIGN KEY ("map_identifier", "match_id") REFERENCES "MapInMatch" ("map_identifier", "match_id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "TeamScore_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); -INSERT INTO "new_TeamScore" ("id", "map_identifier", "match_id", "score", "team_id") SELECT "id", "map_identifier", "match_id", "score", "team_id" FROM "TeamScore"; -DROP TABLE "TeamScore"; -ALTER TABLE "new_TeamScore" RENAME TO "TeamScore"; -CREATE TABLE "new_RoundSettings" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "bans" INTEGER NOT NULL, - "best_of" INTEGER NOT NULL, - "protects" INTEGER NOT NULL, - "round_id" INTEGER, - "match_id" INTEGER, - CONSTRAINT "RoundSettings_round_id_fkey" FOREIGN KEY ("round_id") REFERENCES "Round" ("id") ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT "RoundSettings_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Match" ("id") ON DELETE SET NULL ON UPDATE CASCADE -); -INSERT INTO "new_RoundSettings" ("bans", "best_of", "id", "match_id", "protects", "round_id") SELECT "bans", "best_of", "id", "match_id", "protects", "round_id" FROM "RoundSettings"; -DROP TABLE "RoundSettings"; -ALTER TABLE "new_RoundSettings" RENAME TO "RoundSettings"; -CREATE UNIQUE INDEX "RoundSettings_round_id_key" ON "RoundSettings"("round_id"); -CREATE UNIQUE INDEX "RoundSettings_match_id_key" ON "RoundSettings"("match_id"); -PRAGMA foreign_key_check; -PRAGMA foreign_keys=ON; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml deleted file mode 100644 index e5e5c47..0000000 --- a/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma deleted file mode 100644 index e2cfae7..0000000 --- a/prisma/schema.prisma +++ /dev/null @@ -1,480 +0,0 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -generator client { - provider = "prisma-client-js" - binaryTargets = ["native", "linux-musl"] -} - -generator dbml { - provider = "prisma-dbml-generator" -} - -datasource db { - provider = "sqlite" - url = env("DATABASE_URL") -} - -model Global { - id Int @id @default(autoincrement()) - ties Int @default(0) -} - -model OsuBadge { - id Int @id @default(autoincrement()) - awarded_at DateTime - description String - image_url String - url String - users User[] -} - -model UserTitle { - id Int @id @default(autoincrement()) - awarded_at DateTime - name String - description String - image_url String - url String - users User[] -} - -model User { - id Int @id - username String - country_code String - country_name String - cover_url String - ranked_score BigInt - play_count Int - total_score BigInt - pp_rank Int - level Int - level_progress Int - hit_accuracy Float - pp Float - - osu_token OsuOauth? - discord_accounts DiscordAccount[] - twitch_accounts TwitchAccount[] - in_teams UserInTeam[] - osu_badges OsuBadge[] - titles UserTitle[] - host_of Tournament[] - sessions UserSession[] - invites TeamInvite[] - scores Score[] -} - -model DiscordAccount { - user User @relation(fields: [osu_id], references: [id]) - osu_id Int - id String @id - avatar String - discriminator String - flags Int - username String - - token DiscordOauth? -} - -model TwitchAccount { - user User @relation(fields: [osu_id], references: [id]) - osu_id Int - id Int @id - username String - requests_enabled Boolean @default(false) - req_require_live Boolean @default(false) - req_require_category Boolean @default(false) - tournaments Tournament[] - - token TwitchOauth? -} - -model OsuOauth { - user_id Int @id - last_update DateTime @default(now()) - access_token String - expires_in Int - refresh_token String - token_type String - - user User @relation(fields: [user_id], references: [id]) -} - -model DiscordOauth { - user_id String @id - last_update DateTime @default(now()) - access_token String - expires_in Int - refresh_token String - token_type String - scope String - - user DiscordAccount @relation(fields: [user_id], references: [id]) -} - -model TwitchOauth { - user_id Int @id - last_update DateTime @default(now()) - access_token String - expires_at BigInt - refresh_token String - token_type String - - user TwitchAccount @relation(fields: [user_id], references: [id]) -} - -model UserSession { - id String @id - user User @relation(fields: [osu_id], references: [id]) - osu_id Int - created_at DateTime @default(now()) - last_used DateTime @default(now()) - device String? - browser String? - os String? -} - -model Guild { - guild_id String @id - change_nickname Boolean - linked_role String? - player_role String? - match_results_channel String? - manager_admin_disabled Boolean @default(false) - tournaments Tournament[] - active_tournament Int? -} - -model Tournament { - id Int @id @default(autoincrement()) - acronym String - name String - color String - banner_url String - description String - icon_url String - allow_registrations Boolean - rounds Round[] - guild Guild? @relation(fields: [guild_id], references: [guild_id]) - guild_id String? - private Boolean @default(false) - teams Team[] - - twitch_account_id Int? - twitch_channel TwitchAccount? @relation(fields: [twitch_account_id], references: [id]) - mod_multipliers ModMultiplier[] - hosts User[] - settings TournamentSettings? -} - -// A model that holds the tournament's settings required to run a match. -// These settings exist inside it's own model so that a match can -// be run without instantiating a full tournament object. -model TournamentSettings { - id Int @id @default(autoincrement()) - - force_nf Boolean - score_mode Int - team_mode Int - team_size Int - x_v_x_mode Int - fm_mods Int @default(1) // How many mods are required for freemod picks - double_pick Int @default(1) // 0: No double picking; 1: Only double picking NM; 2 Double picking allowed - double_ban Int @default(1) // 0: No double banning; 1: Only double banning NM; 2 Double banning allowed - - for_tournament Tournament? @relation(fields: [tournament_id], references: [id]) - tournament_id Int? @unique - for_match Match? @relation(fields: [match_id], references: [id]) - match_id Int? @unique -} - -model ModMultiplier { - id Int @id @default(autoincrement()) - tournament Tournament @relation(fields: [tournament_id], references: [id]) - tournament_id Int - mod_string String - match_exactly Boolean @default(false) - multiplier Float -} - -model Round { - id Int @id @default(autoincrement()) - acronym String - name String - is_qualifier Boolean @default(false) - matches Match[] - tournament Tournament @relation(fields: [tournament_id], references: [id], onDelete: Cascade) - tournament_id Int - mappools Mappool[] - settings RoundSettings? -} - -// A model that holds the rounds's settings required to run a match. -// These settings exist inside it's own model so that a match can -// be run without instantiating a full tournament object. -model RoundSettings { - id Int @id @default(autoincrement()) - - bans Int - best_of Int - protects Int - - for_round Round? @relation(fields: [round_id], references: [id]) - round_id Int? @unique - for_match Match? @relation(fields: [match_id], references: [id]) - match_id Int? @unique -} - -model Mappool { - id Int @id @default(autoincrement()) - name String - description String? - map_in_pools MapInPool[] - public Boolean @default(false) - - rounds Round[] - in_matches MappoolInMatch[] -} - -model TeamInvite { - invitee_user_id Int - invitee User @relation(fields: [invitee_user_id], references: [id]) - team_id Int - team Team @relation(fields: [team_id], references: [id], onDelete: Cascade) - - @@id([invitee_user_id, team_id]) -} - -model MapInPool { - identifier String // NM1, NM2 etc. - mods String - data Map? @relation(fields: [map_id], references: [id]) - map_id Int? - mod_priority Int @default(0) - map_order Int? - mappool Mappool @relation(fields: [mappool_id], references: [id], onDelete: Cascade) - mappool_id Int - in_matches MapInMatch[] - - @@id([identifier, mappool_id]) -} - -// New and improved and now based on osu!api v2 -// osu!standard only -model Map { - // Beatmap attributes - id Int @id - beatmapset_id Int - star_rating Float //'difficulty_rating' - status String - total_length Int - diff_mapper_user_id Int //'user_id' - difficulty_name String //'version' - max_combo Int - - // BeatmapDifficultyAttributes attributes - aim_difficulty Float - approach_rate Float - flashlight_difficulty Float - overall_difficulty Float - slider_factor Float - speed_difficulty Float - - // Mod star rating (only fetched and filled in when needed) - star_rating_dt Float? - star_rating_hr Float? - star_rating_ez Float? - star_rating_ht Float? - - // BeatmapExtended attributes - bpm Float - count_circles Int - count_sliders Int - count_spinners Int - circle_size Float //'cs', changed it to be consistent with the other attributes - hp_drain Float //'drain' - hit_length Int //same as drain time (I think??) - last_updated DateTime - url String - - // Beatmapset attributes - artist String - artist_unicode String - cover_url String //Cover art: 'cover.cover' - cover_2x_url String //'cover.cover@2x' - card_url String //'cover.card' - card_2x_url String //'cover.card@2x' - list_url String //'cover.list' - list_2x_url String //'cover.list@2x' - slim_cover_url String //'cover.slimcover' - slim_cover_2x_url String //'cover.slimcover@2x' - preview_url String //the song preview - title String - title_unicode String - set_mapper_user_id Int //'user_id' - - // BeatmapsetExtended attributes - available Boolean - // ^ true if 'availability.download_disabled' is false and 'deleted_at' is null - - // Other - fetch_time DateTime @default(now()) - in_pools MapInPool[] -} - -model Team { - id Int @id @default(autoincrement()) - name String - icon_url String - color String - members UserInTeam[] - tournament Tournament @relation(fields: [tournament_id], references: [id], onDelete: Cascade) - tournament_id Int - scrim Boolean @default(false) - timezone Int? // UTC Offset - in_matches TeamInMatch[] - in_qualifier_matches TeamInQualifierMatch[] - invited_users TeamInvite[] - scores TeamScore[] -} - -model UserInTeam { - osu_id Int - user User @relation(fields: [osu_id], references: [id]) - team Team @relation(fields: [team_id], references: [id], onDelete: Cascade) - team_id Int - member_order Int @default(0) - - @@id([osu_id, team_id]) -} - -model Match { - id Int @id @default(autoincrement()) - teams TeamInMatch[] - start_time DateTime? - message_id String? - channel_id String? - mp_link String? - waiting_on Int? // Index of team in teams array - round Round? @relation(fields: [round_id], references: [id]) - round_id Int? - map_history MapInMatch[] - state Int - - scrim Boolean @default(false) - tournament_settings TournamentSettings? - round_settings RoundSettings? - mappools MappoolInMatch[] -} - -model TeamInMatch { - match_id Int - team_id Int - match Match @relation(fields: [match_id], references: [id], onDelete: Cascade) - team Team @relation(fields: [team_id], references: [id], onDelete: Cascade) - score Int - roll Int? - pick_order Int? - ban_order Int? - aborts Int @default(0) - faults Int @default(0) - warmed_up Boolean @default(false) - bans MapInMatch[] @relation("banned") - wins MapInMatch[] @relation("won") - picks MapInMatch[] @relation("picked") - protects MapInMatch[] @relation("protected") - winner Boolean? - - @@id([team_id, match_id]) -} - -model MapInMatch { - map MapInPool @relation(fields: [map_identifier, pool_id], references: [identifier, mappool_id], onDelete: Cascade) - match Match @relation(fields: [match_id], references: [id], onDelete: Cascade) - match_id Int - map_identifier String - pool_id Int - - scores Score[] - team_scores TeamScore[] - - protected_by TeamInMatch? @relation(fields: [match_id, protected_by_id], references: [match_id, team_id], name: "protected") - protected_by_id Int? - - banned_by TeamInMatch? @relation(fields: [match_id, banned_by_id], references: [match_id, team_id], name: "banned") - banned_by_id Int? - - picked_by TeamInMatch? @relation(fields: [match_id, picked_by_id], references: [match_id, team_id], name: "picked") - picked_by_id Int? - pick_number Int? - pick_team_number Int? - - won_by TeamInMatch? @relation(fields: [match_id, won_by_id], references: [match_id, team_id], name: "won") - won_by_id Int? - - qualifier QualifierMatch? @relation(fields: [qualifier_id], references: [id]) - qualifier_id Int? - - @@id([map_identifier, match_id]) -} - -model Score { - id Int @id @default(autoincrement()) - - score Float - mods String @default("") - - map MapInMatch @relation(fields: [map_identifier, match_id], references: [map_identifier, match_id]) - map_identifier String - match_id Int - - user User @relation(fields: [user_id], references: [id]) - user_id Int - - scores_for TeamScore? @relation(fields: [team_score_id], references: [id]) - team_score_id Int? -} - -model TeamScore { - id Int @id @default(autoincrement()) - - score Float - freemod Boolean @default(false) - - map MapInMatch @relation(fields: [map_identifier, match_id], references: [map_identifier, match_id]) - map_identifier String - match_id Int - - team Team @relation(fields: [team_id], references: [id]) - team_id Int - - player_scores Score[] -} - -model MappoolInMatch { - mappool Mappool @relation(fields: [mappool_id], references: [id]) - match Match @relation(fields: [match_id], references: [id]) - mappool_id Int - match_id Int - - @@id([mappool_id, match_id]) -} - -model QualifierMatch { - id Int @id @default(autoincrement()) - teams TeamInQualifierMatch[] - map_index Int @default(0) - - map_list MapInMatch[] -} - -model TeamInQualifierMatch { - team Team @relation(fields: [team_id], references: [id]) - team_id Int - match QualifierMatch @relation(fields: [match_id], references: [id]) - match_id Int - - @@id([team_id, match_id]) -} diff --git a/src/graphql/index.ts b/src/graphql/index.ts new file mode 100644 index 0000000..2ae9f4e --- /dev/null +++ b/src/graphql/index.ts @@ -0,0 +1,10 @@ +import { db } from "../lib/drizzle" +import { buildSchema } from "drizzle-graphql" +import { GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, graphql, printSchema } from "graphql" + +export const { entities, schema } = buildSchema(db, { "relationsDepthLimit": 1 }); + + +export const sendQuery = (query: string) => { + return graphql({ schema, source: query }) +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index efe44bf..b7503a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,24 @@ -import { Elysia } from 'elysia'; -import { rest } from './rest'; -import { websocket } from './ws'; -const { PORT } = Bun.env; +import express from "express"; +import { ruruHTML } from "ruru/server"; +import { sendQuery } from "./graphql" -if (!PORT) { - throw 'No PORT Specified in env variables!'; -} +const app = express(); -const app = new Elysia().use(rest).use(websocket).listen(PORT); - -console.log(`Running API at ${app.server?.hostname}:${app.server?.port}`); +app.use(express.json()) +app.post( + "/graphql", (req, res) => { + const request = req.body; + const query = request.query + sendQuery(query).then(response => { + res.send(JSON.stringify(response)) + } + ) + } +).get( + "/", (_req, res) => { + res.type("html"); + res.end(ruruHTML({ endpoint: "/graphql" })) + } +).listen(5173, () => { + console.log("server up") +}) \ No newline at end of file diff --git a/src/lib/drizzle/0000_thin_vindicator.sql b/src/lib/drizzle/0000_thin_vindicator.sql new file mode 100644 index 0000000..9290091 --- /dev/null +++ b/src/lib/drizzle/0000_thin_vindicator.sql @@ -0,0 +1,221 @@ +CREATE TABLE `BlockSection` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `match_id` integer NOT NULL, + `mappool_id` integer NOT NULL, + `action` text NOT NULL, + FOREIGN KEY (`match_id`) REFERENCES `Match`(`id`) ON UPDATE cascade ON DELETE cascade, + FOREIGN KEY (`mappool_id`) REFERENCES `Mappool`(`id`) ON UPDATE no action ON DELETE no action +); +--> statement-breakpoint +CREATE TABLE `Map` ( + `id` integer PRIMARY KEY NOT NULL, + `beatmapset_id` integer NOT NULL, + `fetch_time` integer DEFAULT (CURRENT_TIMESTAMP) NOT NULL, + `title` text NOT NULL, + `artist` text NOT NULL, + `difficulty_name` text NOT NULL, + `url` text NOT NULL, + `cover_url` text NOT NULL, + `status` text NOT NULL, + `max_combo` integer NOT NULL, + `last_updated` integer NOT NULL, + `available` integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE `MapInPool` ( + `identifier` text NOT NULL, + `map_order` integer, + `mods` text NOT NULL, + `mappool_id` integer NOT NULL, + `map_id` integer, + `settings_id` integer, + PRIMARY KEY(`identifier`, `mappool_id`), + FOREIGN KEY (`mappool_id`) REFERENCES `Mappool`(`id`) ON UPDATE cascade ON DELETE cascade, + FOREIGN KEY (`map_id`) REFERENCES `Map`(`id`) ON UPDATE cascade ON DELETE set null, + FOREIGN KEY (`settings_id`) REFERENCES `Settings`(`id`) ON UPDATE cascade ON DELETE set null +); +--> statement-breakpoint +CREATE TABLE `MapStats` ( + `map_id` integer NOT NULL, + `mod_string` text DEFAULT '' NOT NULL, + `star_rating` real NOT NULL, + `bpm` real NOT NULL, + `length` integer NOT NULL, + `cs` real NOT NULL, + `ar` real NOT NULL, + `od` real NOT NULL, + `hp` real NOT NULL, + PRIMARY KEY(`map_id`, `mod_string`), + FOREIGN KEY (`map_id`) REFERENCES `Map`(`id`) ON UPDATE cascade ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `Mappool` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text NOT NULL, + `public` integer DEFAULT true NOT NULL +); +--> statement-breakpoint +CREATE TABLE `MappoolInRound` ( + `mappool_id` integer NOT NULL, + `round_id` integer NOT NULL, + PRIMARY KEY(`mappool_id`, `round_id`), + FOREIGN KEY (`mappool_id`) REFERENCES `Mappool`(`id`) ON UPDATE cascade ON DELETE restrict, + FOREIGN KEY (`round_id`) REFERENCES `Round`(`id`) ON UPDATE cascade ON DELETE restrict +); +--> statement-breakpoint +CREATE TABLE `Match` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `start_time` integer, + `mp_link` text, + `scrim` integer DEFAULT false NOT NULL, + `current_section_id` integer NOT NULL, + `block_in_section_id` integer NOT NULL, + `round_id` integer, + `settings_id` integer, + FOREIGN KEY (`current_section_id`) REFERENCES `BlockSection`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`block_in_section_id`) REFERENCES `MatchBlock`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`round_id`) REFERENCES `Round`(`id`) ON UPDATE cascade ON DELETE set null, + FOREIGN KEY (`settings_id`) REFERENCES `Settings`(`id`) ON UPDATE cascade ON DELETE restrict +); +--> statement-breakpoint +CREATE TABLE `MatchBlock` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `section_id` integer NOT NULL, + `action` text NOT NULL, + `order_number` integer NOT NULL, + `map_identifier` text, + `pool_id` integer, + `acted_on_by_id` integer, + FOREIGN KEY (`section_id`) REFERENCES `BlockSection`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`action`) REFERENCES `BlockSection`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`map_identifier`) REFERENCES `MapInPool`(`identifier`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`pool_id`) REFERENCES `MapInPool`(`mappool_id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`acted_on_by_id`) REFERENCES `TeamInMatch`(`id`) ON UPDATE cascade ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `ModMultiplier` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `settings_id` integer, + `multiplier` real NOT NULL, + `mod_string` text NOT NULL, + `match_exactly` integer NOT NULL, + FOREIGN KEY (`settings_id`) REFERENCES `Settings`(`id`) ON UPDATE cascade ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `Round` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `acronym` text NOT NULL, + `name` text NOT NULL, + `tournament_id` integer NOT NULL, + FOREIGN KEY (`tournament_id`) REFERENCES `Tournament`(`id`) ON UPDATE cascade ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `Score` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `score` real NOT NULL, + `mods` text, + `block_id` integer NOT NULL, + `user_id` integer NOT NULL, + `team_score_id` integer, + FOREIGN KEY (`block_id`) REFERENCES `MatchBlock`(`id`) ON UPDATE cascade ON DELETE cascade, + FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON UPDATE cascade ON DELETE cascade, + FOREIGN KEY (`team_score_id`) REFERENCES `TeamScore`(`id`) ON UPDATE cascade ON DELETE set null +); +--> statement-breakpoint +CREATE TABLE `Settings` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `gamemode` integer DEFAULT 0 NOT NULL, + `team_mode` integer NOT NULL, + `score_mode` integer NOT NULL, + `force_nf` integer DEFAULT true NOT NULL, + `fm_mods` integer DEFAULT 1 NOT NULL, + `player_count` integer NOT NULL, + `tournament_id` integer, + `match_id` integer, + FOREIGN KEY (`tournament_id`) REFERENCES `Tournament`(`id`) ON UPDATE cascade ON DELETE set null, + FOREIGN KEY (`match_id`) REFERENCES `Match`(`id`) ON UPDATE cascade ON DELETE set null +); +--> statement-breakpoint +CREATE TABLE `Team` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text NOT NULL, + `icon_url` text, + `color` text NOT NULL, + `timezone` integer +); +--> statement-breakpoint +CREATE TABLE `TeamInMatch` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `match_id` integer NOT NULL, + `team_id` integer, + `score` integer NOT NULL, + `roll` integer, + `winner` integer, + `aborts` integer DEFAULT 0 NOT NULL, + `faults` integer DEFAULT 0 NOT NULL, + FOREIGN KEY (`match_id`) REFERENCES `Match`(`id`) ON UPDATE cascade ON DELETE cascade, + FOREIGN KEY (`team_id`) REFERENCES `Team`(`id`) ON UPDATE cascade ON DELETE set null +); +--> statement-breakpoint +CREATE TABLE `TeamInTournament` ( + `tournament_id` integer, + `team_id` integer, + PRIMARY KEY(`team_id`, `tournament_id`), + FOREIGN KEY (`tournament_id`) REFERENCES `Tournament`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`team_id`) REFERENCES `Team`(`id`) ON UPDATE no action ON DELETE no action +); +--> statement-breakpoint +CREATE TABLE `TeamScore` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `score` real NOT NULL, + `block_id` integer NOT NULL, + `team_id` integer NOT NULL, + FOREIGN KEY (`block_id`) REFERENCES `MatchBlock`(`id`) ON UPDATE cascade ON DELETE cascade, + FOREIGN KEY (`team_id`) REFERENCES `Team`(`id`) ON UPDATE cascade ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `Tournament` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `name` text NOT NULL, + `acronym` text NOT NULL, + `settings_id` integer, + `allow_registrations` integer DEFAULT true NOT NULL, + `private` integer NOT NULL, + `team_size` integer NOT NULL, + `color` text, + `banner_url` text, + `description` text, + `icon_url` text, + FOREIGN KEY (`settings_id`) REFERENCES `Settings`(`id`) ON UPDATE no action ON DELETE no action +); +--> statement-breakpoint +CREATE TABLE `User` ( + `id` integer PRIMARY KEY NOT NULL, + `username` text NOT NULL, + `country_code` text NOT NULL, + `country_name` text NOT NULL, + `cover_url` text NOT NULL, + `avatar_url` text NOT NULL, + `pp` real, + `global_rank` integer, + `country_rank` integer, + `total_score` integer, + `ranked_score` integer, + `hit_accuracy` real, + `play_count` integer, + `level` integer, + `level_progress` integer +); +--> statement-breakpoint +CREATE TABLE `UserInTeam` ( + `user_id` integer NOT NULL, + `team_id` integer NOT NULL, + `invite` integer, + `member_order` integer DEFAULT 0, + PRIMARY KEY(`team_id`, `user_id`), + FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON UPDATE cascade ON DELETE cascade, + FOREIGN KEY (`team_id`) REFERENCES `Team`(`id`) ON UPDATE cascade ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `Settings_tournament_id_unique` ON `Settings` (`tournament_id`);--> statement-breakpoint +CREATE UNIQUE INDEX `Settings_match_id_unique` ON `Settings` (`match_id`); \ No newline at end of file diff --git a/src/lib/drizzle/dbml.ts b/src/lib/drizzle/dbml.ts new file mode 100644 index 0000000..193da95 --- /dev/null +++ b/src/lib/drizzle/dbml.ts @@ -0,0 +1,7 @@ +import { schema } from "." +import { sqliteGenerate } from "drizzle-dbml-generator"; + +const out = "./src/lib/drizzle/schema.dbml" +const relational = true; + +sqliteGenerate({ schema, out, relational }) \ No newline at end of file diff --git a/src/lib/drizzle/index.ts b/src/lib/drizzle/index.ts new file mode 100644 index 0000000..beb87f9 --- /dev/null +++ b/src/lib/drizzle/index.ts @@ -0,0 +1,11 @@ +import { drizzle } from "drizzle-orm/libsql" +import { createClient } from "@libsql/client"; +import * as tables from "./schema/schema" +import * as relations from "./schema/relations" + +const client = createClient({ url: "file:../yagami-db/dev.db" }) + +const schema = { ...tables, ...relations } +const db = drizzle(client, { schema }); + +export { schema, db } \ No newline at end of file diff --git a/src/lib/drizzle/meta/0000_snapshot.json b/src/lib/drizzle/meta/0000_snapshot.json new file mode 100644 index 0000000..53c9f08 --- /dev/null +++ b/src/lib/drizzle/meta/0000_snapshot.json @@ -0,0 +1,1566 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "46120f16-3830-46fa-8d97-8670e1da5ef7", + "prevId": "00000000-0000-0000-0000-000000000000", + "tables": { + "BlockSection": { + "name": "BlockSection", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "match_id": { + "name": "match_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mappool_id": { + "name": "mappool_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "BlockSection_match_id_Match_id_fk": { + "name": "BlockSection_match_id_Match_id_fk", + "tableFrom": "BlockSection", + "tableTo": "Match", + "columnsFrom": [ + "match_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "BlockSection_mappool_id_Mappool_id_fk": { + "name": "BlockSection_mappool_id_Mappool_id_fk", + "tableFrom": "BlockSection", + "tableTo": "Mappool", + "columnsFrom": [ + "mappool_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "Map": { + "name": "Map", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "beatmapset_id": { + "name": "beatmapset_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fetch_time": { + "name": "fetch_time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(CURRENT_TIMESTAMP)" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "artist": { + "name": "artist", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "difficulty_name": { + "name": "difficulty_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "cover_url": { + "name": "cover_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "max_combo": { + "name": "max_combo", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_updated": { + "name": "last_updated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "available": { + "name": "available", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "MapInPool": { + "name": "MapInPool", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "map_order": { + "name": "map_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mods": { + "name": "mods", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mappool_id": { + "name": "mappool_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "map_id": { + "name": "map_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "settings_id": { + "name": "settings_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "MapInPool_mappool_id_Mappool_id_fk": { + "name": "MapInPool_mappool_id_Mappool_id_fk", + "tableFrom": "MapInPool", + "tableTo": "Mappool", + "columnsFrom": [ + "mappool_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "MapInPool_map_id_Map_id_fk": { + "name": "MapInPool_map_id_Map_id_fk", + "tableFrom": "MapInPool", + "tableTo": "Map", + "columnsFrom": [ + "map_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "MapInPool_settings_id_Settings_id_fk": { + "name": "MapInPool_settings_id_Settings_id_fk", + "tableFrom": "MapInPool", + "tableTo": "Settings", + "columnsFrom": [ + "settings_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "MapInPool_identifier_mappool_id_pk": { + "columns": [ + "identifier", + "mappool_id" + ], + "name": "MapInPool_identifier_mappool_id_pk" + } + }, + "uniqueConstraints": {} + }, + "MapStats": { + "name": "MapStats", + "columns": { + "map_id": { + "name": "map_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mod_string": { + "name": "mod_string", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "star_rating": { + "name": "star_rating", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "bpm": { + "name": "bpm", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "length": { + "name": "length", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "cs": { + "name": "cs", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ar": { + "name": "ar", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "od": { + "name": "od", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hp": { + "name": "hp", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "MapStats_map_id_Map_id_fk": { + "name": "MapStats_map_id_Map_id_fk", + "tableFrom": "MapStats", + "tableTo": "Map", + "columnsFrom": [ + "map_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "MapStats_map_id_mod_string_pk": { + "columns": [ + "map_id", + "mod_string" + ], + "name": "MapStats_map_id_mod_string_pk" + } + }, + "uniqueConstraints": {} + }, + "Mappool": { + "name": "Mappool", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "public": { + "name": "public", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "MappoolInRound": { + "name": "MappoolInRound", + "columns": { + "mappool_id": { + "name": "mappool_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "round_id": { + "name": "round_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "MappoolInRound_mappool_id_Mappool_id_fk": { + "name": "MappoolInRound_mappool_id_Mappool_id_fk", + "tableFrom": "MappoolInRound", + "tableTo": "Mappool", + "columnsFrom": [ + "mappool_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + }, + "MappoolInRound_round_id_Round_id_fk": { + "name": "MappoolInRound_round_id_Round_id_fk", + "tableFrom": "MappoolInRound", + "tableTo": "Round", + "columnsFrom": [ + "round_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "MappoolInRound_mappool_id_round_id_pk": { + "columns": [ + "mappool_id", + "round_id" + ], + "name": "MappoolInRound_mappool_id_round_id_pk" + } + }, + "uniqueConstraints": {} + }, + "Match": { + "name": "Match", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "start_time": { + "name": "start_time", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mp_link": { + "name": "mp_link", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scrim": { + "name": "scrim", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "current_section_id": { + "name": "current_section_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "block_in_section_id": { + "name": "block_in_section_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "round_id": { + "name": "round_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "settings_id": { + "name": "settings_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "Match_current_section_id_BlockSection_id_fk": { + "name": "Match_current_section_id_BlockSection_id_fk", + "tableFrom": "Match", + "tableTo": "BlockSection", + "columnsFrom": [ + "current_section_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "Match_block_in_section_id_MatchBlock_id_fk": { + "name": "Match_block_in_section_id_MatchBlock_id_fk", + "tableFrom": "Match", + "tableTo": "MatchBlock", + "columnsFrom": [ + "block_in_section_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "Match_round_id_Round_id_fk": { + "name": "Match_round_id_Round_id_fk", + "tableFrom": "Match", + "tableTo": "Round", + "columnsFrom": [ + "round_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "Match_settings_id_Settings_id_fk": { + "name": "Match_settings_id_Settings_id_fk", + "tableFrom": "Match", + "tableTo": "Settings", + "columnsFrom": [ + "settings_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "MatchBlock": { + "name": "MatchBlock", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "section_id": { + "name": "section_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "order_number": { + "name": "order_number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "map_identifier": { + "name": "map_identifier", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pool_id": { + "name": "pool_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "acted_on_by_id": { + "name": "acted_on_by_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "MatchBlock_section_id_BlockSection_id_fk": { + "name": "MatchBlock_section_id_BlockSection_id_fk", + "tableFrom": "MatchBlock", + "tableTo": "BlockSection", + "columnsFrom": [ + "section_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "MatchBlock_action_BlockSection_id_fk": { + "name": "MatchBlock_action_BlockSection_id_fk", + "tableFrom": "MatchBlock", + "tableTo": "BlockSection", + "columnsFrom": [ + "action" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "MatchBlock_map_identifier_MapInPool_identifier_fk": { + "name": "MatchBlock_map_identifier_MapInPool_identifier_fk", + "tableFrom": "MatchBlock", + "tableTo": "MapInPool", + "columnsFrom": [ + "map_identifier" + ], + "columnsTo": [ + "identifier" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "MatchBlock_pool_id_MapInPool_mappool_id_fk": { + "name": "MatchBlock_pool_id_MapInPool_mappool_id_fk", + "tableFrom": "MatchBlock", + "tableTo": "MapInPool", + "columnsFrom": [ + "pool_id" + ], + "columnsTo": [ + "mappool_id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "MatchBlock_acted_on_by_id_TeamInMatch_id_fk": { + "name": "MatchBlock_acted_on_by_id_TeamInMatch_id_fk", + "tableFrom": "MatchBlock", + "tableTo": "TeamInMatch", + "columnsFrom": [ + "acted_on_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "ModMultiplier": { + "name": "ModMultiplier", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "settings_id": { + "name": "settings_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "multiplier": { + "name": "multiplier", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mod_string": { + "name": "mod_string", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "match_exactly": { + "name": "match_exactly", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "ModMultiplier_settings_id_Settings_id_fk": { + "name": "ModMultiplier_settings_id_Settings_id_fk", + "tableFrom": "ModMultiplier", + "tableTo": "Settings", + "columnsFrom": [ + "settings_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "Round": { + "name": "Round", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "acronym": { + "name": "acronym", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tournament_id": { + "name": "tournament_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "Round_tournament_id_Tournament_id_fk": { + "name": "Round_tournament_id_Tournament_id_fk", + "tableFrom": "Round", + "tableTo": "Tournament", + "columnsFrom": [ + "tournament_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "Score": { + "name": "Score", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "score": { + "name": "score", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mods": { + "name": "mods", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "block_id": { + "name": "block_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "team_score_id": { + "name": "team_score_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "Score_block_id_MatchBlock_id_fk": { + "name": "Score_block_id_MatchBlock_id_fk", + "tableFrom": "Score", + "tableTo": "MatchBlock", + "columnsFrom": [ + "block_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "Score_user_id_User_id_fk": { + "name": "Score_user_id_User_id_fk", + "tableFrom": "Score", + "tableTo": "User", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "Score_team_score_id_TeamScore_id_fk": { + "name": "Score_team_score_id_TeamScore_id_fk", + "tableFrom": "Score", + "tableTo": "TeamScore", + "columnsFrom": [ + "team_score_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "Settings": { + "name": "Settings", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "gamemode": { + "name": "gamemode", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "team_mode": { + "name": "team_mode", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "score_mode": { + "name": "score_mode", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "force_nf": { + "name": "force_nf", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "fm_mods": { + "name": "fm_mods", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "player_count": { + "name": "player_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tournament_id": { + "name": "tournament_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "match_id": { + "name": "match_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "Settings_tournament_id_unique": { + "name": "Settings_tournament_id_unique", + "columns": [ + "tournament_id" + ], + "isUnique": true + }, + "Settings_match_id_unique": { + "name": "Settings_match_id_unique", + "columns": [ + "match_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "Settings_tournament_id_Tournament_id_fk": { + "name": "Settings_tournament_id_Tournament_id_fk", + "tableFrom": "Settings", + "tableTo": "Tournament", + "columnsFrom": [ + "tournament_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "Settings_match_id_Match_id_fk": { + "name": "Settings_match_id_Match_id_fk", + "tableFrom": "Settings", + "tableTo": "Match", + "columnsFrom": [ + "match_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "Team": { + "name": "Team", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "icon_url": { + "name": "icon_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timezone": { + "name": "timezone", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "TeamInMatch": { + "name": "TeamInMatch", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "match_id": { + "name": "match_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "team_id": { + "name": "team_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "roll": { + "name": "roll", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "winner": { + "name": "winner", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "aborts": { + "name": "aborts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "faults": { + "name": "faults", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "TeamInMatch_match_id_Match_id_fk": { + "name": "TeamInMatch_match_id_Match_id_fk", + "tableFrom": "TeamInMatch", + "tableTo": "Match", + "columnsFrom": [ + "match_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "TeamInMatch_team_id_Team_id_fk": { + "name": "TeamInMatch_team_id_Team_id_fk", + "tableFrom": "TeamInMatch", + "tableTo": "Team", + "columnsFrom": [ + "team_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "TeamInTournament": { + "name": "TeamInTournament", + "columns": { + "tournament_id": { + "name": "tournament_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "team_id": { + "name": "team_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "TeamInTournament_tournament_id_Tournament_id_fk": { + "name": "TeamInTournament_tournament_id_Tournament_id_fk", + "tableFrom": "TeamInTournament", + "tableTo": "Tournament", + "columnsFrom": [ + "tournament_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "TeamInTournament_team_id_Team_id_fk": { + "name": "TeamInTournament_team_id_Team_id_fk", + "tableFrom": "TeamInTournament", + "tableTo": "Team", + "columnsFrom": [ + "team_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "TeamInTournament_tournament_id_team_id_pk": { + "columns": [ + "team_id", + "tournament_id" + ], + "name": "TeamInTournament_tournament_id_team_id_pk" + } + }, + "uniqueConstraints": {} + }, + "TeamScore": { + "name": "TeamScore", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "score": { + "name": "score", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "block_id": { + "name": "block_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "team_id": { + "name": "team_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "TeamScore_block_id_MatchBlock_id_fk": { + "name": "TeamScore_block_id_MatchBlock_id_fk", + "tableFrom": "TeamScore", + "tableTo": "MatchBlock", + "columnsFrom": [ + "block_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "TeamScore_team_id_Team_id_fk": { + "name": "TeamScore_team_id_Team_id_fk", + "tableFrom": "TeamScore", + "tableTo": "Team", + "columnsFrom": [ + "team_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "Tournament": { + "name": "Tournament", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "acronym": { + "name": "acronym", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "settings_id": { + "name": "settings_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "allow_registrations": { + "name": "allow_registrations", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "private": { + "name": "private", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "team_size": { + "name": "team_size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "banner_url": { + "name": "banner_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "icon_url": { + "name": "icon_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "Tournament_settings_id_Settings_id_fk": { + "name": "Tournament_settings_id_Settings_id_fk", + "tableFrom": "Tournament", + "tableTo": "Settings", + "columnsFrom": [ + "settings_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "User": { + "name": "User", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "country_code": { + "name": "country_code", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "country_name": { + "name": "country_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "cover_url": { + "name": "cover_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "pp": { + "name": "pp", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "global_rank": { + "name": "global_rank", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "country_rank": { + "name": "country_rank", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "total_score": { + "name": "total_score", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ranked_score": { + "name": "ranked_score", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hit_accuracy": { + "name": "hit_accuracy", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "play_count": { + "name": "play_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "level": { + "name": "level", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "level_progress": { + "name": "level_progress", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "UserInTeam": { + "name": "UserInTeam", + "columns": { + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "team_id": { + "name": "team_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "invite": { + "name": "invite", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "member_order": { + "name": "member_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "UserInTeam_user_id_User_id_fk": { + "name": "UserInTeam_user_id_User_id_fk", + "tableFrom": "UserInTeam", + "tableTo": "User", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "UserInTeam_team_id_Team_id_fk": { + "name": "UserInTeam_team_id_Team_id_fk", + "tableFrom": "UserInTeam", + "tableTo": "Team", + "columnsFrom": [ + "team_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "UserInTeam_user_id_team_id_pk": { + "columns": [ + "team_id", + "user_id" + ], + "name": "UserInTeam_user_id_team_id_pk" + } + }, + "uniqueConstraints": {} + } + }, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/src/lib/drizzle/meta/_journal.json b/src/lib/drizzle/meta/_journal.json new file mode 100644 index 0000000..cd1278a --- /dev/null +++ b/src/lib/drizzle/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "7", + "dialect": "sqlite", + "entries": [ + { + "idx": 0, + "version": "6", + "when": 1717345116396, + "tag": "0000_thin_vindicator", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/src/lib/drizzle/schema.dbml b/src/lib/drizzle/schema.dbml new file mode 100644 index 0000000..4a1473a --- /dev/null +++ b/src/lib/drizzle/schema.dbml @@ -0,0 +1,256 @@ +table BlockSection { + id integer [pk, not null, increment] + match_id integer [not null] + mappool_id integer [not null] + action text [not null] +} + +table Map { + id integer [pk, not null] + beatmapset_id integer [not null] + fetch_time integer [not null, default: `(CURRENT_TIMESTAMP)`] + title text [not null] + artist text [not null] + difficulty_name text [not null] + url text [not null] + cover_url text [not null] + status text [not null] + max_combo integer [not null] + last_updated integer [not null] + available integer [not null] +} + +table MapInPool { + identifier text [not null] + map_order integer + mods text [not null] + mappool_id integer [not null] + map_id integer + tournamentSettingsId integer + + indexes { + (identifier, mappool_id) [pk] + } +} + +table MapStats { + map_id integer [not null] + mod_string text [not null, default: ''] + star_rating real [not null] + bpm real [not null] + length integer [not null] + cs real [not null] + ar real [not null] + od real [not null] + hp real [not null] + + indexes { + (map_id, mod_string) [pk] + } +} + +table Mappool { + id integer [pk, not null, increment] + name text [not null] + public integer [not null, default: 1] +} + +table MappoolInRound { + mappool_id integer [not null] + round_id integer [not null] + + indexes { + (mappool_id, round_id) [pk] + } +} + +table Match { + id integer [pk, not null, increment] + start_time integer + mp_link text + scrim integer [not null, default: 0] + current_section_id integer [not null] + block_in_section_id integer [not null] + round_id integer + settings_id integer +} + +table MatchBlock { + id integer [pk, not null, increment] + section_id integer [not null] + action text [not null] + order_number integer [not null] + map_identifier text + pool_id integer + acted_on_by_id integer +} + +table ModMultiplier { + id integer [pk, not null, increment] + settings_id integer + multiplier real [not null] + mod_string text [not null] + match_exactly integer [not null] +} + +table Round { + id integer [pk, not null, increment] + acronym text [not null] + name text [not null] + tournament_id integer [not null] +} + +table Score { + id integer [pk, not null, increment] + score real [not null] + mods text + block_id integer [not null] + user_id integer [not null] + team_score_id integer +} + +table Settings { + id integer [pk, not null, increment] + gamemode integer [not null, default: 0] + team_mode integer [not null] + score_mode integer [not null] + force_nf integer [not null, default: 1] + fm_mods integer [not null, default: 1] + player_count integer [not null] + tournament_id integer [unique] + match_id integer [unique] +} + +table Team { + id integer [pk, not null, increment] + name text [not null] + icon_url text + color text [not null] + timezone integer +} + +table TeamInMatch { + id integer [pk, not null, increment] + match_id integer [not null] + team_id integer + score integer [not null] + roll integer + winner integer + aborts integer [not null, default: 0] + faults integer [not null, default: 0] +} + +table TeamInTournament { + tournament_id integer + team_id integer + + indexes { + (tournament_id, team_id) [pk] + } +} + +table TeamScore { + id integer [pk, not null, increment] + score real [not null] + block_id integer [not null] + team_id integer [not null] +} + +table Tournament { + id integer [pk, not null, increment] + name text [not null] + acronym text [not null] + settings_id integer + allow_registrations integer [not null, default: 1] + private integer [not null] + team_size integer [not null] + color text + banner_url text + description text + icon_url text +} + +table User { + id integer [pk, not null] + username text [not null] + country_code text [not null] + country_name text [not null] + cover_url text [not null] + avatar_url text [not null] + pp real + global_rank integer + country_rank integer + total_score integer + ranked_score integer + hit_accuracy real + play_count integer + level integer + level_progress integer +} + +table UserInTeam { + user_id integer [not null] + team_id integer [not null] + invite integer + member_order integer [default: 0] + + indexes { + (user_id, team_id) [pk] + } +} + +ref: BlockSection.match_id - Match.id + +ref: MapInPool.mappool_id > Mappool.id + +ref: MapInPool.tournamentSettingsId > Settings.id + +ref: MapInPool.map_id > Map.id + +ref: MapStats.map_id > Map.id + +ref: MappoolInRound.round_id > Round.id + +ref: MappoolInRound.mappool_id > Mappool.id + +ref: MatchBlock.acted_on_by_id > TeamInMatch.id + +ref: MatchBlock.(map_identifier, pool_id) > MapInPool.(identifier, mappool_id) + +ref: MatchBlock.section_id > BlockSection.id + +ref: Match.settings_id > Settings.id + +ref: Match.round_id > Round.id + +ref: Match.current_section_id - BlockSection.id + +ref: Match.block_in_section_id - MatchBlock.id + +ref: ModMultiplier.settings_id - Settings.id + +ref: Round.tournament_id > Tournament.id + +ref: Score.team_score_id > TeamScore.id + +ref: Score.user_id > User.id + +ref: Score.block_id > MatchBlock.id + +ref: TeamInMatch.team_id > Team.id + +ref: TeamInMatch.match_id - Match.id + +ref: TeamInTournament.tournament_id > Tournament.id + +ref: TeamInTournament.team_id > Team.id + +ref: TeamScore.team_id > Team.id + +ref: TeamScore.block_id > MatchBlock.id + +ref: Tournament.settings_id > Settings.id + +ref: UserInTeam.team_id > Team.id + +ref: UserInTeam.user_id > User.id \ No newline at end of file diff --git a/src/lib/drizzle/schema/relations.ts b/src/lib/drizzle/schema/relations.ts new file mode 100644 index 0000000..543db06 --- /dev/null +++ b/src/lib/drizzle/schema/relations.ts @@ -0,0 +1,220 @@ +import { relations } from "drizzle-orm/relations"; +import { Match, Settings, Tournament, Round, MappoolInRound, Mappool, MapInPool, Map, User, Team, UserInTeam, BlockSection, TeamInMatch, MatchBlock, TeamScore, Score, ModMultiplier, MapStats, TeamInTournament } from "./schema"; + + +export const TournamentRelations = relations(Tournament, ({ one, many }) => ({ + rounds: many(Round), + team_list: many(TeamInTournament), + + settings: one(Settings, { + fields: [Tournament.settings_id], + references: [Settings.id] + }), +})); + +export const SettingsRelations = relations(Settings, ({ many }) => ({ + applied_to_tournament: many(Tournament), + applied_to_matches: many(Match), + applied_to_maps: many(MapInPool), +})); + +export const ModMultiplierRelations = relations(ModMultiplier, ({ one }) => ({ + settings: one(Settings, { + fields: [ModMultiplier.settings_id], + references: [Settings.id] + }), +})); + +export const RoundRelations = relations(Round, ({ one, many }) => ({ + tournament: one(Tournament, { + fields: [Round.tournament_id], + references: [Tournament.id] + }), + mappool_list: many(MappoolInRound), + matches: many(Match), +})); + +export const MappoolInRoundRelations = relations(MappoolInRound, ({ one }) => ({ + round: one(Round, { + fields: [MappoolInRound.round_id], + references: [Round.id] + }), + mappool: one(Mappool, { + fields: [MappoolInRound.mappool_id], + references: [Mappool.id] + }), +})); + +export const MappoolRelations = relations(Mappool, ({ many }) => ({ + rounds_list: many(MappoolInRound), + maps_in_pool: many(MapInPool), + section_list: many(BlockSection), +})); + +export const MapInPoolRelations = relations(MapInPool, ({ one, many }) => ({ + mappool: one(Mappool, { + fields: [MapInPool.mappool_id], + references: [Mappool.id] + }), + settings: one(Settings, { + fields: [MapInPool.settings_id], + references: [Settings.id] + }), + map_data: one(Map, { + fields: [MapInPool.map_id], + references: [Map.id] + }), + + used_in: many(MatchBlock), +})); + +export const MapRelations = relations(Map, ({ many }) => ({ + in_pools: many(MapInPool), + stats: many(MapStats) +})); + +export const MapStatsRelations = relations(MapStats, ({ one }) => ({ + for_map: one(Map, { + fields: [MapStats.map_id], + references: [Map.id] + }) +})) + +export const UserRelations = relations(User, ({ many }) => ({ + in_teams_list: many(UserInTeam), + scores: many(Score), +})); + +export const UserInTeamRelations = relations(UserInTeam, ({ one }) => ({ + team: one(Team, { + fields: [UserInTeam.team_id], + references: [Team.id] + }), + user: one(User, { + fields: [UserInTeam.user_id], + references: [User.id] + }), +})); + +export const TeamRelations = relations(Team, ({ many }) => ({ + tournament_list: many(TeamInTournament), + user_list: many(UserInTeam), + match_list: many(TeamInMatch), + team_scores: many(TeamScore), +})); + +export const TeamInTournamentRelations = relations(TeamInTournament, ({ one }) => ({ + tournament: one(Tournament, { + fields: [TeamInTournament.tournament_id], + references: [Tournament.id] + }), + team: one(Team, { + fields: [TeamInTournament.team_id], + references: [Team.id] + }) +})) + +export const MatchRelations = relations(Match, ({ one, many }) => ({ + settings: one(Settings, { + fields: [Match.settings_id], + references: [Settings.id] + }), + round: one(Round, { + fields: [Match.round_id], + references: [Round.id] + }), + sections: many(BlockSection, { relationName: 'section_list' }), + team_list: many(TeamInMatch, { relationName: 'team_list' }), + + // Match state + current_section: one(BlockSection, { + fields: [Match.current_section_id], + references: [BlockSection.id], + relationName: "current_section" + }), + current_block: one(MatchBlock, { + fields: [Match.block_in_section_id], + references: [MatchBlock.id], + relationName: "current_block" + }) +})); + +export const BlockSectionRelations = relations(BlockSection, ({ one, many }) => ({ + for_match: one(Match, { + fields: [BlockSection.match_id], + references: [Match.id], + relationName: 'section_list' + }), + current_for: one(Match, { + fields: [BlockSection.match_id], + references: [Match.current_section_id], + relationName: 'current_section' + }), + mappool: one(Mappool, { + fields: [BlockSection.mappool_id], + references: [Mappool.id] + }), + blocks: many(MatchBlock), +})); + +export const MatchBlockRelations = relations(MatchBlock, ({ one, many }) => ({ + actor_team: one(TeamInMatch, { + fields: [MatchBlock.acted_on_by_id], + references: [TeamInMatch.id] + }), + map: one(MapInPool, { + fields: [MatchBlock.map_identifier, MatchBlock.pool_id], + references: [MapInPool.identifier, MapInPool.mappool_id] + }), + BlockSection: one(BlockSection, { + fields: [MatchBlock.section_id], + references: [BlockSection.id] + }), + current_for: one(Match, { + fields: [BlockSection.match_id], + references: [Match.block_in_section_id], + relationName: 'current_block' + }), + Scores: many(Score), + TeamScores: many(TeamScore), +})); + +export const TeamInMatchRelations = relations(TeamInMatch, ({ one, many }) => ({ + acted_on: many(MatchBlock), + team: one(Team, { + fields: [TeamInMatch.team_id], + references: [Team.id] + }), + match: one(Match, { + fields: [TeamInMatch.match_id], + references: [Match.id], + relationName: 'team_list' + }), +})); + +export const ScoreRelations = relations(Score, ({ one }) => ({ + score_for: one(TeamScore, { + fields: [Score.team_score_id], + references: [TeamScore.id] + }), + user: one(User, { + fields: [Score.user_id], + references: [User.id] + }), + for_block: one(MatchBlock, { + fields: [Score.block_id], + references: [MatchBlock.id] + }), +})); + +export const TeamScoreRelations = relations(TeamScore, ({ one, many }) => ({ + user_scores: many(Score), + team: one(Team, { + fields: [TeamScore.team_id], + references: [Team.id] + }), + match: one(MatchBlock, { + fields: [TeamScore.block_id], + references: [MatchBlock.id] + }), +})); \ No newline at end of file diff --git a/src/lib/drizzle/schema/schema.ts b/src/lib/drizzle/schema/schema.ts new file mode 100644 index 0000000..39a7019 --- /dev/null +++ b/src/lib/drizzle/schema/schema.ts @@ -0,0 +1,339 @@ +import { sqliteTable, text, integer, real, primaryKey } from "drizzle-orm/sqlite-core" +import { sql } from "drizzle-orm" + +/** + * A tournament hosted on Yagami with multiple hosts. + * + * Mappools imported from external places do not have + * a tournament object. + */ +export const Tournament = sqliteTable("Tournament", { + id: integer("id").primaryKey({ autoIncrement: true }), + name: text("name").notNull(), + acronym: text("acronym").notNull(), // Used in the MP name; [ACRONYM: (Team 1) vs (Team 2)] + + settings_id: integer("settings_id").references(() => Settings.id), + + // Registration Settings + allow_registrations: integer("allow_registrations", { mode: "boolean" }).default(true).notNull(), + private: integer("private", { mode: "boolean" }).notNull(), + team_size: integer("team_size").notNull(), + + // Optional Customization + color: text("color"), + banner_url: text("banner_url"), + description: text("description"), + icon_url: text("icon_url"), +}); + +/** + * Holds in-match settings. + * + * Can be applied: + * * Tournament-wide (for default tournament settings) + * * Match-specific (for scrims) + * * Map-specific (for per-map gimmicks like different mod multipliers) + */ +export const Settings = sqliteTable("Settings", { + id: integer("id").primaryKey({ autoIncrement: true }), + + gamemode: integer("gamemode").default(0).notNull(), // 0: std, 1: taiko, 2: catch, 3: mania + + // !mp set [team_mode] [score_mode] + team_mode: integer("team_mode").notNull(), // 0: Head to Head; 1: TagCoop; 2: TeamVS; 3: TeamTagVs + score_mode: integer("score_mode").notNull(), // 0: Score; 1: Accuracy; 2: Combo; 3: ScoreV2; 4: ScoreV2 Accuracy + + force_nf: integer("force_nf", { mode: 'boolean' }).default(true).notNull(), // Whether to add NF to every pick + fm_mods: integer("fm_mods").default(1).notNull(), // How many players need to take a mod + player_count: integer("player_count").notNull(), // How many players vs how many players + + // Foreign Keys + tournament_id: integer("tournament_id").unique().references(() => Tournament.id, { onDelete: "set null", onUpdate: "cascade" }), + match_id: integer("match_id").unique().references(() => Match.id, { onDelete: "set null", onUpdate: "cascade" }), +}); + +/** + * A custom multiplier to be applied to a FreeMod pick + * + * If some mod combination matches multiple mod multipliers, + * all multipliers are averaged, then applied. + */ +export const ModMultiplier = sqliteTable("ModMultiplier", { + id: integer("id").primaryKey({ autoIncrement: true }), + settings_id: integer("settings_id").references(() => Settings.id, { onDelete: "cascade", onUpdate: "cascade" }), + + multiplier: real("multiplier").notNull(), + + // What to match, HD, HR, HDHR etc. + mod_string: text("mod_string").notNull(), + // For example, if a player takes HDHR and the rule is HD - 0.90, rule is applied if match_exactly is false, otherwise it is ignored. + match_exactly: integer("match_exactly", { mode: 'boolean' }).notNull(), +}); + +/** + * A round in the tournament + * + * Can have multiple matches or mappools linked. + */ +export const Round = sqliteTable("Round", { + id: integer("id").primaryKey({ autoIncrement: true }), + acronym: text("acronym").notNull(), + name: text("name").notNull(), + + tournament_id: integer("tournament_id").notNull().references(() => Tournament.id, { onDelete: "cascade", onUpdate: "cascade" }), +}); + +/** + * Linker table for many-to-many relations between Mappool and Round + */ +export const MappoolInRound = sqliteTable("MappoolInRound", { + mappool_id: integer("mappool_id").notNull().references(() => Mappool.id, { onDelete: "restrict", onUpdate: "cascade" }), + round_id: integer("round_id").notNull().references(() => Round.id, { onDelete: "restrict", onUpdate: "cascade" }), +}, + (table) => ({ + composite_key: primaryKey({ columns: [table.mappool_id, table.round_id] }) + })); + +/** + * A list of maps + * + * References multiple MapInPool objects + */ +export const Mappool = sqliteTable("Mappool", { + id: integer("id").primaryKey({ autoIncrement: true }), + name: text("name").notNull(), + public: integer("public", { mode: 'boolean' }).default(true).notNull(), +}); + +/** + * A map in a mappool + * + * Has fields for the name, (NM1, HD2 etc.), + * and references some Map object for map data. + */ +export const MapInPool = sqliteTable("MapInPool", { + identifier: text("identifier").notNull(), // NM1, NM2 etc. + + map_order: integer("map_order"), // Where this map appears in the pool (NM1 is 1, NM2 is 2 etc.) + mods: text("mods").notNull(), // !mp mods [mods] (force_nf ? "NF" : "") + + // Foreign Keys + mappool_id: integer("mappool_id").notNull().references(() => Mappool.id, { onDelete: "cascade", onUpdate: "cascade" }), + map_id: integer("map_id").references(() => Map.id, { onDelete: "set null", onUpdate: "cascade" }), + settings_id: integer("settings_id").references(() => Settings.id, { onDelete: "set null", onUpdate: "cascade" }), +}, + (table) => ({ + composite_key: primaryKey({ columns: [table.identifier, table.mappool_id] }) + })); + +/** + * Cache object for maps from the osu!api + */ +export const Map = sqliteTable("Map", { + id: integer("id").primaryKey(), + beatmapset_id: integer("beatmapset_id").notNull(), + fetch_time: integer("fetch_time", { mode: 'timestamp_ms' }).default(sql`(CURRENT_TIMESTAMP)`).notNull(), + + // Rendered as "title - artist [difficulty_name]" in chat + title: text("title").notNull(), + artist: text("artist").notNull(), + difficulty_name: text("difficulty_name").notNull(), + + // Additional Fields for displaying nicely in a Web format. + url: text("url").notNull(), + cover_url: text("cover_url").notNull(), + status: text("status").notNull(), + max_combo: integer("max_combo").notNull(), + last_updated: integer("last_updated", { mode: 'timestamp_ms' }).notNull(), + + // Whether a user is able to download + // using osu!direct/official servers + available: integer("available", { mode: 'boolean' }).notNull(), +}); + +/** + * Represents stats about a map + * + * Linked to a Map, with some mod_string. For displaying NM stats, DT stats, etc. + * mod_string should match the string of the MapInPool object ("" means nomod) + */ +export const MapStats = sqliteTable('MapStats', { + map_id: integer('map_id',).notNull().references(() => Map.id, { onDelete: 'cascade', onUpdate: 'cascade' }), + mod_string: text('mod_string').default("").notNull(), + + star_rating: real("star_rating").notNull(), + bpm: real("bpm").notNull(), + length: integer("length").notNull(), // Length of map in seconds + + cs: real("cs").notNull(), + ar: real("ar").notNull(), + od: real("od").notNull(), + hp: real("hp").notNull(), +}, (table) => ({ + composite_key: primaryKey({ columns: [table.map_id, table.mod_string] }) +})) + +/** + * Represents an osu user. + * + * id column is shared with osu! id. + */ +export const User = sqliteTable("User", { + id: integer("id").primaryKey(), + username: text("username").notNull(), + country_code: text("country_code").notNull(), + country_name: text("country_name").notNull(), + + cover_url: text("cover_url").notNull(), + avatar_url: text("avatar_url").notNull(), + + pp: real("pp"), + global_rank: integer("global_rank"), + country_rank: integer("country_rank"), + + total_score: integer("total_score"), + ranked_score: integer("ranked_score"), + hit_accuracy: real("hit_accuracy"), + play_count: integer("play_count"), + level: integer("level"), + level_progress: integer("level_progress"), +}); + + +/** + * Linker table for many-to-many relations between User and Team + * + * - When listing players in a team, ignore users with invite=true + */ +export const UserInTeam = sqliteTable("UserInTeam", { + user_id: integer("user_id").notNull().references(() => User.id, { onDelete: "cascade", onUpdate: "cascade" }), + team_id: integer("team_id").notNull().references(() => Team.id, { onDelete: "cascade", onUpdate: "cascade" }), + invite: integer("invite", { mode: 'boolean' }), // If true, the user is not a member of the team (they have been invited and have not accepted) + member_order: integer("member_order").default(0), // Where in the team the user appears. (Captain is 0, etc.) +}, + (table) => ({ + composite_key: primaryKey({ columns: [table.user_id, table.team_id] }) + })); + +/** + * Represents a Team for a tournament or scrim. + * + * - A team can be in multiple Tournaments or scrims + * - 1v1 matches still use Teams, just a Team consisting of 1 player. + */ +export const Team = sqliteTable("Team", { + id: integer("id").primaryKey({ autoIncrement: true }), + name: text("name").notNull(), + icon_url: text("icon_url"), + color: text("color").notNull(), + timezone: integer("timezone"), +}); + +/** + * A linker table for many-to-many relations between Team and Tournament + */ +export const TeamInTournament = sqliteTable("TeamInTournament", { + tournament_id: integer("tournament_id").references(() => Tournament.id), + team_id: integer("team_id").references(() => Team.id), +}, (table) => ({ + composite_key: primaryKey({ columns: [table.tournament_id, table.team_id] }) +})) + +/** + * Represents a match that is or has run + * + * The state of the match is stored entirely within the database. + */ +export const Match = sqliteTable("Match", { + id: integer("id").primaryKey({ autoIncrement: true }).notNull(), + start_time: integer("start_time", { mode: 'timestamp_ms' }), + mp_link: text("mp_link"), + + scrim: integer("scrim", { mode: 'boolean' }).default(false).notNull(), + + // The current state of the match: + current_section_id: integer("current_section_id").notNull().references(() => BlockSection.id), // What block section are we currently on + block_in_section_id: integer("block_in_section_id").notNull().references(() => MatchBlock.id), // What block in the section are we currently on + + round_id: integer("round_id").references(() => Round.id, { onDelete: "set null", onUpdate: "cascade" }), + settings_id: integer("settings_id").references(() => Settings.id, { onDelete: "restrict", onUpdate: "cascade" }) +}); + +/** + * A set ordered blocks with some common action. + * When a team runs out of time to do some action, + * the block is moved to the end of the list. + * (MatchBlock.order_number => MatchBlocks.maxOrderNumber() + 1) + */ +export const BlockSection = sqliteTable("BlockSection", { + id: integer("id").primaryKey({ autoIncrement: true }).notNull(), + match_id: integer("match_id").notNull().references(() => Match.id, { onDelete: "cascade", onUpdate: "cascade" }), + mappool_id: integer("mappool_id").notNull().references(() => Mappool.id), + + action: text("action").notNull(), // PICK, BAN, PROTECT, FORCED PICK etc. +}); + +/** + * A block where something happens in a match, be it pick, ban, protect etc. + */ +export const MatchBlock = sqliteTable("MatchBlock", { + id: integer("id").primaryKey({ autoIncrement: true }).notNull(), + + // Which section + section_id: integer("section_id").notNull().references(() => BlockSection.id), + action: text("action").notNull().references(() => BlockSection.id), + + order_number: integer("order_number").notNull(), + + // Which map + map_identifier: text("map_identifier").references(() => MapInPool.identifier), + pool_id: integer("pool_id").references(() => MapInPool.mappool_id), + + // Who did it + acted_on_by_id: integer("acted_on_by_id").references(() => TeamInMatch.id, { onDelete: "cascade", onUpdate: "cascade" }), +}); + +/** + * A Team object that is a member of a Match + * Linker table for many-to-many relations between Team and Match + */ +export const TeamInMatch = sqliteTable("TeamInMatch", { + id: integer("id").primaryKey({ autoIncrement: true }).notNull(), + match_id: integer("match_id").notNull().references(() => Match.id, { onDelete: "cascade", onUpdate: "cascade" }), + team_id: integer("team_id").references(() => Team.id, { onDelete: "set null", onUpdate: "cascade" }), + + score: integer("score").notNull(), + roll: integer("roll"), + winner: integer("winner", { mode: 'boolean' }), + + // Honor System + aborts: integer("aborts").default(0).notNull(), + faults: integer("faults").default(0).notNull(), +}); + +/** + * A user's score on a map (MatchBlock) + * + * Contains references to a team score (for a team's score) + */ +export const Score = sqliteTable("Score", { + id: integer("id").primaryKey({ autoIncrement: true }).notNull(), + + score: real("score").notNull(), // This is stored as a real number for storing either Score or Accuracy + mods: text("mods"), // In the case of freemods + + block_id: integer("block_id").notNull().references(() => MatchBlock.id, { onDelete: "cascade", onUpdate: "cascade" }), + user_id: integer("user_id").notNull().references(() => User.id, { onDelete: "cascade", onUpdate: "cascade" }), + team_score_id: integer("team_score_id").references(() => TeamScore.id, { onDelete: "set null", onUpdate: "cascade" }), +}); + +/** + * A team's score on a map (MatchBlock) + */ +export const TeamScore = sqliteTable("TeamScore", { + id: integer("id").primaryKey({ autoIncrement: true }).notNull(), + score: real("score").notNull(), + + block_id: integer("block_id").notNull().references(() => MatchBlock.id, { onDelete: "cascade", onUpdate: "cascade" }), + team_id: integer("team_id").notNull().references(() => Team.id, { onDelete: "cascade", onUpdate: "cascade" }), +}); \ No newline at end of file diff --git a/src/prisma.ts b/src/prisma.ts deleted file mode 100644 index 0a7fbaa..0000000 --- a/src/prisma.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { PrismaClient } from '@prisma/client'; -export const prisma = new PrismaClient(); diff --git a/src/rest/docs/index.ts b/src/rest/docs/index.ts deleted file mode 100644 index 8e2c888..0000000 --- a/src/rest/docs/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import swagger from '@elysiajs/swagger'; - -export default swagger({ - exclude: ['/'], - documentation: { - tags: [{ name: 'Tournaments' }], - info: { - title: 'Yagami API Documentation', - version: '1.0.0', - description: 'The RESTFUL-facing API that allows you to interact with the Yagami Database', - contact: { - name: 'clxxiii', - url: 'https://yagami.app', - email: 'info@yagami.app', - }, - }, - }, -}); diff --git a/src/rest/index.ts b/src/rest/index.ts deleted file mode 100644 index 9284305..0000000 --- a/src/rest/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Elysia from 'elysia'; -import { tournament } from './tournament'; -import swagger from './docs'; - -const { DOCS_URL } = process.env; - -export const rest = new Elysia() - .use(swagger) - .use(tournament) - .get('/', ({ set }) => (set.redirect = DOCS_URL), {}); diff --git a/src/rest/tournament/get.ts b/src/rest/tournament/get.ts deleted file mode 100644 index 220d7d6..0000000 --- a/src/rest/tournament/get.ts +++ /dev/null @@ -1,76 +0,0 @@ -import Elysia from 'elysia'; -import { prisma } from '../../prisma'; -import { LocalHook } from 'elysia'; - -const hooks: LocalHook = { - beforeHandle: ({ params: { id }, set }) => { - if (isNaN(parseInt(id))) { - set.status = 'Bad Request'; - return { - error: 'Tournament ID is not a number', - }; - } - }, - detail: { - tags: ['Tournaments'], - }, -}; - -export const get = new Elysia() - .get('/:id/get_partial', ({ params }) => getPartial(params.id), hooks) - .get('/:id/get_full', ({ params }) => getFull(params.id), hooks); - -const getPartial = async (id: string) => { - const tournament = await prisma.tournament.findUnique({ - where: { - id: parseInt(id), - }, - }); - return tournament; -}; - -const getFull = async (id: string) => { - const tournament = await prisma.tournament.findUnique({ - where: { - id: parseInt(id), - }, - include: { - Hosts: { - select: { - User: { - select: { - id: true, - username: true, - }, - }, - }, - }, - rounds: { - include: { - Match: { - include: { - MapsInMatch: true, - Teams: { - include: { - Team: true, - }, - }, - }, - }, - mappool: { - include: { - Maps: { - select: { - mods: true, - identifier: true, - mapId: true, - }, - }, - }, - }, - }, - }, - }, - }); - return tournament; -}; diff --git a/src/rest/tournament/index.ts b/src/rest/tournament/index.ts deleted file mode 100644 index 831f8e1..0000000 --- a/src/rest/tournament/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Elysia } from 'elysia'; -import { get } from './get'; - -export const tournament = new Elysia({ prefix: '/tournaments' }).use(get); diff --git a/src/ws/index.ts b/src/ws/index.ts deleted file mode 100644 index 23bf3e9..0000000 --- a/src/ws/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import Elysia from 'elysia'; - -export const websocket = new Elysia().ws('/ws', { - message: (ws, message) => {}, -});