feat: add sqlite db
This commit is contained in:
1 parent
39769391ea
commit
8b8d220b13
8 files changed
+64
-1
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { createClient } from "@libsql/client";
|
||||
import { drizzle } from "drizzle-orm/libsql";
|
||||
import { migrate } from "drizzle-orm/libsql/migrator";
|
||||
import path from "path";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const DB_PATH =
|
||||
process.env.APP_DB_PATH || path.join(process.cwd(), "data", "app.db");
|
||||
|
||||
const client = createClient({ url: `file:${DB_PATH}` });
|
||||
|
||||
export const appDb = drizzle(client, { schema });
|
||||
|
||||
// Run pending migrations automatically on startup.
|
||||
// migrate() is idempotent — safe to call on every boot.
|
||||
export async function runMigrations() {
|
||||
await migrate(appDb, {
|
||||
migrationsFolder: path.join(process.cwd(), "src", "db", "migrations"),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "5",
|
||||
"dialect": "sqlite",
|
||||
"entries": []
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./settings.schema";
|
||||
@@ -0,0 +1,9 @@
|
||||
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const settings = sqliteTable("settings", {
|
||||
key: text("key").primaryKey(),
|
||||
value: text("value").notNull(),
|
||||
updatedAt: integer("updated_at", { mode: "timestamp" }).$onUpdate(
|
||||
() => new Date()
|
||||
),
|
||||
});
|
||||
Reference in new issue
Block a user