feat: 添加 flowme-life 功能,包括创建、更新、删除和列表接口,导入 life JSON 数据到数据库

This commit is contained in:
2026-03-10 20:17:49 +08:00
parent 48425c6120
commit 027cbecab6
11 changed files with 588 additions and 202 deletions

View File

@@ -0,0 +1,75 @@
import { pgTable, serial, text, jsonb, varchar, timestamp, unique, uuid, doublePrecision, json, integer, boolean, index, uniqueIndex, pgEnum } from "drizzle-orm/pg-core"
import { sql, sum } from "drizzle-orm"
export const life = pgTable("flowme_life", {
id: uuid().primaryKey().notNull().defaultRandom(),
uid: uuid(),
title: text('title').default(''),
tags: jsonb().default([]),
summary: text('summary').default(''),
description: text('description').default(''),
link: text('link').default(''),
data: jsonb().default({}),
effectiveAt: text('effectiveAt').default(''),
type: text('type').default(''),
prompt: text('prompt').default(''),
taskType: text('taskType').default(''),
taskResult: jsonb('taskResult').default({}),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow().$onUpdate(() => new Date()),
}, (table) => [
index('life_uid_idx').using('btree', table.uid.asc().nullsLast()),
index('life_title_idx').using('btree', table.title.asc().nullsLast()),
index('life_effective_at_idx').using('btree', table.effectiveAt.asc().nullsLast()),
index('life_summary_idx').using('btree', table.summary.asc().nullsLast()),
]);
export const flowme = pgTable("flowme", {
id: uuid().primaryKey().notNull().defaultRandom(),
uid: uuid(),
title: text('title').default(''),
tags: jsonb().default([]),
summary: text('summary').default(''),
description: text('description').default(''),
link: text('link').default(''),
data: jsonb().default({}),
channelId: uuid().references(() => flowmeChannels.id, { onDelete: 'set null' }),
type: text('type').default(''),
source: text('source').default(''),
importance: integer('importance').default(0), // 重要性等级
isArchived: boolean('isArchived').default(false), // 是否归档
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow().$onUpdate(() => new Date()),
}, (table) => [
index('flowme_uid_idx').using('btree', table.uid.asc().nullsLast()),
index('flowme_title_idx').using('btree', table.title.asc().nullsLast()),
index('flowme_channel_id_idx').using('btree', table.channelId.asc().nullsLast()),
]);
export const flowmeChannels = pgTable("flowme_channels", {
id: uuid().primaryKey().notNull().defaultRandom(),
uid: uuid(),
title: text('title').default(''),
tags: jsonb().default([]),
summary: text('summary').default(''),
description: text('description').default(''),
link: text('link').default(''),
data: jsonb().default({}),
key: text('key').default(''),
color: text('color').default('#007bff'),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow().$onUpdate(() => new Date()),
}, (table) => [
index('flowme_channels_uid_idx').using('btree', table.uid.asc().nullsLast()),
index('flowme_channels_key_idx').using('btree', table.key.asc().nullsLast()),
index('flowme_channels_title_idx').using('btree', table.title.asc().nullsLast()),
]);