feat: 迁移数据库至 SQLite 并新增项目文档
- 将 Postgres 数据库替换为 SQLite - 并同步添加 README 文档以优化项目初始化流程
This commit is contained in:
@@ -1,15 +1,33 @@
|
||||
/**
|
||||
* Todo 表 Schema
|
||||
*
|
||||
* 使用 SQLite 数据类型:
|
||||
* - text: 字符串类型
|
||||
* - integer: 整数类型 (可配置为 boolean/timestamp 模式)
|
||||
*/
|
||||
import { sql } from 'drizzle-orm'
|
||||
import { boolean, pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core'
|
||||
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
||||
|
||||
export const todoTable = pgTable('todo', {
|
||||
id: uuid('id').primaryKey().default(sql`uuidv7()`),
|
||||
export const todoTable = sqliteTable('todo', {
|
||||
/** 主键 UUID */
|
||||
id: text('id')
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
|
||||
/** 待办事项标题 */
|
||||
title: text('title').notNull(),
|
||||
completed: boolean('completed').notNull().default(false),
|
||||
createdAt: timestamp('created_at', { withTimezone: true })
|
||||
|
||||
/** 是否已完成 (SQLite 用 0/1 表示布尔值) */
|
||||
completed: integer('completed', { mode: 'boolean' }).notNull().default(false),
|
||||
|
||||
/** 创建时间 (Unix 时间戳) */
|
||||
createdAt: integer('created_at', { mode: 'timestamp' })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true })
|
||||
.default(sql`(unixepoch())`),
|
||||
|
||||
/** 更新时间 (Unix 时间戳,自动更新) */
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' })
|
||||
.notNull()
|
||||
.defaultNow()
|
||||
.default(sql`(unixepoch())`)
|
||||
.$onUpdateFn(() => new Date()),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user