🗃️ db: add video generation schema changes

- async_tasks: add inference_id column with index
- generation_topics: add type column (default 'image')
This commit is contained in:
YuTengjing
2026-02-13 12:09:18 +08:00
parent d225da96df
commit e112cd6f7f
6 changed files with 12154 additions and 5 deletions

View File

@@ -201,6 +201,7 @@ table async_tasks {
type text
status text
error jsonb
inference_id text
user_id text [not null]
duration integer
parent_id uuid
@@ -213,6 +214,7 @@ table async_tasks {
user_id [name: 'async_tasks_user_id_idx']
parent_id [name: 'async_tasks_parent_id_idx']
(type, status) [name: 'async_tasks_type_status_idx']
inference_id [name: 'async_tasks_inference_id_idx']
metadata [name: 'async_tasks_metadata_idx']
}
}
@@ -479,6 +481,7 @@ table generation_topics {
user_id text [not null]
title text
cover_url text
type varchar(32) [not null, default: 'image']
accessed_at "timestamp with time zone" [not null, default: `now()`]
created_at "timestamp with time zone" [not null, default: `now()`]
updated_at "timestamp with time zone" [not null, default: `now()`]

View File

@@ -0,0 +1,3 @@
ALTER TABLE "async_tasks" ADD COLUMN IF NOT EXISTS "inference_id" text;--> statement-breakpoint
ALTER TABLE "generation_topics" ADD COLUMN IF NOT EXISTS "type" varchar(32) DEFAULT 'image' NOT NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "async_tasks_inference_id_idx" ON "async_tasks" USING btree ("inference_id");

File diff suppressed because it is too large Load Diff

View File

@@ -602,7 +602,14 @@
"when": 1770632176750,
"tag": "0085_remove_id_unique_constraint",
"breakpoints": true
},
{
"idx": 86,
"version": "7",
"when": 1770955654188,
"tag": "0086_video_generation_schema",
"breakpoints": true
}
],
"version": "6"
}
}

View File

@@ -12,6 +12,7 @@ export const asyncTasks = pgTable(
status: text('status'),
error: jsonb('error'),
inferenceId: text('inference_id'),
userId: text('user_id')
.references(() => users.id, { onDelete: 'cascade' })
@@ -26,10 +27,8 @@ export const asyncTasks = pgTable(
index('async_tasks_user_id_idx').on(t.userId),
index('async_tasks_parent_id_idx').on(t.parentId),
index('async_tasks_type_status_idx').on(t.type, t.status),
index('async_tasks_metadata_idx').using(
'gin',
t.metadata,
)
index('async_tasks_inference_id_idx').on(t.inferenceId),
index('async_tasks_metadata_idx').using('gin', t.metadata)
],
);

View File

@@ -31,6 +31,9 @@ export const generationTopics = pgTable(
/** Topic cover image URL */
coverUrl: text('cover_url'),
/** Topic type: 'image' or 'video' */
type: varchar('type', { length: 32 }).notNull().default('image'),
...timestamps,
},
(t) => [index('generation_topics_user_id_idx').on(t.userId)],