mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
✨ feat(database): extended async task with metadata and parent id, added index (#11712)
This commit is contained in:
@@ -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']
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
10720
packages/database/migrations/meta/0071_snapshot.json
Normal file
10720
packages/database/migrations/meta/0071_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
|
||||
@@ -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'>>;
|
||||
|
||||
Reference in New Issue
Block a user