mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-11 00:05:36 +02:00
🐜 fix(db): Make controller_support an enum
This commit is contained in:
3
packages/core/migrations/0013_neat_colleen_wing.sql
Normal file
3
packages/core/migrations/0013_neat_colleen_wing.sql
Normal 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;
|
||||
1265
packages/core/migrations/meta/0013_snapshot.json
Normal file
1265
packages/core/migrations/meta/0013_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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 })
|
||||
|
||||
@@ -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
|
||||
}),
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user