feat(database): extended async task with metadata and parent id, added index (#11712)

This commit is contained in:
Neko
2026-01-23 21:49:56 +08:00
committed by GitHub
parent 464e5605c7
commit 31d2f26b6e
5 changed files with 10749 additions and 2 deletions

View File

@@ -174,12 +174,17 @@ table async_tasks {
error jsonb
user_id text [not null]
duration integer
parent_id uuid
metadata jsonb [not null, default: '{}']
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()`]
indexes {
user_id [name: 'async_tasks_user_id_idx']
parent_id [name: 'async_tasks_parent_id_idx']
(type, status) [name: 'async_tasks_type_status_idx']
metadata [name: 'async_tasks_metadata_idx']
}
}

View File

@@ -0,0 +1,5 @@
ALTER TABLE "async_tasks" ADD COLUMN IF NOT EXISTS "parent_id" uuid;--> statement-breakpoint
ALTER TABLE "async_tasks" ADD COLUMN IF NOT EXISTS "metadata" jsonb DEFAULT '{}' NOT NULL;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "async_tasks_parent_id_idx" ON "async_tasks" USING btree ("parent_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "async_tasks_type_status_idx" ON "async_tasks" USING btree ("type","status");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "async_tasks_metadata_idx" ON "async_tasks" USING gin ("metadata");

File diff suppressed because it is too large Load Diff

View File

@@ -497,6 +497,13 @@
"when": 1768999498635,
"tag": "0070_add_user_memory_activities",
"breakpoints": true
},
{
"idx": 71,
"version": "7",
"when": 1769093425330,
"tag": "0071_add_async_task_extend",
"breakpoints": true
}
],
"version": "6"

View File

@@ -17,11 +17,21 @@ export const asyncTasks = pgTable(
.references(() => users.id, { onDelete: 'cascade' })
.notNull(),
duration: integer('duration'),
parentId: uuid('parent_id'),
metadata: jsonb('metadata').notNull().default('{}'),
...timestamps,
},
(t) => [index('async_tasks_user_id_idx').on(t.userId)],
(t) => [
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,
)
],
);
export type NewAsyncTaskItem = typeof asyncTasks.$inferInsert;
export type AsyncTaskSelectItem = typeof asyncTasks.$inferSelect;
export type AsyncTaskSelectItem = Omit<typeof asyncTasks.$inferSelect, 'metadata' | 'parentId'> & Partial<Pick<typeof asyncTasks.$inferSelect, 'metadata' | 'parentId'>>;