feat : remove legacy feature
CI / Verify (push) Successful in 1m21s
CI / Build immutable images and deploy (push) Successful in 4m32s

This commit is contained in:
2026-09-10 19:45:06 +07:00 Unverified
parent cc0757d0a0
commit 249af29e9b
56 changed files with 5491 additions and 9393 deletions
-304
View File
@@ -1,4 +1,3 @@
import { relations, sql } from "drizzle-orm";
import {
bigint,
boolean,
@@ -26,7 +25,6 @@ import type { ExtraSheet } from "@/lib/guides/extra-sheet";
const authSchema = pgSchema("auth");
const mediaSchema = pgSchema("media");
const editorSchema = pgSchema("editor");
const catalogSchema = pgSchema("catalog");
const guidesSchema = pgSchema("guides");
@@ -135,9 +133,6 @@ export const media = mediaSchema.table(
currentReferenceCount: integer("current_reference_count")
.default(0)
.notNull(),
revisionReferenceCount: integer("revision_reference_count")
.default(0)
.notNull(),
createdById: text("created_by_id").references(() => users.id, {
onDelete: "set null",
}),
@@ -152,265 +147,6 @@ export const media = mediaSchema.table(
],
);
export const characters = editorSchema.table(
"character",
{
id: uuid("id").defaultRandom().primaryKey(),
slug: varchar("slug", { length: 120 }).notNull(),
nameTh: text("name_th").notNull(),
nameEn: text("name_en"),
description: text("description"),
portraitMediaId: uuid("portrait_media_id").references(() => media.id, {
onDelete: "set null",
}),
element: varchar("element", { length: 48 }),
role: varchar("role", { length: 80 }),
rarity: integer("rarity"),
sortOrder: integer("sort_order").default(0).notNull(),
visible: boolean("visible").default(false).notNull(),
...timestamps,
},
(table) => [
uniqueIndex("character_slug_unique").on(table.slug),
index("character_directory_idx").on(table.visible, table.sortOrder),
],
);
export const pages = editorSchema.table(
"page",
{
id: uuid("id").defaultRandom().primaryKey(),
characterId: uuid("character_id")
.notNull()
.references(() => characters.id, { onDelete: "cascade" }),
slug: varchar("slug", { length: 120 }).notNull(),
title: text("title").notNull(),
navOrder: integer("nav_order").default(0).notNull(),
visible: boolean("visible").default(false).notNull(),
publicNote: text("public_note"),
version: integer("version").default(1).notNull(),
...timestamps,
},
(table) => [
uniqueIndex("page_character_slug_unique").on(
table.characterId,
table.slug,
),
index("page_navigation_idx").on(
table.characterId,
table.visible,
table.navOrder,
),
],
);
export const blocks = editorSchema.table(
"block",
{
id: uuid("id").primaryKey(),
pageId: uuid("page_id")
.notNull()
.references(() => pages.id, { onDelete: "cascade" }),
type: varchar("type", { length: 64 }).notNull(),
schemaVersion: integer("schema_version").default(1).notNull(),
config: jsonb("config").$type<Record<string, unknown>>().notNull(),
responsiveLayout: jsonb("responsive_layout")
.$type<Record<string, unknown>>()
.default({})
.notNull(),
sortOrder: integer("sort_order").default(0).notNull(),
...timestamps,
},
(table) => [index("block_page_order_idx").on(table.pageId, table.sortOrder)],
);
export const dataSources = editorSchema.table(
"data_source",
{
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
description: text("description"),
fields: jsonb("fields").$type<unknown[]>().default([]).notNull(),
currentVersion: integer("current_version").default(1).notNull(),
...timestamps,
},
(table) => [index("data_source_name_idx").on(table.name)],
);
export const dataSourceVersions = editorSchema.table(
"data_source_version",
{
id: uuid("id").defaultRandom().primaryKey(),
dataSourceId: uuid("data_source_id")
.notNull()
.references(() => dataSources.id, { onDelete: "cascade" }),
version: integer("version").notNull(),
rows: jsonb("rows").$type<unknown[]>().default([]).notNull(),
evaluation: jsonb("evaluation").$type<Record<string, unknown>>(),
createdById: text("created_by_id").references(() => users.id, {
onDelete: "set null",
}),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => [
uniqueIndex("data_source_version_unique").on(
table.dataSourceId,
table.version,
),
],
);
export const pageDataSources = editorSchema.table(
"page_data_source",
{
pageId: uuid("page_id")
.notNull()
.references(() => pages.id, { onDelete: "cascade" }),
dataSourceId: uuid("data_source_id")
.notNull()
.references(() => dataSources.id, { onDelete: "restrict" }),
pinnedVersion: integer("pinned_version"),
},
(table) => [
primaryKey({ columns: [table.pageId, table.dataSourceId] }),
index("page_data_source_dependency_idx").on(table.dataSourceId),
],
);
export const templates = editorSchema.table(
"template",
{
id: uuid("id").defaultRandom().primaryKey(),
slug: varchar("slug", { length: 120 }).notNull(),
name: text("name").notNull(),
description: text("description"),
category: varchar("category", { length: 64 }).notNull(),
structure: jsonb("structure").$type<Record<string, unknown>>().notNull(),
builtIn: boolean("built_in").default(false).notNull(),
...timestamps,
},
(table) => [uniqueIndex("template_slug_unique").on(table.slug)],
);
export const revisions = editorSchema.table(
"revision",
{
id: uuid("id").defaultRandom().primaryKey(),
pageId: uuid("page_id")
.notNull()
.references(() => pages.id, { onDelete: "cascade" }),
pageVersion: integer("page_version").notNull(),
kind: varchar("kind", { length: 24 }).notNull(),
label: text("label"),
authorId: text("author_id").references(() => users.id, {
onDelete: "set null",
}),
sourceRevisionId: uuid("source_revision_id"),
checkpointHour: timestamp("checkpoint_hour", { withTimezone: true }),
snapshot: jsonb("snapshot").$type<Record<string, unknown>>().notNull(),
dataSourceVersions: jsonb("data_source_versions")
.$type<Record<string, number>>()
.default({})
.notNull(),
mediaIds: jsonb("media_ids").$type<string[]>().default([]).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
expiresAt: timestamp("expires_at", { withTimezone: true }),
},
(table) => [
index("revision_page_created_idx").on(table.pageId, table.createdAt),
uniqueIndex("revision_checkpoint_hour_unique")
.on(table.pageId, table.checkpointHour)
.where(sql`${table.kind} = 'checkpoint'`),
],
);
export const publicSnapshots = editorSchema.table(
"public_snapshot",
{
id: uuid("id").defaultRandom().primaryKey(),
pageId: uuid("page_id")
.notNull()
.references(() => pages.id, { onDelete: "cascade" }),
pageVersion: integer("page_version").notNull(),
versionVector: jsonb("version_vector")
.$type<Record<string, number>>()
.default({})
.notNull(),
vectorHash: varchar("vector_hash", { length: 64 }).notNull(),
dto: jsonb("dto").$type<Record<string, unknown>>().notNull(),
visible: boolean("visible").default(false).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => [
uniqueIndex("public_snapshot_version_unique").on(
table.pageId,
table.pageVersion,
table.vectorHash,
),
index("public_snapshot_lookup_idx").on(
table.pageId,
table.visible,
table.createdAt,
),
],
);
export const slugAliases = editorSchema.table(
"slug_alias",
{
id: uuid("id").defaultRandom().primaryKey(),
kind: varchar("kind", { length: 24 }).notNull(),
oldCharacterSlug: varchar("old_character_slug", { length: 120 }).notNull(),
oldPageSlug: varchar("old_page_slug", { length: 120 }),
targetCharacterId: uuid("target_character_id")
.notNull()
.references(() => characters.id, { onDelete: "cascade" }),
targetPageId: uuid("target_page_id").references(() => pages.id, {
onDelete: "cascade",
}),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => [
uniqueIndex("slug_alias_path_unique").on(
table.oldCharacterSlug,
table.oldPageSlug,
),
],
);
export const mediaReferences = mediaSchema.table(
"media_reference",
{
mediaId: uuid("media_id")
.notNull()
.references(() => media.id, { onDelete: "cascade" }),
ownerType: varchar("owner_type", { length: 24 }).notNull(),
ownerId: uuid("owner_id").notNull(),
referenceKind: varchar("reference_kind", { length: 24 }).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => [
primaryKey({
columns: [
table.mediaId,
table.ownerType,
table.ownerId,
table.referenceKind,
],
}),
index("media_reference_owner_idx").on(table.ownerType, table.ownerId),
],
);
export const outboxEvents = pgTable(
"outbox_event",
@@ -762,43 +498,3 @@ export const extraSectionRows = guidesSchema.table(
},
(table) => [index("extra_section_row_order_idx").on(table.sectionId, table.sortOrder)],
);
export const characterRelations = relations(characters, ({ many, one }) => ({
pages: many(pages),
portrait: one(media, {
fields: [characters.portraitMediaId],
references: [media.id],
}),
}));
export const pageRelations = relations(pages, ({ many, one }) => ({
character: one(characters, {
fields: [pages.characterId],
references: [characters.id],
}),
blocks: many(blocks),
dependencies: many(pageDataSources),
revisions: many(revisions),
}));
export const blockRelations = relations(blocks, ({ one }) => ({
page: one(pages, {
fields: [blocks.pageId],
references: [pages.id],
}),
}));
export const dataSourceRelations = relations(dataSources, ({ many }) => ({
versions: many(dataSourceVersions),
pageDependencies: many(pageDataSources),
}));
export const dataSourceVersionRelations = relations(
dataSourceVersions,
({ one }) => ({
dataSource: one(dataSources, {
fields: [dataSourceVersions.dataSourceId],
references: [dataSources.id],
}),
}),
);