refactor: remove structured settings tables, use freeform JSON for presets and entries
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
integer,
|
||||
jsonb,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
@@ -27,6 +28,13 @@ export const communityPresets = pgTable(
|
||||
onDelete: "set null",
|
||||
}),
|
||||
upvotes: integer("upvotes").default(0).notNull(),
|
||||
// Freeform settings JSON — same flexible structure as performanceEntries.settingsJson
|
||||
settingsJson: jsonb("settings_json").$type<
|
||||
{
|
||||
category: string
|
||||
settings: { title: string; value: string | number | boolean }[]
|
||||
}[]
|
||||
>(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||
},
|
||||
|
||||
@@ -5,8 +5,5 @@ export * from "./gameVersions"
|
||||
export * from "./hardware"
|
||||
export * from "./performanceEntries"
|
||||
export * from "./gamePlatformSupport"
|
||||
export * from "./settingCategories"
|
||||
export * from "./settingDefinitions"
|
||||
export * from "./communityPresets"
|
||||
export * from "./presetSettings"
|
||||
export * from "./gameComments"
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { jsonb, pgTable, text, timestamp, unique } from "drizzle-orm/pg-core"
|
||||
import { communityPresets } from "./communityPresets"
|
||||
import { settingDefinitions } from "./settingDefinitions"
|
||||
|
||||
export const presetSettings = pgTable(
|
||||
"preset_settings",
|
||||
{
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
presetId: text("preset_id")
|
||||
.notNull()
|
||||
.references(() => communityPresets.id, { onDelete: "cascade" }),
|
||||
settingDefinitionId: text("setting_definition_id")
|
||||
.notNull()
|
||||
.references(() => settingDefinitions.id, { onDelete: "cascade" }),
|
||||
// Value stored as JSON — boolean for toggle, string for select,
|
||||
// number for range/number
|
||||
value: jsonb("value").notNull().$type<boolean | string | number>(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
},
|
||||
(table) => [
|
||||
unique("preset_setting_unique").on(table.presetId, table.settingDefinitionId),
|
||||
],
|
||||
)
|
||||
@@ -1,11 +0,0 @@
|
||||
import { integer, pgTable, text, timestamp } from "drizzle-orm/pg-core"
|
||||
|
||||
export const settingCategories = pgTable("setting_categories", {
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
name: text("name").notNull(),
|
||||
slug: text("slug").notNull().unique(),
|
||||
sortOrder: integer("sort_order").default(0).notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
})
|
||||
@@ -1,46 +0,0 @@
|
||||
import {
|
||||
integer,
|
||||
jsonb,
|
||||
pgEnum,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
unique,
|
||||
} from "drizzle-orm/pg-core"
|
||||
import { settingCategories } from "./settingCategories"
|
||||
|
||||
export const settingInputTypeEnum = pgEnum("setting_input_type", [
|
||||
"toggle",
|
||||
"select",
|
||||
"range",
|
||||
"number",
|
||||
])
|
||||
|
||||
export const impactLevelEnum = pgEnum("impact_level", [
|
||||
"minor",
|
||||
"moderate",
|
||||
"major",
|
||||
])
|
||||
|
||||
export const settingDefinitions = pgTable(
|
||||
"setting_definitions",
|
||||
{
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
categoryId: text("category_id")
|
||||
.notNull()
|
||||
.references(() => settingCategories.id, { onDelete: "cascade" }),
|
||||
name: text("name").notNull(),
|
||||
slug: text("slug").notNull(),
|
||||
inputType: settingInputTypeEnum("input_type").notNull(),
|
||||
// For `select`: string[] of option labels
|
||||
// For `range`: { min: number, max: number, step: number }
|
||||
// For `toggle`/`number`: null
|
||||
options: jsonb("options").$type<string[] | { min: number; max: number; step: number }>(),
|
||||
impactLevel: impactLevelEnum("impact_level").default("minor").notNull(),
|
||||
sortOrder: integer("sort_order").default(0).notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
},
|
||||
(table) => [unique("setting_category_slug_unique").on(table.categoryId, table.slug)],
|
||||
)
|
||||
Reference in New Issue
Block a user