diff --git a/.vscode/settings.json b/.vscode/settings.json index 4a1f28c2..4480f811 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -43,17 +43,22 @@ "kalos", "nitropack", "paldea", + "preconfigured", "Pressable", "prettiercache", "sinnoh", "sluggable", + "Solito", "subrouters", + "Supabase", "thatguyinabenaie", "tsbuildinfo", "tseslint", + "Turborepo", "typesafe", "unauthed", "unova", + "unviable", "Ursaluna" ], "coverage-gutters.showGutterCoverage": false, diff --git a/README.md b/README.md index a8b2f204..771c2077 100644 --- a/README.md +++ b/README.md @@ -128,11 +128,11 @@ In order to get Next-Auth to work with Expo, you must either: In [apps/auth-proxy](./apps/auth-proxy) you can find a Nitro server that proxies OAuth requests. By deploying this and setting the `AUTH_REDIRECT_PROXY_URL` environment variable to the URL of this proxy, you can get OAuth working in preview deployments and development for Expo apps. See more deployment instructions in the [auth proxy README](./apps/auth-proxy/README.md). -By using the proxy server, the Next.js apps will forward any auth requests to the proxy server, which will handle the OAuth flow and then redirect back to the Next.js app. This makes it easy to get OAuth working since you'll have a stable URL that is publically accessible and doesn't change for every deployment and doesn't rely on what port the app is running on. So if port 3000 is taken and your Next.js app starts at port 3001 instead, your auth should still work without having to reconfigure the OAuth provider. +By using the proxy server, the Next.js apps will forward any auth requests to the proxy server, which will handle the OAuth flow and then redirect back to the Next.js app. This makes it easy to get OAuth working since you'll have a stable URL that is publicly accessible and doesn't change for every deployment and doesn't rely on what port the app is running on. So if port 3000 is taken and your Next.js app starts at port 3001 instead, your auth should still work without having to reconfigure the OAuth provider. #### Add your local IP to your OAuth provider -You can alternatively add your local IP (e.g. `192.168.x.y:$PORT`) to your OAuth provider. This may not be as reliable as your local IP may change when you change networks. Some OAuth providers may also only support a single callback URL for each app making this approach unviable for some providers (e.g. GitHub). +You can alternatively add your local IP (e.g. `192.168.x.y:$PORT`) to your OAuth provider. This may not be as reliable as your local IP may change when you change networks. Some OAuth providers may also only support a single callback URL for each app making this approach not viable for some providers (e.g. GitHub). ### 4a. When it's time to add a new UI component @@ -160,7 +160,7 @@ Integrating Solito into this repo isn't hard, and there are a few [official temp ### Does this pattern leak backend code to my client applications? -No, it does not. The `api` package should only be a production dependency in the Next.js application where it's served. The Expo app, and all other apps you may add in the future, should only add the `api` package as a dev dependency. This lets you have full typesafety in your client applications, while keeping your backend code safe. +No, it does not. The `api` package should only be a production dependency in the Next.js application where it's served. The Expo app, and all other apps you may add in the future, should only add the `api` package as a dev dependency. This lets you have full type safety in your client applications, while keeping your backend code safe. If you need to share runtime code between the client and server, such as input validation schemas, you can create a separate `shared` package for this and import it on both sides. diff --git a/apps/nextjs/src/app/server-actions/pokemon/actions.ts b/apps/nextjs/src/app/server-actions/pokemon/actions.ts index 6756f211..12a41da8 100644 --- a/apps/nextjs/src/app/server-actions/pokemon/actions.ts +++ b/apps/nextjs/src/app/server-actions/pokemon/actions.ts @@ -12,16 +12,18 @@ export async function getPokemonTeams() { export async function postPokemonTeam( validatedTeam: ValidatedPokemon[], metadata: PokePasteMetadata, - profileId?: bigint, + // profileId: bigint, + // gameId: bigint, + // formatId: bigint, ) { const body = { pokepasteId: metadata.id, - profileId: profileId, + profileId: 1n, name: metadata.title, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), - gameId: BigInt(1), - formatId: BigInt(1), + gameId: 1n, + formatId: 1n, }; const pokemonTeamResult = await db diff --git a/packages/db/drizzle.config.ts b/packages/db/drizzle.config.ts index f71362c1..4060c3de 100644 --- a/packages/db/drizzle.config.ts +++ b/packages/db/drizzle.config.ts @@ -8,7 +8,7 @@ if (!process.env.DATABASE_URL) { const nonPoolingUrl = process.env.DATABASE_URL.replace(":6543", ":5432"); export default defineConfig({ - schema: "./src/schema.ts", + schema: "./drizzle/schema.ts", dialect: "postgresql", dbCredentials: { url: nonPoolingUrl }, casing: "snake_case", diff --git a/packages/db/src/relations.ts b/packages/db/drizzle/relations.ts similarity index 99% rename from packages/db/src/relations.ts rename to packages/db/drizzle/relations.ts index 05588fed..4b860300 100644 --- a/packages/db/src/relations.ts +++ b/packages/db/drizzle/relations.ts @@ -19,15 +19,15 @@ import { rounds, tournamentFormats, tournaments, -} from "./schemas"; +} from "./schema"; export const formatsRelations = relations(formats, ({ one, many }) => ({ game: one(games, { fields: [formats.gameId], references: [games.id], }), - tournamentFormats: many(tournamentFormats), pokemonTeams: many(pokemonTeams), + tournamentFormats: many(tournamentFormats), })); export const gamesRelations = relations(games, ({ many }) => ({ @@ -36,138 +36,135 @@ export const gamesRelations = relations(games, ({ many }) => ({ pokemonTeams: many(pokemonTeams), })); -export const organizationStaffMembersRelations = relations( - organizationStaffMembers, - ({ one }) => ({ - organization: one(organizations, { - fields: [organizationStaffMembers.organizationId], - references: [organizations.id], - }), - account: one(accounts, { - fields: [organizationStaffMembers.accountId], - references: [accounts.id], - }), +export const tournamentsRelations = relations(tournaments, ({ one, many }) => ({ + game: one(games, { + fields: [tournaments.gameId], + references: [games.id], }), -); + organization: one(organizations, { + fields: [tournaments.organizationId], + references: [organizations.id], + }), + phase: one(phases, { + fields: [tournaments.currentPhaseId], + references: [phases.id], + relationName: "tournaments_currentPhaseId_phases_id", + }), + tournamentFormats: many(tournamentFormats), + players: many(players), + phases: many(phases, { + relationName: "phases_tournamentId_tournaments_id", + }), + matches: many(matches), +})); export const organizationsRelations = relations( organizations, ({ one, many }) => ({ + tournaments: many(tournaments), organizationStaffMembers: many(organizationStaffMembers), account: one(accounts, { fields: [organizations.ownerId], references: [accounts.id], }), - tournaments: many(tournaments), }), ); -export const accountsRelations = relations(accounts, ({ one, many }) => ({ - organizationStaffMembers: many(organizationStaffMembers), - organizations: many(organizations), - matches: many(matches), - clerkUsers: many(clerkUsers), - profile: one(profiles, { - fields: [accounts.defaultProfileId], - references: [profiles.id], - relationName: "accounts_defaultProfileId_profiles_id", +export const phasesRelations = relations(phases, ({ one, many }) => ({ + tournaments: many(tournaments, { + relationName: "tournaments_currentPhaseId_phases_id", }), - players: many(players), - profiles: many(profiles, { - relationName: "profiles_accountId_accounts_id", + tournament: one(tournaments, { + fields: [phases.tournamentId], + references: [tournaments.id], + relationName: "phases_tournamentId_tournaments_id", }), - chatMessages: many(chatMessages), -})); - -export const phasePlayersRelations = relations(phasePlayers, ({ one }) => ({ - player: one(players, { - fields: [phasePlayers.playerId], - references: [players.id], + round: one(rounds, { + fields: [phases.currentRoundId], + references: [rounds.id], }), + matches: many(matches), })); -export const playersRelations = relations(players, ({ one, many }) => ({ - phasePlayers: many(phasePlayers), - matches_loserId: many(matches, { - relationName: "matches_loserId_players_id", - }), - matches_playerOneId: many(matches, { - relationName: "matches_playerOneId_players_id", - }), - matches_playerTwoId: many(matches, { - relationName: "matches_playerTwoId_players_id", - }), - matches_winnerId: many(matches, { - relationName: "matches_winnerId_players_id", - }), - matchGames_loserId: many(matchGames, { - relationName: "matchGames_loserId_players_id", - }), - matchGames_winnerId: many(matchGames, { - relationName: "matchGames_winnerId_players_id", - }), +export const pokemonRelations = relations(pokemon, ({ one }) => ({ pokemonTeam: one(pokemonTeams, { - fields: [players.pokemonTeamId], + fields: [pokemon.pokemonTeamId], references: [pokemonTeams.id], }), - tournament: one(tournaments, { - fields: [players.tournamentId], - references: [tournaments.id], +})); + +export const pokemonTeamsRelations = relations( + pokemonTeams, + ({ one, many }) => ({ + pokemon: many(pokemon), + format: one(formats, { + fields: [pokemonTeams.formatId], + references: [formats.id], + }), + game: one(games, { + fields: [pokemonTeams.gameId], + references: [games.id], + }), + profile: one(profiles, { + fields: [pokemonTeams.profileId], + references: [profiles.id], + }), + players: many(players), + }), +); + +export const profilesRelations = relations(profiles, ({ one, many }) => ({ + pokemonTeams: many(pokemonTeams), + matchGames: many(matchGames), + accounts: many(accounts, { + relationName: "accounts_defaultProfileId_profiles_id", }), + players: many(players), account: one(accounts, { - fields: [players.accountId], + fields: [profiles.accountId], references: [accounts.id], + relationName: "profiles_accountId_accounts_id", }), - profile: one(profiles, { - fields: [players.profileId], - references: [profiles.id], - }), + chatMessages: many(chatMessages), })); -export const phasesRelations = relations(phases, ({ one, many }) => ({ - tournament: one(tournaments, { - fields: [phases.tournamentId], - references: [tournaments.id], - relationName: "phases_tournamentId_tournaments_id", - }), - round: one(rounds, { - fields: [phases.currentRoundId], - references: [rounds.id], - }), - matches: many(matches), - tournaments: many(tournaments, { - relationName: "tournaments_currentPhaseId_phases_id", +export const tournamentFormatsRelations = relations( + tournamentFormats, + ({ one }) => ({ + format: one(formats, { + fields: [tournamentFormats.formatId], + references: [formats.id], + }), + tournament: one(tournaments, { + fields: [tournamentFormats.tournamentId], + references: [tournaments.id], + }), }), -})); +); -export const tournamentsRelations = relations(tournaments, ({ one, many }) => ({ - phases: many(phases, { - relationName: "phases_tournamentId_tournaments_id", +export const matchGamesRelations = relations(matchGames, ({ one }) => ({ + match: one(matches, { + fields: [matchGames.matchId], + references: [matches.id], }), - matches: many(matches), - tournamentFormats: many(tournamentFormats), - game: one(games, { - fields: [tournaments.gameId], - references: [games.id], + player_loserId: one(players, { + fields: [matchGames.loserId], + references: [players.id], + relationName: "matchGames_loserId_players_id", }), - organization: one(organizations, { - fields: [tournaments.organizationId], - references: [organizations.id], + player_winnerId: one(players, { + fields: [matchGames.winnerId], + references: [players.id], + relationName: "matchGames_winnerId_players_id", }), - phase: one(phases, { - fields: [tournaments.currentPhaseId], - references: [phases.id], - relationName: "tournaments_currentPhaseId_phases_id", + profile: one(profiles, { + fields: [matchGames.reporterProfileId], + references: [profiles.id], }), - players: many(players), -})); - -export const roundsRelations = relations(rounds, ({ many }) => ({ - phases: many(phases), - matches: many(matches), })); export const matchesRelations = relations(matches, ({ one, many }) => ({ + matchGames: many(matchGames), player_loserId: one(players, { fields: [matches.loserId], references: [players.id], @@ -204,92 +201,95 @@ export const matchesRelations = relations(matches, ({ one, many }) => ({ fields: [matches.resetById], references: [accounts.id], }), - matchGames: many(matchGames), chatMessages: many(chatMessages), })); -export const tournamentFormatsRelations = relations( - tournamentFormats, - ({ one }) => ({ - format: one(formats, { - fields: [tournamentFormats.formatId], - references: [formats.id], - }), - tournament: one(tournaments, { - fields: [tournamentFormats.tournamentId], - references: [tournaments.id], - }), +export const playersRelations = relations(players, ({ one, many }) => ({ + matchGames_loserId: many(matchGames, { + relationName: "matchGames_loserId_players_id", + }), + matchGames_winnerId: many(matchGames, { + relationName: "matchGames_winnerId_players_id", }), -); - -export const pokemonRelations = relations(pokemon, ({ one }) => ({ pokemonTeam: one(pokemonTeams, { - fields: [pokemon.pokemonTeamId], + fields: [players.pokemonTeamId], references: [pokemonTeams.id], }), + tournament: one(tournaments, { + fields: [players.tournamentId], + references: [tournaments.id], + }), + account: one(accounts, { + fields: [players.accountId], + references: [accounts.id], + }), + profile: one(profiles, { + fields: [players.profileId], + references: [profiles.id], + }), + phasePlayers: many(phasePlayers), + matches_loserId: many(matches, { + relationName: "matches_loserId_players_id", + }), + matches_playerOneId: many(matches, { + relationName: "matches_playerOneId_players_id", + }), + matches_playerTwoId: many(matches, { + relationName: "matches_playerTwoId_players_id", + }), + matches_winnerId: many(matches, { + relationName: "matches_winnerId_players_id", + }), })); -export const pokemonTeamsRelations = relations( - pokemonTeams, - ({ one, many }) => ({ - pokemon: many(pokemon), - format: one(formats, { - fields: [pokemonTeams.formatId], - references: [formats.id], - }), - game: one(games, { - fields: [pokemonTeams.gameId], - references: [games.id], - }), - profile: one(profiles, { - fields: [pokemonTeams.profileId], - references: [profiles.id], - }), - players: many(players), +export const clerkUsersRelations = relations(clerkUsers, ({ one }) => ({ + account: one(accounts, { + fields: [clerkUsers.accountId], + references: [accounts.id], }), -); +})); -export const profilesRelations = relations(profiles, ({ one, many }) => ({ - pokemonTeams: many(pokemonTeams), - matchGames: many(matchGames), - accounts: many(accounts, { +export const accountsRelations = relations(accounts, ({ one, many }) => ({ + clerkUsers: many(clerkUsers), + profile: one(profiles, { + fields: [accounts.defaultProfileId], + references: [profiles.id], relationName: "accounts_defaultProfileId_profiles_id", }), players: many(players), - account: one(accounts, { - fields: [profiles.accountId], - references: [accounts.id], + profiles: many(profiles, { relationName: "profiles_accountId_accounts_id", }), + organizationStaffMembers: many(organizationStaffMembers), + organizations: many(organizations), + matches: many(matches), chatMessages: many(chatMessages), })); -export const matchGamesRelations = relations(matchGames, ({ one }) => ({ - match: one(matches, { - fields: [matchGames.matchId], - references: [matches.id], - }), - player_loserId: one(players, { - fields: [matchGames.loserId], - references: [players.id], - relationName: "matchGames_loserId_players_id", +export const organizationStaffMembersRelations = relations( + organizationStaffMembers, + ({ one }) => ({ + organization: one(organizations, { + fields: [organizationStaffMembers.organizationId], + references: [organizations.id], + }), + account: one(accounts, { + fields: [organizationStaffMembers.accountId], + references: [accounts.id], + }), }), - player_winnerId: one(players, { - fields: [matchGames.winnerId], +); + +export const phasePlayersRelations = relations(phasePlayers, ({ one }) => ({ + player: one(players, { + fields: [phasePlayers.playerId], references: [players.id], - relationName: "matchGames_winnerId_players_id", - }), - profile: one(profiles, { - fields: [matchGames.reporterProfileId], - references: [profiles.id], }), })); -export const clerkUsersRelations = relations(clerkUsers, ({ one }) => ({ - account: one(accounts, { - fields: [clerkUsers.accountId], - references: [accounts.id], - }), +export const roundsRelations = relations(rounds, ({ many }) => ({ + phases: many(phases), + matches: many(matches), })); export const chatMessagesRelations = relations(chatMessages, ({ one }) => ({ diff --git a/packages/db/drizzle/schema.ts b/packages/db/drizzle/schema.ts new file mode 100644 index 00000000..c1b38896 --- /dev/null +++ b/packages/db/drizzle/schema.ts @@ -0,0 +1,1028 @@ +import { sql } from "drizzle-orm"; +import { + bigint, + bigserial, + boolean, + date, + foreignKey, + index, + integer, + numeric, + pgTable, + text, + timestamp, + uniqueIndex, + varchar, +} from "drizzle-orm/pg-core"; + +export const formats = pgTable( + "formats", + { + id: bigserial({ mode: "number" }).primaryKey().notNull(), + name: varchar(), + + gameId: bigint("game_id", { mode: "bigint" }), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (table): Record => { + return { + indexFormatsOnGameId: index("index_formats_on_game_id").using( + "btree", + table.gameId.asc().nullsLast(), + ), + indexFormatsOnNameAndGameId: uniqueIndex( + "index_formats_on_name_and_game_id", + ).using( + "btree", + table.name.asc().nullsLast(), + table.gameId.asc().nullsLast(), + ), + fkRailsA0E0605606: foreignKey({ + columns: [table.gameId], + foreignColumns: [games.id], + name: "fk_rails_a0e0605606", + }), + }; + }, +); + +export const tournaments = pgTable( + "tournaments", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + name: varchar(), + startAt: timestamp("start_at", { precision: 6, mode: "string" }), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + + organizationId: bigint("organization_id", { mode: "bigint" }), + checkInStartAt: timestamp("check_in_start_at", { + precision: 6, + mode: "string", + }), + + gameId: bigint("game_id", { mode: "bigint" }), + + formatId: bigint("format_id", { mode: "bigint" }), + endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), + registrationStartAt: timestamp("registration_start_at", { + precision: 6, + mode: "string", + }), + registrationEndAt: timestamp("registration_end_at", { + precision: 6, + mode: "string", + }), + playerCap: integer("player_cap"), + autostart: boolean().default(false).notNull(), + startedAt: timestamp("started_at", { precision: 6, mode: "string" }), + lateRegistration: boolean("late_registration").default(true).notNull(), + teamlistsRequired: boolean("teamlists_required").default(true).notNull(), + openTeamSheets: boolean("open_team_sheets").default(true).notNull(), + endAt: timestamp("end_at", { precision: 6, mode: "string" }), + + limitlessId: bigint("limitless_id", { mode: "bigint" }), + published: boolean().default(false).notNull(), + + currentPhaseId: bigint("current_phase_id", { mode: "bigint" }), + }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (table): Record => { + return { + indexTournamentsOnCurrentPhaseId: index( + "index_tournaments_on_current_phase_id", + ).using("btree", table.currentPhaseId.asc().nullsLast()), + indexTournamentsOnFormatId: index("index_tournaments_on_format_id").using( + "btree", + table.formatId.asc().nullsLast(), + ), + indexTournamentsOnGameId: index("index_tournaments_on_game_id").using( + "btree", + table.gameId.asc().nullsLast(), + ), + indexTournamentsOnLimitlessId: uniqueIndex( + "index_tournaments_on_limitless_id", + ) + .using("btree", table.limitlessId.asc().nullsLast()) + .where(sql`(limitless_id IS NOT NULL)`), + indexTournamentsOnOrganizationId: index( + "index_tournaments_on_organization_id", + ).using("btree", table.organizationId.asc().nullsLast()), + fkRails8Ef7Ba6258: foreignKey({ + columns: [table.gameId], + foreignColumns: [games.id], + name: "fk_rails_8ef7ba6258", + }), + fkRails325Ccadea6: foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "fk_rails_325ccadea6", + }), + fkRails40Bc0Fb494: foreignKey({ + columns: [table.currentPhaseId], + foreignColumns: [phases.id], + name: "fk_rails_40bc0fb494", + }), + }; + }, +); + +export const pokemon = pgTable( + "pokemon", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + species: varchar(), + ability: varchar(), + teraType: varchar("tera_type"), + nature: varchar(), + item: varchar(), + move1: varchar(), + move2: varchar(), + move3: varchar(), + move4: varchar(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + nickname: varchar(), + + pokemonTeamId: bigint("pokemon_team_id", { mode: "bigint" }) + .default(0n) + .notNull(), + form: varchar(), + position: integer().default(0).notNull(), + gender: integer().default(2).notNull(), + shiny: boolean().default(false).notNull(), + evHp: integer("ev_hp"), + evAtk: integer("ev_atk"), + evDef: integer("ev_def"), + evSpa: integer("ev_spa"), + evSpd: integer("ev_spd"), + evSpe: integer("ev_spe"), + ivHp: integer("iv_hp"), + ivAtk: integer("iv_atk"), + ivDef: integer("iv_def"), + ivSpa: integer("iv_spa"), + ivSpd: integer("iv_spd"), + ivSpe: integer("iv_spe"), + }, + (table) => { + return { + indexPokemonOnPokemonTeamId: index( + "index_pokemon_on_pokemon_team_id", + ).using("btree", table.pokemonTeamId.asc().nullsLast()), + indexPokemonOnPokemonTeamIdAndPosition: uniqueIndex( + "index_pokemon_on_pokemon_team_id_and_position", + ).using( + "btree", + table.pokemonTeamId.asc().nullsLast(), + table.position.asc().nullsLast(), + ), + fkRails5B6022737B: foreignKey({ + columns: [table.pokemonTeamId], + foreignColumns: [pokemonTeams.id], + name: "fk_rails_5b6022737b", + }), + }; + }, +); + +export const pokemonTeams = pgTable( + "pokemon_teams", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + published: boolean().default(true).notNull(), + name: varchar(), + + formatId: bigint("format_id", { mode: "bigint" }).notNull(), + + gameId: bigint("game_id", { mode: "bigint" }).notNull(), + archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }), + pokepasteId: varchar("pokepaste_id"), + + profileId: bigint("profile_id", { mode: "bigint" }), + }, + (table) => { + return { + indexPokemonTeamsOnFormatId: index( + "index_pokemon_teams_on_format_id", + ).using("btree", table.formatId.asc().nullsLast()), + indexPokemonTeamsOnGameId: index("index_pokemon_teams_on_game_id").using( + "btree", + table.gameId.asc().nullsLast(), + ), + fkRails6E351688B8: foreignKey({ + columns: [table.formatId], + foreignColumns: [formats.id], + name: "fk_rails_6e351688b8", + }), + fkRailsE0513D6A9C: foreignKey({ + columns: [table.gameId], + foreignColumns: [games.id], + name: "fk_rails_e0513d6a9c", + }), + fkRails7Bf8C65391: foreignKey({ + columns: [table.profileId], + foreignColumns: [profiles.id], + name: "fk_rails_7bf8c65391", + }), + }; + }, +); + +export const rounds = pgTable( + "rounds", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + phaseId: bigint("phase_id", { mode: "bigint" }).notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + roundNumber: integer("round_number").default(1).notNull(), + startedAt: timestamp("started_at", { precision: 6, mode: "string" }), + endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), + }, + (table) => { + return { + indexRoundsOnPhaseId: index("index_rounds_on_phase_id").using( + "btree", + table.phaseId.asc().nullsLast(), + ), + indexRoundsOnPhaseIdAndRoundNumber: uniqueIndex( + "index_rounds_on_phase_id_and_round_number", + ).using( + "btree", + table.phaseId.asc().nullsLast(), + table.roundNumber.asc().nullsLast(), + ), + }; + }, +); + +export const tournamentFormats = pgTable( + "tournament_formats", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + tournamentId: bigint("tournament_id", { mode: "bigint" }).notNull(), + + formatId: bigint("format_id", { mode: "bigint" }).notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + }, + (table) => { + return { + indexTournamentFormatsOnFormatId: index( + "index_tournament_formats_on_format_id", + ).using("btree", table.formatId.asc().nullsLast()), + indexTournamentFormatsOnTournamentId: index( + "index_tournament_formats_on_tournament_id", + ).using("btree", table.tournamentId.asc().nullsLast()), + fkRails08C15D3C37: foreignKey({ + columns: [table.formatId], + foreignColumns: [formats.id], + name: "fk_rails_08c15d3c37", + }), + fkRailsC679052Dc0: foreignKey({ + columns: [table.tournamentId], + foreignColumns: [tournaments.id], + name: "fk_rails_c679052dc0", + }), + }; + }, +); + +export const matchGames = pgTable( + "match_games", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + matchId: bigint("match_id", { mode: "bigint" }).notNull(), + + winnerId: bigint("winner_id", { mode: "bigint" }), + + loserId: bigint("loser_id", { mode: "bigint" }), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + gameNumber: integer("game_number").default(1).notNull(), + endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), + startedAt: timestamp("started_at", { precision: 6, mode: "string" }), + + reporterProfileId: bigint("reporter_profile_id", { mode: "bigint" }), + }, + (table) => { + return { + indexMatchGamesOnLoserId: index("index_match_games_on_loser_id").using( + "btree", + table.loserId.asc().nullsLast(), + ), + indexMatchGamesOnMatchId: index("index_match_games_on_match_id").using( + "btree", + table.matchId.asc().nullsLast(), + ), + indexMatchGamesOnWinnerId: index("index_match_games_on_winner_id").using( + "btree", + table.winnerId.asc().nullsLast(), + ), + fkRails76Cefaebc0: foreignKey({ + columns: [table.matchId], + foreignColumns: [matches.id], + name: "fk_rails_76cefaebc0", + }), + fkRailsA2C90Fc36D: foreignKey({ + columns: [table.loserId], + foreignColumns: [players.id], + name: "fk_rails_a2c90fc36d", + }), + fkRailsBe3D6Ef1Eb: foreignKey({ + columns: [table.winnerId], + foreignColumns: [players.id], + name: "fk_rails_be3d6ef1eb", + }), + fkRails8599A8B8Df: foreignKey({ + columns: [table.reporterProfileId], + foreignColumns: [profiles.id], + name: "fk_rails_8599a8b8df", + }), + }; + }, +); + +export const clerkUsers = pgTable( + "clerk_users", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + clerkUserId: varchar("clerk_user_id").notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + + accountId: bigint("account_id", { mode: "bigint" }), + }, + (table) => { + return { + indexClerkUsersOnAccountId: index( + "index_clerk_users_on_account_id", + ).using("btree", table.accountId.asc().nullsLast()), + indexClerkUsersOnClerkUserId: uniqueIndex( + "index_clerk_users_on_clerk_user_id", + ).using("btree", table.clerkUserId.asc().nullsLast()), + fkRails982E94E92D: foreignKey({ + columns: [table.accountId], + foreignColumns: [accounts.id], + name: "fk_rails_982e94e92d", + }), + }; + }, +); + +export const accounts = pgTable( + "accounts", + { + email: varchar().default("").notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + unlockToken: varchar("unlock_token"), + firstName: varchar("first_name"), + lastName: varchar("last_name"), + pronouns: varchar().default("").notNull(), + jti: varchar().default("invalid").notNull(), + name: varchar(), + imageUrl: text("image_url"), + admin: boolean().default(false).notNull(), + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + defaultProfileId: bigint("default_profile_id", { mode: "bigint" }), + archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }), + country: varchar(), + timezone: varchar(), + }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (table): Record => { + return { + indexAccountsOnEmail: uniqueIndex("index_accounts_on_email").using( + "btree", + table.email.asc().nullsLast(), + ), + indexAccountsOnJti: uniqueIndex("index_accounts_on_jti").using( + "btree", + table.jti.asc().nullsLast(), + ), + indexAccountsOnUnlockToken: uniqueIndex( + "index_accounts_on_unlock_token", + ).using("btree", table.unlockToken.asc().nullsLast()), + fkRailsCee78B4B7D: foreignKey({ + columns: [table.defaultProfileId], + foreignColumns: [profiles.id], + name: "fk_rails_cee78b4b7d", + }), + }; + }, +); + +export const players = pgTable( + "players", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + tournamentId: bigint("tournament_id", { mode: "bigint" }).notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + teamSheetSubmitted: boolean("team_sheet_submitted") + .default(false) + .notNull(), + checkedInAt: timestamp("checked_in_at", { mode: "string" }), + inGameName: varchar("in_game_name").default("").notNull(), + pokemonTeamId: bigint("pokemon_team_id", { mode: "bigint" }), + dropped: boolean().default(false).notNull(), + disqualified: boolean().default(false).notNull(), + roundWins: integer("round_wins").default(0).notNull(), + roundLosses: integer("round_losses").default(0).notNull(), + gameWins: integer("game_wins").default(0).notNull(), + gameLosses: integer("game_losses").default(0).notNull(), + resistance: numeric({ precision: 5, scale: 2 }), + accountId: bigint("account_id", { mode: "bigint" }), + profileId: bigint("profile_id", { mode: "bigint" }).notNull(), + showCountryFlag: boolean("show_country_flag").default(true).notNull(), + }, + (table) => { + return { + indexPlayersOnAccountId: index("index_players_on_account_id").using( + "btree", + table.accountId.asc().nullsLast(), + ), + indexPlayersOnPokemonTeamId: index( + "index_players_on_pokemon_team_id", + ).using("btree", table.pokemonTeamId.asc().nullsLast()), + indexPlayersOnTournamentId: index("index_players_on_tournament_id").using( + "btree", + table.tournamentId.asc().nullsLast(), + ), + fkRailsAeec102047: foreignKey({ + columns: [table.pokemonTeamId], + foreignColumns: [pokemonTeams.id], + name: "fk_rails_aeec102047", + }), + fkRailsF96Ec8A72F: foreignKey({ + columns: [table.tournamentId], + foreignColumns: [tournaments.id], + name: "fk_rails_f96ec8a72f", + }), + fkRails224Cac07Ce: foreignKey({ + columns: [table.accountId], + foreignColumns: [accounts.id], + name: "fk_rails_224cac07ce", + }), + fkRailsC31Cf6Bf09: foreignKey({ + columns: [table.profileId], + foreignColumns: [profiles.id], + name: "fk_rails_c31cf6bf09", + }), + }; + }, +); + +export const games = pgTable( + "games", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + name: varchar(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + }, + (_table) => { + return { + indexGamesOnLowerName: uniqueIndex("index_games_on_lower_name").using( + "btree", + sql`lower((name)::text)`, + ), + }; + }, +); + +export const profiles = pgTable( + "profiles", + { + username: varchar().notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + imageUrl: varchar("image_url"), + slug: varchar(), + accountId: bigint("account_id", { mode: "bigint" }), + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }), + default: boolean().default(false).notNull(), + type: varchar().default("Profile").notNull(), + }, + (table) => { + return { + indexProfilesOnAccountId: index("index_profiles_on_account_id").using( + "btree", + table.accountId.asc().nullsLast(), + ), + indexProfilesOnSlug: uniqueIndex("index_profiles_on_slug").using( + "btree", + table.slug.asc().nullsLast(), + ), + indexProfilesOnUsername: uniqueIndex("index_profiles_on_username").using( + "btree", + table.username.asc().nullsLast(), + ), + fkRailsE424190865: foreignKey({ + columns: [table.accountId], + foreignColumns: [accounts.id], + name: "fk_rails_e424190865", + }), + }; + }, +); + +export const friendlyIdSlugs = pgTable( + "friendly_id_slugs", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + slug: varchar().notNull(), + sluggableId: integer("sluggable_id").notNull(), + sluggableType: varchar("sluggable_type", { length: 50 }), + scope: varchar(), + createdAt: timestamp("created_at", { precision: 6, mode: "string" }), + }, + (table) => { + return { + indexFriendlyIdSlugsOnSlugAndSluggableType: index( + "index_friendly_id_slugs_on_slug_and_sluggable_type", + ).using( + "btree", + table.slug.asc().nullsLast(), + table.sluggableType.asc().nullsLast(), + ), + indexFriendlyIdSlugsOnSlugAndSluggableTypeAndScope: uniqueIndex( + "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", + ).using( + "btree", + table.slug.asc().nullsLast(), + table.sluggableType.asc().nullsLast(), + table.scope.asc().nullsLast(), + ), + indexFriendlyIdSlugsOnSluggableTypeAndSluggableId: index( + "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id", + ).using( + "btree", + table.sluggableType.asc().nullsLast(), + table.sluggableId.asc().nullsLast(), + ), + }; + }, +); + +export const schemaMigrations = pgTable("schema_migrations", { + version: varchar().primaryKey().notNull(), +}); + +export const arInternalMetadata = pgTable("ar_internal_metadata", { + key: varchar().primaryKey().notNull(), + value: varchar(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), +}); + +export const organizationStaffMembers = pgTable( + "organization_staff_members", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + organizationId: bigint("organization_id", { mode: "bigint" }).notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + + accountId: bigint("account_id", { mode: "bigint" }), + }, + (table) => { + return { + indexOrganizationStaffMembersOnAccountId: index( + "index_organization_staff_members_on_account_id", + ).using("btree", table.accountId.asc().nullsLast()), + indexOrganizationStaffMembersOnOrganizationId: index( + "index_organization_staff_members_on_organization_id", + ).using("btree", table.organizationId.asc().nullsLast()), + fkRailsA177A0142C: foreignKey({ + columns: [table.organizationId], + foreignColumns: [organizations.id], + name: "fk_rails_a177a0142c", + }), + fkRails65Be078Ae6: foreignKey({ + columns: [table.accountId], + foreignColumns: [accounts.id], + name: "fk_rails_65be078ae6", + }), + }; + }, +); + +export const phasePlayers = pgTable( + "phase_players", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + playerId: bigint("player_id", { mode: "bigint" }).notNull(), + phaseType: varchar("phase_type").notNull(), + + phaseId: bigint("phase_id", { mode: "bigint" }).notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + }, + (table) => { + return { + indexPhasePlayersOnPlayerId: index( + "index_phase_players_on_player_id", + ).using("btree", table.playerId.asc().nullsLast()), + indexTournamentPhasePlayersOnPhase: index( + "index_tournament_phase_players_on_phase", + ).using( + "btree", + table.phaseType.asc().nullsLast(), + table.phaseId.asc().nullsLast(), + ), + fkRails71Fbe65D92: foreignKey({ + columns: [table.playerId], + foreignColumns: [players.id], + name: "fk_rails_71fbe65d92", + }), + }; + }, +); + +export const phases = pgTable( + "phases", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + + tournamentId: bigint("tournament_id", { mode: "bigint" }).notNull(), + numberOfRounds: integer("number_of_rounds"), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + type: varchar().notNull(), + name: varchar(), + bestOf: integer("best_of").default(3).notNull(), + startedAt: timestamp("started_at", { precision: 6, mode: "string" }), + endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), + order: integer().default(0).notNull(), + + currentRoundId: bigint("current_round_id", { mode: "bigint" }), + }, + (table) => { + return { + indexPhasesOnCurrentRoundId: index( + "index_phases_on_current_round_id", + ).using("btree", table.currentRoundId.asc().nullsLast()), + indexPhasesOnTournamentId: index("index_phases_on_tournament_id").using( + "btree", + table.tournamentId.asc().nullsLast(), + ), + indexPhasesOnType: index("index_phases_on_type").using( + "btree", + table.type.asc().nullsLast(), + ), + fkRails75E775589E: foreignKey({ + columns: [table.tournamentId], + foreignColumns: [tournaments.id], + name: "fk_rails_75e775589e", + }), + fkRails2909E41898: foreignKey({ + columns: [table.currentRoundId], + foreignColumns: [rounds.id], + name: "fk_rails_2909e41898", + }), + }; + }, +); + +export const organizations = pgTable( + "organizations", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + name: varchar(), + description: text(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + logoUrl: varchar("logo_url"), + partner: boolean().default(false).notNull(), + hidden: boolean().default(false).notNull(), + slug: varchar(), + + limitlessOrgId: bigint("limitless_org_id", { mode: "bigint" }), + + ownerId: bigint("owner_id", { mode: "bigint" }), + }, + (table) => { + return { + indexOrganizationsOnName: uniqueIndex( + "index_organizations_on_name", + ).using("btree", table.name.asc().nullsLast()), + indexOrganizationsOnOwnerId: index( + "index_organizations_on_owner_id", + ).using("btree", table.ownerId.asc().nullsLast()), + indexOrganizationsOnSlug: uniqueIndex( + "index_organizations_on_slug", + ).using("btree", table.slug.asc().nullsLast()), + fkRailsAb574863F6: foreignKey({ + columns: [table.ownerId], + foreignColumns: [accounts.id], + name: "fk_rails_ab574863f6", + }), + }; + }, +); + +export const matches = pgTable( + "matches", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + roundId: bigint("round_id", { mode: "bigint" }).notNull(), + tableNumber: integer("table_number"), + playerOneId: bigint("player_one_id", { mode: "bigint" }), + playerTwoId: bigint("player_two_id", { mode: "bigint" }), + winnerId: bigint("winner_id", { mode: "bigint" }), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + playerOneCheckIn: timestamp("player_one_check_in", { + precision: 6, + mode: "string", + }), + playerTwoCheckIn: timestamp("player_two_check_in", { + precision: 6, + mode: "string", + }), + loserId: bigint("loser_id", { mode: "bigint" }), + endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), + tournamentId: bigint("tournament_id", { mode: "bigint" }), + phaseId: bigint("phase_id", { mode: "bigint" }), + bye: boolean().default(false).notNull(), + resetById: bigint("reset_by_id", { mode: "bigint" }), + }, + (table) => { + return { + indexMatchesOnLoserId: index("index_matches_on_loser_id").using( + "btree", + table.loserId.asc().nullsLast(), + ), + indexMatchesOnPhaseId: index("index_matches_on_phase_id").using( + "btree", + table.phaseId.asc().nullsLast(), + ), + indexMatchesOnPlayerOneId: index("index_matches_on_player_one_id").using( + "btree", + table.playerOneId.asc().nullsLast(), + ), + indexMatchesOnPlayerTwoId: index("index_matches_on_player_two_id").using( + "btree", + table.playerTwoId.asc().nullsLast(), + ), + indexMatchesOnRoundAndPlayersUnique: uniqueIndex( + "index_matches_on_round_and_players_unique", + ).using( + "btree", + table.roundId.asc().nullsLast(), + table.playerOneId.asc().nullsLast(), + table.playerTwoId.asc().nullsLast(), + ), + indexMatchesOnTournamentId: index("index_matches_on_tournament_id").using( + "btree", + table.tournamentId.asc().nullsLast(), + ), + indexMatchesOnWinnerId: index("index_matches_on_winner_id").using( + "btree", + table.winnerId.asc().nullsLast(), + ), + fkRails973A5646Ac: foreignKey({ + columns: [table.loserId], + foreignColumns: [players.id], + name: "fk_rails_973a5646ac", + }), + fkRailsBfcd6A3C9F: foreignKey({ + columns: [table.playerOneId], + foreignColumns: [players.id], + name: "fk_rails_bfcd6a3c9f", + }), + fkRailsB58C6C3513: foreignKey({ + columns: [table.playerTwoId], + foreignColumns: [players.id], + name: "fk_rails_b58c6c3513", + }), + fkRails9D0Deeb219: foreignKey({ + columns: [table.winnerId], + foreignColumns: [players.id], + name: "fk_rails_9d0deeb219", + }), + fkRailsE7C0250650: foreignKey({ + columns: [table.roundId], + foreignColumns: [rounds.id], + name: "fk_rails_e7c0250650", + }), + fkRails700Eaa2935: foreignKey({ + columns: [table.tournamentId], + foreignColumns: [tournaments.id], + name: "fk_rails_700eaa2935", + }), + fkRails36Efc9F0F5: foreignKey({ + columns: [table.phaseId], + foreignColumns: [phases.id], + name: "fk_rails_36efc9f0f5", + }), + fkRailsAf814604Cc: foreignKey({ + columns: [table.resetById], + foreignColumns: [accounts.id], + name: "fk_rails_af814604cc", + }), + }; + }, +); + +export const chatMessages = pgTable( + "chat_messages", + { + matchId: bigint("match_id", { mode: "bigint" }).notNull(), + content: text(), + messageType: varchar("message_type"), + sentAt: timestamp("sent_at", { precision: 6, mode: "string" }), + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + accountId: bigint("account_id", { mode: "bigint" }), + profileId: bigint("profile_id", { mode: "bigint" }).notNull(), + }, + (table) => { + return { + indexChatMessagesOnAccountId: index( + "index_chat_messages_on_account_id", + ).using("btree", table.accountId.asc().nullsLast()), + indexChatMessagesOnMatchId: index( + "index_chat_messages_on_match_id", + ).using("btree", table.matchId.asc().nullsLast()), + fkRailsF9Ae4172Ee: foreignKey({ + columns: [table.matchId], + foreignColumns: [matches.id], + name: "fk_rails_f9ae4172ee", + }), + fkRails918Ef7Acc4: foreignKey({ + columns: [table.accountId], + foreignColumns: [accounts.id], + name: "fk_rails_918ef7acc4", + }), + fkRailsF531Ed39E3: foreignKey({ + columns: [table.profileId], + foreignColumns: [profiles.id], + name: "fk_rails_f531ed39e3", + }), + }; + }, +); + +export const rk9Tournaments = pgTable( + "rk9_tournaments", + { + id: bigserial({ mode: "bigint" }).primaryKey().notNull(), + rk9Id: varchar("rk9_id").notNull(), + name: varchar().notNull(), + startDate: date("start_date").notNull(), + endDate: date("end_date").notNull(), + createdAt: timestamp("created_at", { + precision: 6, + mode: "string", + }).notNull(), + updatedAt: timestamp("updated_at", { + precision: 6, + mode: "string", + }).notNull(), + }, + (table) => { + return { + indexRk9TournamentsOnEndDate: index( + "index_rk9_tournaments_on_end_date", + ).using("btree", table.endDate.asc().nullsLast()), + indexRk9TournamentsOnName: uniqueIndex( + "index_rk9_tournaments_on_name", + ).using("btree", table.name.asc().nullsLast()), + indexRk9TournamentsOnRk9Id: uniqueIndex( + "index_rk9_tournaments_on_rk9_id", + ).using("btree", table.rk9Id.asc().nullsLast()), + indexRk9TournamentsOnStartAndEndDate: index( + "index_rk9_tournaments_on_start_and_end_date", + ).using( + "btree", + table.startDate.asc().nullsLast(), + table.endDate.asc().nullsLast(), + ), + indexRk9TournamentsOnStartDate: index( + "index_rk9_tournaments_on_start_date", + ).using("btree", table.startDate.asc().nullsLast()), + }; + }, +); diff --git a/packages/db/package.json b/packages/db/package.json index 889f0cd9..5680c933 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -14,8 +14,12 @@ "default": "./src/client.ts" }, "./schema": { - "types": "./dist/schema.d.ts", + "types": "./dist/src/schema.d.ts", "default": "./src/schema.ts" + }, + "./relations": { + "types": "./dist/relation.d.ts", + "default": "./drizzle/relation.ts" } }, "scripts": { diff --git a/packages/db/src/client.ts b/packages/db/src/client.ts index 67bf04dd..11d8d26e 100644 --- a/packages/db/src/client.ts +++ b/packages/db/src/client.ts @@ -1,7 +1,7 @@ import { neon } from "@neondatabase/serverless"; import { drizzle } from "drizzle-orm/neon-http"; -import * as schema from "./schemas"; +import * as schema from "../drizzle/schema"; if (!process.env.DATABASE_URL) { throw new Error("Missing DATABASE_URL"); diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index 292f6057..7879452c 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -1 +1,61 @@ -export * from "./schemas"; +import type * as schema from "../drizzle/schema"; + +export * from "../drizzle/schema"; +export type Account = typeof schema.accounts.$inferSelect; +export type AccountInsert = typeof schema.accounts.$inferInsert; + +export type ChatMessage = typeof schema.chatMessages.$inferInsert; +export type ChatMessageInsert = typeof schema.chatMessages.$inferInsert; + +export type ClerkUser = typeof schema.clerkUsers.$inferSelect; +export type ClerkUserInsert = typeof schema.clerkUsers.$inferInsert; + +export type Format = typeof schema.formats.$inferSelect; +export type FormatInsert = typeof schema.formats.$inferInsert; +export type Game = typeof schema.games.$inferSelect; +export type GameInsert = typeof schema.games.$inferInsert; + +export type MatchGame = typeof schema.matchGames.$inferSelect; +export type MatchGameInsert = typeof schema.matchGames.$inferInsert; + +export type Match = typeof schema.matches.$inferSelect; +export type MatchInsert = typeof schema.matches.$inferInsert; + +export type OrganizationStaffMember = + typeof schema.organizationStaffMembers.$inferSelect; +export type OrganizationStaffMemberInsert = + typeof schema.organizationStaffMembers.$inferInsert; + +export type Organization = typeof schema.organizations.$inferSelect; +export type OrganizationInsert = typeof schema.organizations.$inferInsert; + +export type PhasePlayer = typeof schema.phasePlayers.$inferSelect; +export type PhasePlayerInsert = typeof schema.phasePlayers.$inferInsert; + +export type Phase = typeof schema.phases.$inferSelect; +export type PhaseInsert = typeof schema.phases.$inferInsert; + +export type Player = typeof schema.players.$inferSelect; +export type PlayerInsert = typeof schema.players.$inferInsert; + +export type PokemonTeam = typeof schema.pokemonTeams.$inferSelect; +export type PokemonTeamInsert = typeof schema.pokemonTeams.$inferInsert; + +export type Pokemon = typeof schema.pokemon.$inferSelect; +export type PokemonInsert = typeof schema.pokemon.$inferInsert; + +export type Profile = typeof schema.profiles.$inferSelect; +export type ProfileInsert = typeof schema.profiles.$inferInsert; + +export type Round = typeof schema.rounds.$inferSelect; +export type RoundInsert = typeof schema.rounds.$inferInsert; + +export type TournamentFormat = typeof schema.tournamentFormats.$inferSelect; +export type TournamentFormatInsert = + typeof schema.tournamentFormats.$inferInsert; + +export type Tournament = typeof schema.tournaments.$inferSelect; +export type TournamentInsert = typeof schema.tournaments.$inferInsert; + +export type Rk9Tournament = typeof schema.rk9Tournaments.$inferSelect; +export type Rk9TournamentInsert = typeof schema.rk9Tournaments.$inferInsert; diff --git a/packages/db/src/schemas/accounts.ts b/packages/db/src/schemas/accounts.ts deleted file mode 100644 index cd8d14cd..00000000 --- a/packages/db/src/schemas/accounts.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { - bigint, - bigserial, - boolean, - foreignKey, - pgTable, - text, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -import { profiles } from "./profiles"; - -export const accounts = pgTable( - "accounts", - { - email: varchar().default("").notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - unlockToken: varchar("unlock_token"), - firstName: varchar("first_name"), - lastName: varchar("last_name"), - pronouns: varchar().default("").notNull(), - jti: varchar().default("invalid").notNull(), - name: varchar(), - imageUrl: text("image_url"), - admin: boolean().default(false).notNull(), - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - defaultProfileId: bigint("default_profile_id", { mode: "bigint" }), - archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }), - country: varchar(), - timezone: varchar(), - }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (table): Record => { - return { - indexAccountsOnEmail: uniqueIndex("index_accounts_on_email").using( - "btree", - table.email.asc().nullsLast(), - ), - indexAccountsOnJti: uniqueIndex("index_accounts_on_jti").using( - "btree", - table.jti.asc().nullsLast(), - ), - indexAccountsOnUnlockToken: uniqueIndex( - "index_accounts_on_unlock_token", - ).using("btree", table.unlockToken.asc().nullsLast()), - fkRailsCee78B4B7D: foreignKey({ - columns: [table.defaultProfileId], - foreignColumns: [profiles.id], - name: "fk_rails_cee78b4b7d", - }), - }; - }, -); - -export type Account = typeof accounts.$inferSelect; -export type AccountInsert = typeof accounts.$inferInsert; diff --git a/packages/db/src/schemas/chat-messages.ts b/packages/db/src/schemas/chat-messages.ts deleted file mode 100644 index 624b9f3d..00000000 --- a/packages/db/src/schemas/chat-messages.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - pgTable, - text, - timestamp, - varchar, -} from "drizzle-orm/pg-core"; - -import { accounts } from "./accounts"; -import { matches } from "./matches"; -import { profiles } from "./profiles"; - -export const chatMessages = pgTable( - "chat_messages", - { - matchId: bigint("match_id", { mode: "bigint" }).notNull(), - content: text(), - messageType: varchar("message_type"), - sentAt: timestamp("sent_at", { precision: 6, mode: "string" }), - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - accountId: bigint("account_id", { mode: "bigint" }), - profileId: bigint("profile_id", { mode: "bigint" }).notNull(), - }, - (table) => { - return { - indexChatMessagesOnAccountId: index( - "index_chat_messages_on_account_id", - ).using("btree", table.accountId.asc().nullsLast()), - indexChatMessagesOnMatchId: index( - "index_chat_messages_on_match_id", - ).using("btree", table.matchId.asc().nullsLast()), - fkRailsF9Ae4172Ee: foreignKey({ - columns: [table.matchId], - foreignColumns: [matches.id], - name: "fk_rails_f9ae4172ee", - }), - fkRails918Ef7Acc4: foreignKey({ - columns: [table.accountId], - foreignColumns: [accounts.id], - name: "fk_rails_918ef7acc4", - }), - fkRailsF531Ed39E3: foreignKey({ - columns: [table.profileId], - foreignColumns: [profiles.id], - name: "fk_rails_f531ed39e3", - }), - }; - }, -); - -export type ChatMessage = typeof chatMessages.$inferInsert; -export type ChatMessageInsert = typeof chatMessages.$inferInsert; diff --git a/packages/db/src/schemas/clerk-users.ts b/packages/db/src/schemas/clerk-users.ts deleted file mode 100644 index 41d0bec6..00000000 --- a/packages/db/src/schemas/clerk-users.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - pgTable, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -import { accounts } from "./accounts"; - -export const clerkUsers = pgTable( - "clerk_users", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - clerkUserId: varchar("clerk_user_id").notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - accountId: bigint("account_id", { mode: "bigint" }), - }, - (table) => { - return { - indexClerkUsersOnAccountId: index( - "index_clerk_users_on_account_id", - ).using("btree", table.accountId.asc().nullsLast()), - indexClerkUsersOnClerkUserId: uniqueIndex( - "index_clerk_users_on_clerk_user_id", - ).using("btree", table.clerkUserId.asc().nullsLast()), - fkRails982E94E92D: foreignKey({ - columns: [table.accountId], - foreignColumns: [accounts.id], - name: "fk_rails_982e94e92d", - }), - }; - }, -); - -export type ClerkUser = typeof clerkUsers.$inferSelect; -export type ClerkUserInsert = typeof clerkUsers.$inferInsert; diff --git a/packages/db/src/schemas/formats.ts b/packages/db/src/schemas/formats.ts deleted file mode 100644 index 7dee7f54..00000000 --- a/packages/db/src/schemas/formats.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - pgTable, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -import { games } from "./games"; - -export const formats = pgTable( - "formats", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - name: varchar(), - gameId: bigint("game_id", { mode: "bigint" }), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - }, - (table) => { - return { - indexFormatsOnGameId: index("index_formats_on_game_id").using( - "btree", - table.gameId.asc().nullsLast(), - ), - indexFormatsOnNameAndGameId: uniqueIndex( - "index_formats_on_name_and_game_id", - ).using( - "btree", - table.name.asc().nullsLast(), - table.gameId.asc().nullsLast(), - ), - fkRailsA0E0605606: foreignKey({ - columns: [table.gameId], - foreignColumns: [games.id], - name: "fk_rails_a0e0605606", - }), - }; - }, -); - -export type Format = typeof formats.$inferSelect; -export type FormatInsert = typeof formats.$inferInsert; diff --git a/packages/db/src/schemas/friendly-id-slugs.ts b/packages/db/src/schemas/friendly-id-slugs.ts deleted file mode 100644 index 25ca4e91..00000000 --- a/packages/db/src/schemas/friendly-id-slugs.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { - bigserial, - index, - integer, - pgTable, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -export const friendlyIdSlugs = pgTable( - "friendly_id_slugs", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - slug: varchar().notNull(), - sluggableId: integer("sluggable_id").notNull(), - sluggableType: varchar("sluggable_type", { length: 50 }), - scope: varchar(), - createdAt: timestamp("created_at", { precision: 6, mode: "string" }), - }, - (table) => { - return { - indexFriendlyIdSlugsOnSlugAndSluggableType: index( - "index_friendly_id_slugs_on_slug_and_sluggable_type", - ).using( - "btree", - table.slug.asc().nullsLast(), - table.sluggableType.asc().nullsLast(), - ), - indexFriendlyIdSlugsOnSlugAndSluggableTypeAndScope: uniqueIndex( - "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", - ).using( - "btree", - table.slug.asc().nullsLast(), - table.sluggableType.asc().nullsLast(), - table.scope.asc().nullsLast(), - ), - indexFriendlyIdSlugsOnSluggableTypeAndSluggableId: index( - "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id", - ).using( - "btree", - table.sluggableType.asc().nullsLast(), - table.sluggableId.asc().nullsLast(), - ), - }; - }, -); diff --git a/packages/db/src/schemas/games.ts b/packages/db/src/schemas/games.ts deleted file mode 100644 index 08e232ee..00000000 --- a/packages/db/src/schemas/games.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { sql } from "drizzle-orm"; -import { - bigserial, - pgTable, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -export const games = pgTable( - "games", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - name: varchar(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - }, - (_table) => { - return { - indexGamesOnLowerName: uniqueIndex("index_games_on_lower_name").using( - "btree", - sql`lower((name)::text)`, - ), - }; - }, -); - -export type Game = typeof games.$inferSelect; -export type GameInsert = typeof games.$inferInsert; diff --git a/packages/db/src/schemas/index.ts b/packages/db/src/schemas/index.ts deleted file mode 100644 index 03accf79..00000000 --- a/packages/db/src/schemas/index.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { pgTable, timestamp, varchar } from "drizzle-orm/pg-core"; - -export const schemaMigrations = pgTable("schema_migrations", { - version: varchar().primaryKey().notNull(), -}); - -export const arInternalMetadata = pgTable("ar_internal_metadata", { - key: varchar().primaryKey().notNull(), - value: varchar(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), -}); - -export * from "./accounts"; -export * from "./chat-messages"; -export * from "./clerk-users"; -export * from "./formats"; -export * from "./friendly-id-slugs"; -export * from "./games"; -export * from "./matches"; -export * from "./match-games"; -export * from "./organizations"; -export * from "./organization-staff-members"; -export * from "./players"; -export * from "./phase-players"; -export * from "./phases"; -export * from "./pokemon"; -export * from "./pokemon-teams"; -export * from "./rounds"; -export * from "./profiles"; -export * from "./tournaments"; -export * from "./tournaments-formats"; diff --git a/packages/db/src/schemas/match-games.ts b/packages/db/src/schemas/match-games.ts deleted file mode 100644 index 4dd082f5..00000000 --- a/packages/db/src/schemas/match-games.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - integer, - pgTable, - timestamp, -} from "drizzle-orm/pg-core"; - -import { matches } from "./matches"; -import { players } from "./players"; -import { profiles } from "./profiles"; - -export const matchGames = pgTable( - "match_games", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - matchId: bigint("match_id", { mode: "bigint" }).notNull(), - winnerId: bigint("winner_id", { mode: "bigint" }), - loserId: bigint("loser_id", { mode: "bigint" }), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - gameNumber: integer("game_number").default(1).notNull(), - endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), - startedAt: timestamp("started_at", { precision: 6, mode: "string" }), - reporterProfileId: bigint("reporter_profile_id", { mode: "bigint" }), - }, - (table) => { - return { - indexMatchGamesOnLoserId: index("index_match_games_on_loser_id").using( - "btree", - table.loserId.asc().nullsLast(), - ), - indexMatchGamesOnMatchId: index("index_match_games_on_match_id").using( - "btree", - table.matchId.asc().nullsLast(), - ), - indexMatchGamesOnWinnerId: index("index_match_games_on_winner_id").using( - "btree", - table.winnerId.asc().nullsLast(), - ), - fkRails76Cefaebc0: foreignKey({ - columns: [table.matchId], - foreignColumns: [matches.id], - name: "fk_rails_76cefaebc0", - }), - fkRailsA2C90Fc36D: foreignKey({ - columns: [table.loserId], - foreignColumns: [players.id], - name: "fk_rails_a2c90fc36d", - }), - fkRailsBe3D6Ef1Eb: foreignKey({ - columns: [table.winnerId], - foreignColumns: [players.id], - name: "fk_rails_be3d6ef1eb", - }), - fkRails8599A8B8Df: foreignKey({ - columns: [table.reporterProfileId], - foreignColumns: [profiles.id], - name: "fk_rails_8599a8b8df", - }), - }; - }, -); - -export type MatchGame = typeof matchGames.$inferSelect; -export type MatchGameInsert = typeof matchGames.$inferInsert; diff --git a/packages/db/src/schemas/matches.ts b/packages/db/src/schemas/matches.ts deleted file mode 100644 index 0ad9255d..00000000 --- a/packages/db/src/schemas/matches.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { - bigint, - bigserial, - boolean, - foreignKey, - index, - integer, - pgTable, - timestamp, - uniqueIndex, -} from "drizzle-orm/pg-core"; - -import { accounts } from "./accounts"; -import { phases } from "./phases"; -import { players } from "./players"; -import { rounds } from "./rounds"; -import { tournaments } from "./tournaments"; - -export const matches = pgTable( - "matches", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - roundId: bigint("round_id", { mode: "bigint" }).notNull(), - tableNumber: integer("table_number"), - playerOneId: bigint("player_one_id", { mode: "bigint" }), - playerTwoId: bigint("player_two_id", { mode: "bigint" }), - winnerId: bigint("winner_id", { mode: "bigint" }), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - playerOneCheckIn: timestamp("player_one_check_in", { - precision: 6, - mode: "string", - }), - playerTwoCheckIn: timestamp("player_two_check_in", { - precision: 6, - mode: "string", - }), - loserId: bigint("loser_id", { mode: "bigint" }), - endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), - tournamentId: bigint("tournament_id", { mode: "bigint" }), - phaseId: bigint("phase_id", { mode: "bigint" }), - bye: boolean().default(false).notNull(), - resetById: bigint("reset_by_id", { mode: "bigint" }), - }, - (table) => { - return { - indexMatchesOnLoserId: index("index_matches_on_loser_id").using( - "btree", - table.loserId.asc().nullsLast(), - ), - indexMatchesOnPhaseId: index("index_matches_on_phase_id").using( - "btree", - table.phaseId.asc().nullsLast(), - ), - indexMatchesOnPlayerOneId: index("index_matches_on_player_one_id").using( - "btree", - table.playerOneId.asc().nullsLast(), - ), - indexMatchesOnPlayerTwoId: index("index_matches_on_player_two_id").using( - "btree", - table.playerTwoId.asc().nullsLast(), - ), - indexMatchesOnRoundAndPlayersUnique: uniqueIndex( - "index_matches_on_round_and_players_unique", - ).using( - "btree", - table.roundId.asc().nullsLast(), - table.playerOneId.asc().nullsLast(), - table.playerTwoId.asc().nullsLast(), - ), - indexMatchesOnTournamentId: index("index_matches_on_tournament_id").using( - "btree", - table.tournamentId.asc().nullsLast(), - ), - indexMatchesOnWinnerId: index("index_matches_on_winner_id").using( - "btree", - table.winnerId.asc().nullsLast(), - ), - fkRails973A5646Ac: foreignKey({ - columns: [table.loserId], - foreignColumns: [players.id], - name: "fk_rails_973a5646ac", - }), - fkRailsBfcd6A3C9F: foreignKey({ - columns: [table.playerOneId], - foreignColumns: [players.id], - name: "fk_rails_bfcd6a3c9f", - }), - fkRailsB58C6C3513: foreignKey({ - columns: [table.playerTwoId], - foreignColumns: [players.id], - name: "fk_rails_b58c6c3513", - }), - fkRails9D0Deeb219: foreignKey({ - columns: [table.winnerId], - foreignColumns: [players.id], - name: "fk_rails_9d0deeb219", - }), - fkRailsE7C0250650: foreignKey({ - columns: [table.roundId], - foreignColumns: [rounds.id], - name: "fk_rails_e7c0250650", - }), - fkRails700Eaa2935: foreignKey({ - columns: [table.tournamentId], - foreignColumns: [tournaments.id], - name: "fk_rails_700eaa2935", - }), - fkRails36Efc9F0F5: foreignKey({ - columns: [table.phaseId], - foreignColumns: [phases.id], - name: "fk_rails_36efc9f0f5", - }), - fkRailsAf814604Cc: foreignKey({ - columns: [table.resetById], - foreignColumns: [accounts.id], - name: "fk_rails_af814604cc", - }), - }; - }, -); - -export type Match = typeof matches.$inferSelect; -export type MatchInsert = typeof matches.$inferInsert; diff --git a/packages/db/src/schemas/organization-staff-members.ts b/packages/db/src/schemas/organization-staff-members.ts deleted file mode 100644 index b976bcae..00000000 --- a/packages/db/src/schemas/organization-staff-members.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - pgTable, - timestamp, -} from "drizzle-orm/pg-core"; - -import { accounts } from "./accounts"; -import { organizations } from "./organizations"; - -export const organizationStaffMembers = pgTable( - "organization_staff_members", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - organizationId: bigint("organization_id", { mode: "bigint" }).notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - accountId: bigint("account_id", { mode: "bigint" }), - }, - (table) => { - return { - indexOrganizationStaffMembersOnAccountId: index( - "index_organization_staff_members_on_account_id", - ).using("btree", table.accountId.asc().nullsLast()), - indexOrganizationStaffMembersOnOrganizationId: index( - "index_organization_staff_members_on_organization_id", - ).using("btree", table.organizationId.asc().nullsLast()), - fkRailsA177A0142C: foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: "fk_rails_a177a0142c", - }), - fkRails65Be078Ae6: foreignKey({ - columns: [table.accountId], - foreignColumns: [accounts.id], - name: "fk_rails_65be078ae6", - }), - }; - }, -); - -export type OrganizationStaffMember = - typeof organizationStaffMembers.$inferSelect; -export type OrganizationStaffMemberInsert = - typeof organizationStaffMembers.$inferInsert; diff --git a/packages/db/src/schemas/organizations.ts b/packages/db/src/schemas/organizations.ts deleted file mode 100644 index c5db6e6f..00000000 --- a/packages/db/src/schemas/organizations.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { - bigint, - bigserial, - boolean, - foreignKey, - index, - pgTable, - text, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -import { accounts } from "./accounts"; - -export const organizations = pgTable( - "organizations", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - name: varchar(), - description: text(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - logoUrl: varchar("logo_url"), - partner: boolean().default(false).notNull(), - hidden: boolean().default(false).notNull(), - slug: varchar(), - limitlessOrgId: bigint("limitless_org_id", { mode: "bigint" }), - ownerId: bigint("owner_id", { mode: "bigint" }), - }, - (table) => { - return { - indexOrganizationsOnName: uniqueIndex( - "index_organizations_on_name", - ).using("btree", table.name.asc().nullsLast()), - indexOrganizationsOnOwnerId: index( - "index_organizations_on_owner_id", - ).using("btree", table.ownerId.asc().nullsLast()), - indexOrganizationsOnSlug: uniqueIndex( - "index_organizations_on_slug", - ).using("btree", table.slug.asc().nullsLast()), - fkRailsAb574863F6: foreignKey({ - columns: [table.ownerId], - foreignColumns: [accounts.id], - name: "fk_rails_ab574863f6", - }), - }; - }, -); - -export type Organization = typeof organizations.$inferSelect; - -export type OrganizationInsert = typeof organizations.$inferInsert; diff --git a/packages/db/src/schemas/phase-players.ts b/packages/db/src/schemas/phase-players.ts deleted file mode 100644 index 43e08b97..00000000 --- a/packages/db/src/schemas/phase-players.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - pgTable, - timestamp, - varchar, -} from "drizzle-orm/pg-core"; - -import { players } from "./players"; - -export const phasePlayers = pgTable( - "phase_players", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - playerId: bigint("player_id", { mode: "bigint" }).notNull(), - phaseType: varchar("phase_type").notNull(), - phaseId: bigint("phase_id", { mode: "bigint" }).notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - }, - (table) => { - return { - indexPhasePlayersOnPlayerId: index( - "index_phase_players_on_player_id", - ).using("btree", table.playerId.asc().nullsLast()), - indexTournamentPhasePlayersOnPhase: index( - "index_tournament_phase_players_on_phase", - ).using( - "btree", - table.phaseType.asc().nullsLast(), - table.phaseId.asc().nullsLast(), - ), - fkRails71Fbe65D92: foreignKey({ - columns: [table.playerId], - foreignColumns: [players.id], - name: "fk_rails_71fbe65d92", - }), - }; - }, -); - -export type PhasePlayer = typeof phasePlayers.$inferSelect; -export type PhasePlayerInsert = typeof phasePlayers.$inferInsert; diff --git a/packages/db/src/schemas/phases.ts b/packages/db/src/schemas/phases.ts deleted file mode 100644 index 722f1fda..00000000 --- a/packages/db/src/schemas/phases.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - integer, - pgTable, - timestamp, - varchar, -} from "drizzle-orm/pg-core"; - -import { rounds } from "./rounds"; -import { tournaments } from "./tournaments"; - -export const phases = pgTable( - "phases", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - // You can use { mode: "bigint" } if numbers are exceeding js number limitations - tournamentId: bigint("tournament_id", { mode: "number" }).notNull(), - numberOfRounds: integer("number_of_rounds"), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - type: varchar().notNull(), - name: varchar(), - bestOf: integer("best_of").default(3).notNull(), - startedAt: timestamp("started_at", { precision: 6, mode: "string" }), - endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), - order: integer().default(0).notNull(), - currentRoundId: bigint("current_round_id", { mode: "bigint" }), - }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (table): Record => { - return { - indexPhasesOnCurrentRoundId: index( - "index_phases_on_current_round_id", - ).using("btree", table.currentRoundId.asc().nullsLast()), - indexPhasesOnTournamentId: index("index_phases_on_tournament_id").using( - "btree", - table.tournamentId.asc().nullsLast(), - ), - indexPhasesOnType: index("index_phases_on_type").using( - "btree", - table.type.asc().nullsLast(), - ), - fkRails75E775589E: foreignKey({ - columns: [table.tournamentId], - foreignColumns: [tournaments.id], - name: "fk_rails_75e775589e", - }), - fkRails2909E41898: foreignKey({ - columns: [table.currentRoundId], - foreignColumns: [rounds.id], - name: "fk_rails_2909e41898", - }), - }; - }, -); - -export type Phase = typeof phases.$inferSelect; -export type PhaseInsert = typeof phases.$inferInsert; diff --git a/packages/db/src/schemas/players.ts b/packages/db/src/schemas/players.ts deleted file mode 100644 index d27bad6d..00000000 --- a/packages/db/src/schemas/players.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { - bigint, - bigserial, - boolean, - foreignKey, - index, - integer, - numeric, - pgTable, - timestamp, - varchar, -} from "drizzle-orm/pg-core"; - -import { accounts } from "./accounts"; -import { pokemonTeams } from "./pokemon-teams"; -import { profiles } from "./profiles"; -import { tournaments } from "./tournaments"; - -export const players = pgTable( - "players", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - tournamentId: bigint("tournament_id", { mode: "bigint" }).notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - teamSheetSubmitted: boolean("team_sheet_submitted") - .default(false) - .notNull(), - checkedInAt: timestamp("checked_in_at", { mode: "string" }), - inGameName: varchar("in_game_name").default("").notNull(), - pokemonTeamId: bigint("pokemon_team_id", { mode: "bigint" }), - dropped: boolean().default(false).notNull(), - disqualified: boolean().default(false).notNull(), - roundWins: integer("round_wins").default(0).notNull(), - roundLosses: integer("round_losses").default(0).notNull(), - gameWins: integer("game_wins").default(0).notNull(), - gameLosses: integer("game_losses").default(0).notNull(), - resistance: numeric({ precision: 5, scale: 2 }), - accountId: bigint("account_id", { mode: "bigint" }), - profileId: bigint("profile_id", { mode: "bigint" }).notNull(), - showCountryFlag: boolean("show_country_flag").default(true).notNull(), - }, - (table) => { - return { - indexPlayersOnAccountId: index("index_players_on_account_id").using( - "btree", - table.accountId.asc().nullsLast(), - ), - indexPlayersOnPokemonTeamId: index( - "index_players_on_pokemon_team_id", - ).using("btree", table.pokemonTeamId.asc().nullsLast()), - indexPlayersOnTournamentId: index("index_players_on_tournament_id").using( - "btree", - table.tournamentId.asc().nullsLast(), - ), - fkRailsAeec102047: foreignKey({ - columns: [table.pokemonTeamId], - foreignColumns: [pokemonTeams.id], - name: "fk_rails_aeec102047", - }), - fkRailsF96Ec8A72F: foreignKey({ - columns: [table.tournamentId], - foreignColumns: [tournaments.id], - name: "fk_rails_f96ec8a72f", - }), - fkRails224Cac07Ce: foreignKey({ - columns: [table.accountId], - foreignColumns: [accounts.id], - name: "fk_rails_224cac07ce", - }), - fkRailsC31Cf6Bf09: foreignKey({ - columns: [table.profileId], - foreignColumns: [profiles.id], - name: "fk_rails_c31cf6bf09", - }), - }; - }, -); - -export type Player = typeof players.$inferSelect; -export type PlayerInsert = typeof players.$inferInsert; diff --git a/packages/db/src/schemas/pokemon-teams.ts b/packages/db/src/schemas/pokemon-teams.ts deleted file mode 100644 index 90491ddb..00000000 --- a/packages/db/src/schemas/pokemon-teams.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { - bigint, - bigserial, - boolean, - foreignKey, - index, - pgTable, - timestamp, - varchar, -} from "drizzle-orm/pg-core"; - -import { formats } from "./formats"; -import { games } from "./games"; -import { profiles } from "./profiles"; - -export const pokemonTeams = pgTable( - "pokemon_teams", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - published: boolean().default(true).notNull(), - name: varchar(), - formatId: bigint("format_id", { mode: "bigint" }).notNull(), - gameId: bigint("game_id", { mode: "bigint" }).notNull(), - archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }), - pokepasteId: varchar("pokepaste_id"), - profileId: bigint("profile_id", { mode: "bigint" }), - }, - (table) => { - return { - indexPokemonTeamsOnFormatId: index( - "index_pokemon_teams_on_format_id", - ).using("btree", table.formatId.asc().nullsLast()), - indexPokemonTeamsOnGameId: index("index_pokemon_teams_on_game_id").using( - "btree", - table.gameId.asc().nullsLast(), - ), - fkRails6E351688B8: foreignKey({ - columns: [table.formatId], - foreignColumns: [formats.id], - name: "fk_rails_6e351688b8", - }), - fkRailsE0513D6A9C: foreignKey({ - columns: [table.gameId], - foreignColumns: [games.id], - name: "fk_rails_e0513d6a9c", - }), - fkRails7Bf8C65391: foreignKey({ - columns: [table.profileId], - foreignColumns: [profiles.id], - name: "fk_rails_7bf8c65391", - }), - }; - }, -); - -export type PokemonTeam = typeof pokemonTeams.$inferSelect; -export type PokemonTeamInsert = typeof pokemonTeams.$inferInsert; diff --git a/packages/db/src/schemas/pokemon.ts b/packages/db/src/schemas/pokemon.ts deleted file mode 100644 index 0b9315c0..00000000 --- a/packages/db/src/schemas/pokemon.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { - bigint, - bigserial, - boolean, - foreignKey, - index, - integer, - pgTable, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -import { pokemonTeams } from "./pokemon-teams"; - -export const pokemon = pgTable( - "pokemon", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - species: varchar(), - ability: varchar(), - teraType: varchar("tera_type"), - nature: varchar(), - item: varchar(), - move1: varchar(), - move2: varchar(), - move3: varchar(), - move4: varchar(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - nickname: varchar(), - pokemonTeamId: bigint("pokemon_team_id", { mode: "bigint" }) - .default(BigInt(0)) - .notNull(), - form: varchar(), - position: integer().default(0).notNull(), - gender: integer().default(2).notNull(), - shiny: boolean().default(false).notNull(), - evHp: integer("ev_hp"), - evAtk: integer("ev_atk"), - evDef: integer("ev_def"), - evSpa: integer("ev_spa"), - evSpd: integer("ev_spd"), - evSpe: integer("ev_spe"), - ivHp: integer("iv_hp"), - ivAtk: integer("iv_atk"), - ivDef: integer("iv_def"), - ivSpa: integer("iv_spa"), - ivSpd: integer("iv_spd"), - ivSpe: integer("iv_spe"), - }, - (table) => { - return { - indexPokemonOnPokemonTeamId: index( - "index_pokemon_on_pokemon_team_id", - ).using("btree", table.pokemonTeamId.asc().nullsLast()), - indexPokemonOnPokemonTeamIdAndPosition: uniqueIndex( - "index_pokemon_on_pokemon_team_id_and_position", - ).using( - "btree", - table.pokemonTeamId.asc().nullsLast(), - table.position.asc().nullsLast(), - ), - fkRails5B6022737B: foreignKey({ - columns: [table.pokemonTeamId], - foreignColumns: [pokemonTeams.id], - name: "fk_rails_5b6022737b", - }), - }; - }, -); - -export type Pokemon = typeof pokemon.$inferSelect; -export type PokemonInsert = typeof pokemon.$inferInsert; diff --git a/packages/db/src/schemas/profiles.ts b/packages/db/src/schemas/profiles.ts deleted file mode 100644 index ab310c39..00000000 --- a/packages/db/src/schemas/profiles.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { - bigint, - bigserial, - boolean, - foreignKey, - index, - pgTable, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -import { accounts } from "./accounts"; - -export const profiles = pgTable( - "profiles", - { - username: varchar().notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - imageUrl: varchar("image_url"), - slug: varchar(), - accountId: bigint("account_id", { mode: "bigint" }), - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }), - default: boolean().default(false).notNull(), - type: varchar().default("Profile").notNull(), - }, - (table) => { - return { - indexProfilesOnAccountId: index("index_profiles_on_account_id").using( - "btree", - table.accountId.asc().nullsLast(), - ), - indexProfilesOnSlug: uniqueIndex("index_profiles_on_slug").using( - "btree", - table.slug.asc().nullsLast(), - ), - indexProfilesOnUsername: uniqueIndex("index_profiles_on_username").using( - "btree", - table.username.asc().nullsLast(), - ), - fkRailsE424190865: foreignKey({ - columns: [table.accountId], - foreignColumns: [accounts.id], - name: "fk_rails_e424190865", - }), - }; - }, -); - -export type Profile = typeof profiles.$inferSelect; -export type ProfileInsert = typeof profiles.$inferInsert; diff --git a/packages/db/src/schemas/rounds.ts b/packages/db/src/schemas/rounds.ts deleted file mode 100644 index c2b7aafd..00000000 --- a/packages/db/src/schemas/rounds.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - bigint, - bigserial, - index, - integer, - pgTable, - timestamp, - uniqueIndex, -} from "drizzle-orm/pg-core"; - -export const rounds = pgTable( - "rounds", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - phaseId: bigint("phase_id", { mode: "bigint" }).notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - roundNumber: integer("round_number").default(1).notNull(), - startedAt: timestamp("started_at", { precision: 6, mode: "string" }), - endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), - }, - (table) => { - return { - indexRoundsOnPhaseId: index("index_rounds_on_phase_id").using( - "btree", - table.phaseId.asc().nullsLast(), - ), - indexRoundsOnPhaseIdAndRoundNumber: uniqueIndex( - "index_rounds_on_phase_id_and_round_number", - ).using( - "btree", - table.phaseId.asc().nullsLast(), - table.roundNumber.asc().nullsLast(), - ), - }; - }, -); - -export type Round = typeof rounds.$inferSelect; -export type RoundInsert = typeof rounds.$inferInsert; diff --git a/packages/db/src/schemas/tournaments-formats.ts b/packages/db/src/schemas/tournaments-formats.ts deleted file mode 100644 index 62193d64..00000000 --- a/packages/db/src/schemas/tournaments-formats.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - bigint, - bigserial, - foreignKey, - index, - pgTable, - timestamp, -} from "drizzle-orm/pg-core"; - -import { formats } from "./formats"; -import { tournaments } from "./tournaments"; - -export const tournamentFormats = pgTable( - "tournament_formats", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - tournamentId: bigint("tournament_id", { mode: "bigint" }).notNull(), - formatId: bigint("format_id", { mode: "bigint" }).notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - }, - (table) => { - return { - indexTournamentFormatsOnFormatId: index( - "index_tournament_formats_on_format_id", - ).using("btree", table.formatId.asc().nullsLast()), - indexTournamentFormatsOnTournamentId: index( - "index_tournament_formats_on_tournament_id", - ).using("btree", table.tournamentId.asc().nullsLast()), - fkRails08C15D3C37: foreignKey({ - columns: [table.formatId], - foreignColumns: [formats.id], - name: "fk_rails_08c15d3c37", - }), - fkRailsC679052Dc0: foreignKey({ - columns: [table.tournamentId], - foreignColumns: [tournaments.id], - name: "fk_rails_c679052dc0", - }), - }; - }, -); - -export type TournamentFormat = typeof tournamentFormats.$inferSelect; -export type TournamentFormatInsert = typeof tournamentFormats.$inferInsert; diff --git a/packages/db/src/schemas/tournaments.ts b/packages/db/src/schemas/tournaments.ts deleted file mode 100644 index a59877c4..00000000 --- a/packages/db/src/schemas/tournaments.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { sql } from "drizzle-orm"; -import { - bigint, - bigserial, - boolean, - date, - foreignKey, - index, - integer, - pgTable, - timestamp, - uniqueIndex, - varchar, -} from "drizzle-orm/pg-core"; - -import { games } from "./games"; -import { organizations } from "./organizations"; -import { phases } from "./phases"; - -export const tournaments = pgTable( - "tournaments", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - name: varchar(), - startAt: timestamp("start_at", { precision: 6, mode: "string" }), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - organizationId: bigint("organization_id", { mode: "bigint" }), - checkInStartAt: timestamp("check_in_start_at", { - precision: 6, - mode: "string", - }), - gameId: bigint("game_id", { mode: "bigint" }), - formatId: bigint("format_id", { mode: "bigint" }), - endedAt: timestamp("ended_at", { precision: 6, mode: "string" }), - registrationStartAt: timestamp("registration_start_at", { - precision: 6, - mode: "string", - }), - registrationEndAt: timestamp("registration_end_at", { - precision: 6, - mode: "string", - }), - playerCap: integer("player_cap"), - autostart: boolean().default(false).notNull(), - startedAt: timestamp("started_at", { precision: 6, mode: "string" }), - lateRegistration: boolean("late_registration").default(true).notNull(), - teamlistsRequired: boolean("teamlists_required").default(true).notNull(), - openTeamSheets: boolean("open_team_sheets").default(true).notNull(), - endAt: timestamp("end_at", { precision: 6, mode: "string" }), - limitlessId: bigint("limitless_id", { mode: "bigint" }), - published: boolean().default(false).notNull(), - currentPhaseId: bigint("current_phase_id", { mode: "bigint" }), - }, - (table) => { - return { - indexTournamentsOnCurrentPhaseId: index( - "index_tournaments_on_current_phase_id", - ).using("btree", table.currentPhaseId.asc().nullsLast()), - indexTournamentsOnFormatId: index("index_tournaments_on_format_id").using( - "btree", - table.formatId.asc().nullsLast(), - ), - indexTournamentsOnGameId: index("index_tournaments_on_game_id").using( - "btree", - table.gameId.asc().nullsLast(), - ), - indexTournamentsOnLimitlessId: uniqueIndex( - "index_tournaments_on_limitless_id", - ) - .using("btree", table.limitlessId.asc().nullsLast()) - .where(sql`(limitless_id IS NOT NULL)`), - indexTournamentsOnOrganizationId: index( - "index_tournaments_on_organization_id", - ).using("btree", table.organizationId.asc().nullsLast()), - fkRails8Ef7Ba6258: foreignKey({ - columns: [table.gameId], - foreignColumns: [games.id], - name: "fk_rails_8ef7ba6258", - }), - fkRails325Ccadea6: foreignKey({ - columns: [table.organizationId], - foreignColumns: [organizations.id], - name: "fk_rails_325ccadea6", - }), - fkRails40Bc0Fb494: foreignKey({ - columns: [table.currentPhaseId], - foreignColumns: [phases.id], - name: "fk_rails_40bc0fb494", - }), - }; - }, -); - -export const rk9Tournaments = pgTable( - "rk9_tournaments", - { - id: bigserial({ mode: "bigint" }).primaryKey().notNull(), - rk9Id: varchar("rk9_id").notNull(), - name: varchar().notNull(), - startDate: date("start_date").notNull(), - endDate: date("end_date").notNull(), - createdAt: timestamp("created_at", { - precision: 6, - mode: "string", - }).notNull(), - updatedAt: timestamp("updated_at", { - precision: 6, - mode: "string", - }).notNull(), - }, - (table) => { - return { - indexRk9TournamentsOnEndDate: index( - "index_rk9_tournaments_on_end_date", - ).using("btree", table.endDate.asc().nullsLast()), - indexRk9TournamentsOnName: uniqueIndex( - "index_rk9_tournaments_on_name", - ).using("btree", table.name.asc().nullsLast()), - indexRk9TournamentsOnRk9Id: uniqueIndex( - "index_rk9_tournaments_on_rk9_id", - ).using("btree", table.rk9Id.asc().nullsLast()), - indexRk9TournamentsOnStartAndEndDate: index( - "index_rk9_tournaments_on_start_and_end_date", - ).using( - "btree", - table.startDate.asc().nullsLast(), - table.endDate.asc().nullsLast(), - ), - indexRk9TournamentsOnStartDate: index( - "index_rk9_tournaments_on_start_date", - ).using("btree", table.startDate.asc().nullsLast()), - }; - }, -); - -export type Tournament = typeof tournaments.$inferSelect; -export type TournamentInsert = typeof tournaments.$inferInsert; -export type Rk9Tournament = typeof rk9Tournaments.$inferSelect; -export type Rk9TournamentInsert = typeof rk9Tournaments.$inferInsert; diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json index a58a3d69..5a01b42e 100644 --- a/packages/db/tsconfig.json +++ b/packages/db/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "@battle-stadium/tsconfig/internal-package.json", - "include": ["src"], - "exclude": ["node_modules", ".cache", ".turbo", "dist"] + "include": ["src", "drizzle"], + "exclude": ["node_modules", ".cache", ".turbo"] }