🐜 fix(db): Make controller_support an enum

This commit is contained in:
Wanjohi
2025-05-11 03:58:30 +03:00
parent 6051e11921
commit 82dfd6506d
7 changed files with 1282 additions and 6 deletions

View File

@@ -0,0 +1,3 @@
CREATE TYPE "public"."controller_support" AS ENUM('full', 'unknown');--> statement-breakpoint
ALTER TABLE "base_games" ALTER COLUMN "controller_support" SET DATA TYPE controller_support;--> statement-breakpoint
ALTER TABLE "base_games" ALTER COLUMN "controller_support" SET NOT NULL;

File diff suppressed because it is too large Load Diff

View File

@@ -92,6 +92,13 @@
"when": 1746905730079,
"tag": "0012_glorious_jetstream",
"breakpoints": true
},
{
"idx": 13,
"version": "7",
"when": 1746925065142,
"tag": "0013_neat_colleen_wing",
"breakpoints": true
}
]
}

View File

@@ -3,6 +3,7 @@ import { timestamps, utc } from "../drizzle/types";
import { json, numeric, pgEnum, pgTable, text, unique, varchar } from "drizzle-orm/pg-core";
export const CompatibilityEnum = pgEnum("compatibility", ["high", "mid", "low", "unknown"])
export const ControllerEnum = pgEnum("controller_support", ["full", "unknown"])
export const Size =
z.object({
@@ -26,7 +27,7 @@ export const baseGamesTable = pgTable(
size: json("size").$type<Size>().notNull(),
description: text("description").notNull(),
primaryGenre: text("primary_genre").notNull(),
controllerSupport: text("controller_support"),
controllerSupport: ControllerEnum("controller_support").notNull(),
compatibility: CompatibilityEnum("compatibility").notNull().default("unknown"),
// Score ranges from 0.0 to 5.0
score: numeric("score", { precision: 2, scale: 1 })

View File

@@ -2,9 +2,9 @@ import { z } from "zod";
import { fn } from "../utils";
import { Common } from "../common";
import { Examples } from "../examples";
import { createTransaction } from "../drizzle/transaction";
import { CompatibilityEnum, baseGamesTable, Size } from "./base-game.sql";
import { eq, isNull, or, and } from "drizzle-orm";
import { createTransaction } from "../drizzle/transaction";
import { CompatibilityEnum, baseGamesTable, Size, ControllerEnum } from "./base-game.sql";
export namespace BaseGame {
export const Info = z.object({
@@ -40,7 +40,7 @@ export namespace BaseGame {
description: "The main category or genre that best represents the game's content and gameplay style",
example: Examples.BaseGame.primaryGenre
}),
controllerSupport: z.string().nullable().openapi({
controllerSupport: z.enum(ControllerEnum.enumValues).openapi({
description: "Indicates the level of gamepad/controller compatibility: 'Full', 'Partial', or null for no support",
example: Examples.BaseGame.controllerSupport
}),

View File

@@ -152,7 +152,7 @@ export namespace Examples {
id: "1809540",
slug: "nine-sols",
name: "Nine Sols",
controllerSupport: "full",
controllerSupport: "full" as const,
releaseDate: new Date("2024-05-29T06:53:24.000Z"),
compatibility: "high" as const,
size: {

View File

@@ -96,7 +96,7 @@ const base_games = table("base_games")
size: json<Size>(),
description: string(),
primary_genre: string(),
controller_support: string().optional(),
controller_support: enumeration<"full" | "unknown">(),
compatibility: enumeration<"high" | "mid" | "low" | "unknown">(),
score: number(),
...timestamps