08749df050
Swap modernc.org/sqlite for jackc/pgx/v5 with no observable change: same endpoints, same wire format, same updated_at ordering rule. The schema now comes from numbered SQL embedded in the binary and applied on startup, one transaction each, recorded in schema_migrations. That replaces two pieces of SQLite-era machinery, both deleted rather than ported: the column probing (Postgres has ADD COLUMN IF NOT EXISTS, and there is no legacy database left to probe) and the Asura key rewrite, which has run clean on every start for months now that the userscripts strip build hashes before writing. Its regexp survives as latest.asuraBuildHash, where the poller still needs it to scope chapter links to a series whose slug carries a rotating hash. Types get real: favorite is a boolean, chapter numbers double precision, timestamps stay unix-ms bigint. SQLite's null-safe IS NOT becomes IS DISTINCT FROM, which is what implements the rule that only reading progress reorders a list. Inside COALESCE/NULLIF the status and kind parameters need an explicit ::text -- there is no target column to infer from and Postgres refuses to guess. Tests lose their free t.TempDir() database, so Docker is now a hard prerequisite for `go test ./...`: internal/pgtest starts one postgres:17-alpine per test binary and hands each test a database of its own. Also lands CONTEXT.md and the four ADRs written while scoping #18. BREAKING CHANGE: DB_PATH is retired for DATABASE_URL, which is required and has no default. Compose gains a postgres service on an internal network with its own volume; POSTGRES_PASSWORD joins .env. The old bookmarks-data volume is deliberately left undeclared so `docker compose down -v` cannot take the pre-migration database with it. main is not deployable until #25 and #26 land. Closes #20 Co-authored-by: Sulthan Zaki <sultankiki05@gmail.com> Co-committed-by: Sulthan Zaki <sultankiki05@gmail.com>
29 lines
1.3 KiB
SQL
29 lines
1.3 KiB
SQL
-- One row per tracked series, keyed "<site>:<series_id>".
|
|
--
|
|
-- Everything is NOT NULL with a default except latest_chapter_num, where NULL
|
|
-- is a distinct state: nothing has been captured yet, which is not the same as
|
|
-- chapter zero.
|
|
--
|
|
-- Timestamps are unix milliseconds as bigint, not timestamptz: the userscripts
|
|
-- send Date.now() over the wire and the ordering rule compares them directly.
|
|
CREATE TABLE bookmarks (
|
|
key text PRIMARY KEY,
|
|
site text NOT NULL,
|
|
series_id text NOT NULL,
|
|
title text NOT NULL DEFAULT '',
|
|
series_url text NOT NULL DEFAULT '',
|
|
cover text NOT NULL DEFAULT '',
|
|
last_chapter text NOT NULL DEFAULT '',
|
|
last_chapter_num double precision NOT NULL DEFAULT 0,
|
|
last_chapter_url text NOT NULL DEFAULT '',
|
|
favorite boolean NOT NULL DEFAULT false,
|
|
latest_chapter text NOT NULL DEFAULT '',
|
|
latest_chapter_num double precision,
|
|
-- When the server last polled this series, unix ms; 0 means never, and sorts
|
|
-- first so a new bookmark is picked up on the next tick with no special case.
|
|
latest_checked_at bigint NOT NULL DEFAULT 0,
|
|
status text NOT NULL DEFAULT 'reading',
|
|
kind text NOT NULL DEFAULT 'manga',
|
|
updated_at bigint NOT NULL
|
|
);
|