- packages/db: schema on sqlite-core (timestamps as epoch ms → Date, JSON as text, booleans 0/1), one baseline migration; node:sqlite client under drizzle's better-sqlite3 session (busy_timeout first, WAL, BEGIN IMMEDIATE, retries on SQLITE_BUSY, lazy open, async transaction callbacks refused); PEPPA_DB (default ~/.peppa/peppa.db) - live updates: notify() pokes the bot over a unix socket; the bot also watches PRAGMA data_version every second (writes by other processes) - Postgres specifics ported: createTask transaction is synchronous, no `for update skip locked`, `count(*)`, json_extract instead of ->>, json_each instead of @> - `peppa db migrate` and `peppa db migrate-to-sqlite <file>` (read-only snapshot of Postgres, FK order from the schema, row count + foreign key checks, file appears only when they pass); old Postgres schema kept in packages/cli/legacy-pg-migrations for the migration and its test - daily VACUUM INTO backup from the watchdog (7 copies, admin alert on failure) - tests: a temp SQLite file per test file; storage.test.ts (20 processes, per-project numbering across processes, socket/data_version, migration from Postgres incl. a dangling foreign key, backups); two test races fixed - CI: no per-run Postgres database; PEPPA_TEST_PG only for the migration test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.1 KiB
SQL
29 lines
1.1 KiB
SQL
CREATE TABLE "settings" (
|
|
"key" text PRIMARY KEY NOT NULL,
|
|
"value" jsonb NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "telegram_outbox" (
|
|
"id" serial PRIMARY KEY NOT NULL,
|
|
"dedupe_key" text NOT NULL,
|
|
"method" text NOT NULL,
|
|
"params" jsonb NOT NULL,
|
|
"question_id" integer,
|
|
"status" text DEFAULT 'pending' NOT NULL,
|
|
"attempts" integer DEFAULT 0 NOT NULL,
|
|
"next_attempt_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"telegram_message_id" integer,
|
|
"error" text,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"sent_at" timestamp with time zone,
|
|
CONSTRAINT "telegram_outbox_dedupe_key_unique" UNIQUE("dedupe_key")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "telegram_updates" (
|
|
"update_id" integer PRIMARY KEY NOT NULL,
|
|
"status" text NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "telegram_outbox" ADD CONSTRAINT "telegram_outbox_question_id_questions_id_fk" FOREIGN KEY ("question_id") REFERENCES "public"."questions"("id") ON DELETE set null ON UPDATE no action; |