feat(db): introduce SQLite (better-sqlite3) backing store
First step of the folder/video refactor. Adds an app-local SQLite DB at
data/app.db with schema for nested folders (max 2 levels enforced in
code, not SQL) and user-editable globally-unique video IDs.
- src/db.ts: open + WAL + schema (folders, videos) + partial unique
index for top-level folder names (NULL parent_id case)
- One-shot disk-tree migration: on first start scans data/folders/*
and seeds folder rows; reads each {videoId}/meta.json to seed video
rows. Skips invalid/missing meta gracefully.
- Wired into app.ts startup before routes mount.
- gitignore: data/app.db* (DB + WAL/journal sidecars).
Schema only — no routes or store.ts changes yet. Next step swaps the
file-based store calls to DB-backed equivalents.
Smoke-tested on the current data dir: 3 folders migrated, 0 videos
(folders were empty). Build (npx tsc) passes.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import fsp from 'node:fs/promises'
|
||||
import { dataDir, foldersDir, jobsDir, tmpDir, publicDir, viewsDir } from './paths.js'
|
||||
import { publicRouter } from './routes/public.js'
|
||||
import { opRouter } from './routes/op.js'
|
||||
import { initDatabase } from './db.js'
|
||||
|
||||
async function ensureDirs(): Promise<void> {
|
||||
for (const dir of [dataDir, foldersDir, jobsDir, tmpDir]) {
|
||||
@@ -15,6 +16,8 @@ async function ensureDirs(): Promise<void> {
|
||||
|
||||
async function main(): Promise<void> {
|
||||
await ensureDirs()
|
||||
// SQLite 스키마 보장 + 비어 있으면 기존 디스크 트리에서 마이그레이션.
|
||||
await initDatabase()
|
||||
|
||||
const PORT = Number(process.env.PORT ?? 3000)
|
||||
const HOST = process.env.HOST ?? '127.0.0.1'
|
||||
|
||||
Reference in New Issue
Block a user