books: regenerate migration as 20261024013208_books after money_bank_balance (old 010449/010518 would sort before the applied 011919 and be skipped)
Some checks failed
Deploy production / deploy (push) Failing after 27s
Some checks failed
Deploy production / deploy (push) Failing after 27s
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,43 +0,0 @@
|
|||||||
CREATE TYPE "books"."reading_status" AS ENUM('want_to_read', 'reading', 'finished', 'abandoned');--> statement-breakpoint
|
|
||||||
CREATE TABLE "books"."sessions" (
|
|
||||||
"id" serial PRIMARY KEY,
|
|
||||||
"work_id" integer NOT NULL,
|
|
||||||
"file_id" integer,
|
|
||||||
"started_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
||||||
"ended_at" timestamp with time zone,
|
|
||||||
"start_percent" real,
|
|
||||||
"end_percent" real,
|
|
||||||
"start_page" integer,
|
|
||||||
"end_page" integer,
|
|
||||||
"pages_read" integer,
|
|
||||||
"source" text DEFAULT 'reader' NOT NULL,
|
|
||||||
"note" text,
|
|
||||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
||||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
||||||
CONSTRAINT "sessions_percent_check" CHECK (("start_percent" is null or "start_percent" between 0 and 100) and ("end_percent" is null or "end_percent" between 0 and 100)),
|
|
||||||
CONSTRAINT "sessions_end_check" CHECK ("ended_at" is null or "ended_at" >= "started_at")
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
ALTER TABLE "books"."progress" ADD COLUMN "status" "books"."reading_status" DEFAULT 'want_to_read'::"books"."reading_status" NOT NULL;--> statement-breakpoint
|
|
||||||
ALTER TABLE "books"."progress" ADD COLUMN "rating" smallint;--> statement-breakpoint
|
|
||||||
ALTER TABLE "books"."progress" ADD COLUMN "last_read_at" timestamp with time zone;--> statement-breakpoint
|
|
||||||
CREATE INDEX "progress_status_idx" ON "books"."progress" ("status");--> statement-breakpoint
|
|
||||||
CREATE INDEX "sessions_work_id_idx" ON "books"."sessions" ("work_id");--> statement-breakpoint
|
|
||||||
CREATE INDEX "sessions_started_at_idx" ON "books"."sessions" ("started_at");--> statement-breakpoint
|
|
||||||
ALTER TABLE "books"."sessions" ADD CONSTRAINT "sessions_work_id_works_id_fkey" FOREIGN KEY ("work_id") REFERENCES "books"."works"("id") ON DELETE CASCADE;--> statement-breakpoint
|
|
||||||
ALTER TABLE "books"."sessions" ADD CONSTRAINT "sessions_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "books"."files"("id") ON DELETE SET NULL;--> statement-breakpoint
|
|
||||||
ALTER TABLE "books"."progress" ADD CONSTRAINT "progress_rating_check" CHECK ("rating" is null or "rating" between 1 and 5);
|
|
||||||
--> statement-breakpoint
|
|
||||||
-- Hand-written: updated_at trigger and explicit grants (default privileges from the books migration cover new tables too).
|
|
||||||
CREATE TRIGGER touch_updated_at BEFORE UPDATE ON books.sessions FOR EACH ROW EXECUTE FUNCTION meta.touch_updated_at();
|
|
||||||
--> statement-breakpoint
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'personal_app') THEN
|
|
||||||
GRANT SELECT, INSERT, UPDATE, DELETE ON books.sessions TO personal_app;
|
|
||||||
GRANT USAGE, SELECT ON SEQUENCE books.sessions_id_seq TO personal_app;
|
|
||||||
END IF;
|
|
||||||
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'personal_ro') THEN
|
|
||||||
GRANT SELECT ON books.sessions TO personal_ro;
|
|
||||||
END IF;
|
|
||||||
END $$;
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
CREATE SCHEMA "books";
|
CREATE SCHEMA "books";
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
CREATE TYPE "books"."metadata_status" AS ENUM('pending', 'matched', 'low_confidence', 'not_found', 'manual');--> statement-breakpoint
|
CREATE TYPE "books"."metadata_status" AS ENUM('pending', 'matched', 'low_confidence', 'not_found', 'manual');--> statement-breakpoint
|
||||||
|
CREATE TYPE "books"."reading_status" AS ENUM('want_to_read', 'reading', 'finished', 'abandoned');--> statement-breakpoint
|
||||||
CREATE TABLE "books"."files" (
|
CREATE TABLE "books"."files" (
|
||||||
"id" serial PRIMARY KEY,
|
"id" serial PRIMARY KEY,
|
||||||
"work_id" integer NOT NULL,
|
"work_id" integer NOT NULL,
|
||||||
@@ -36,9 +37,32 @@ CREATE TABLE "books"."progress" (
|
|||||||
"percent" real DEFAULT 0 NOT NULL,
|
"percent" real DEFAULT 0 NOT NULL,
|
||||||
"started_at" timestamp with time zone,
|
"started_at" timestamp with time zone,
|
||||||
"finished_at" timestamp with time zone,
|
"finished_at" timestamp with time zone,
|
||||||
|
"status" "books"."reading_status" DEFAULT 'want_to_read'::"books"."reading_status" NOT NULL,
|
||||||
|
"rating" smallint,
|
||||||
|
"last_read_at" timestamp with time zone,
|
||||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
CONSTRAINT "progress_percent_check" CHECK ("percent" between 0 and 100)
|
CONSTRAINT "progress_percent_check" CHECK ("percent" between 0 and 100),
|
||||||
|
CONSTRAINT "progress_rating_check" CHECK ("rating" is null or "rating" between 1 and 5)
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "books"."sessions" (
|
||||||
|
"id" serial PRIMARY KEY,
|
||||||
|
"work_id" integer NOT NULL,
|
||||||
|
"file_id" integer,
|
||||||
|
"started_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"ended_at" timestamp with time zone,
|
||||||
|
"start_percent" real,
|
||||||
|
"end_percent" real,
|
||||||
|
"start_page" integer,
|
||||||
|
"end_page" integer,
|
||||||
|
"pages_read" integer,
|
||||||
|
"source" text DEFAULT 'reader' NOT NULL,
|
||||||
|
"note" text,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
CONSTRAINT "sessions_percent_check" CHECK (("start_percent" is null or "start_percent" between 0 and 100) and ("end_percent" is null or "end_percent" between 0 and 100)),
|
||||||
|
CONSTRAINT "sessions_end_check" CHECK ("ended_at" is null or "ended_at" >= "started_at")
|
||||||
);
|
);
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
CREATE TABLE "books"."shelf_works" (
|
CREATE TABLE "books"."shelf_works" (
|
||||||
@@ -92,6 +116,9 @@ CREATE UNIQUE INDEX "files_sha256_key" ON "books"."files" ("sha256");--> stateme
|
|||||||
CREATE INDEX "files_work_id_idx" ON "books"."files" ("work_id");--> statement-breakpoint
|
CREATE INDEX "files_work_id_idx" ON "books"."files" ("work_id");--> statement-breakpoint
|
||||||
CREATE INDEX "notes_work_id_idx" ON "books"."notes" ("work_id");--> statement-breakpoint
|
CREATE INDEX "notes_work_id_idx" ON "books"."notes" ("work_id");--> statement-breakpoint
|
||||||
CREATE UNIQUE INDEX "progress_work_id_key" ON "books"."progress" ("work_id");--> statement-breakpoint
|
CREATE UNIQUE INDEX "progress_work_id_key" ON "books"."progress" ("work_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "progress_status_idx" ON "books"."progress" ("status");--> statement-breakpoint
|
||||||
|
CREATE INDEX "sessions_work_id_idx" ON "books"."sessions" ("work_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "sessions_started_at_idx" ON "books"."sessions" ("started_at");--> statement-breakpoint
|
||||||
CREATE INDEX "shelf_works_work_id_idx" ON "books"."shelf_works" ("work_id");--> statement-breakpoint
|
CREATE INDEX "shelf_works_work_id_idx" ON "books"."shelf_works" ("work_id");--> statement-breakpoint
|
||||||
CREATE UNIQUE INDEX "shelves_slug_key" ON "books"."shelves" ("slug");--> statement-breakpoint
|
CREATE UNIQUE INDEX "shelves_slug_key" ON "books"."shelves" ("slug");--> statement-breakpoint
|
||||||
CREATE UNIQUE INDEX "works_isbn13_key" ON "books"."works" ("isbn13") WHERE "isbn13" is not null;--> statement-breakpoint
|
CREATE UNIQUE INDEX "works_isbn13_key" ON "books"."works" ("isbn13") WHERE "isbn13" is not null;--> statement-breakpoint
|
||||||
@@ -101,6 +128,8 @@ ALTER TABLE "books"."notes" ADD CONSTRAINT "notes_work_id_works_id_fkey" FOREIGN
|
|||||||
ALTER TABLE "books"."notes" ADD CONSTRAINT "notes_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "books"."files"("id") ON DELETE SET NULL;--> statement-breakpoint
|
ALTER TABLE "books"."notes" ADD CONSTRAINT "notes_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "books"."files"("id") ON DELETE SET NULL;--> statement-breakpoint
|
||||||
ALTER TABLE "books"."progress" ADD CONSTRAINT "progress_work_id_works_id_fkey" FOREIGN KEY ("work_id") REFERENCES "books"."works"("id") ON DELETE CASCADE;--> statement-breakpoint
|
ALTER TABLE "books"."progress" ADD CONSTRAINT "progress_work_id_works_id_fkey" FOREIGN KEY ("work_id") REFERENCES "books"."works"("id") ON DELETE CASCADE;--> statement-breakpoint
|
||||||
ALTER TABLE "books"."progress" ADD CONSTRAINT "progress_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "books"."files"("id") ON DELETE SET NULL;--> statement-breakpoint
|
ALTER TABLE "books"."progress" ADD CONSTRAINT "progress_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "books"."files"("id") ON DELETE SET NULL;--> statement-breakpoint
|
||||||
|
ALTER TABLE "books"."sessions" ADD CONSTRAINT "sessions_work_id_works_id_fkey" FOREIGN KEY ("work_id") REFERENCES "books"."works"("id") ON DELETE CASCADE;--> statement-breakpoint
|
||||||
|
ALTER TABLE "books"."sessions" ADD CONSTRAINT "sessions_file_id_files_id_fkey" FOREIGN KEY ("file_id") REFERENCES "books"."files"("id") ON DELETE SET NULL;--> statement-breakpoint
|
||||||
ALTER TABLE "books"."shelf_works" ADD CONSTRAINT "shelf_works_shelf_id_shelves_id_fkey" FOREIGN KEY ("shelf_id") REFERENCES "books"."shelves"("id") ON DELETE CASCADE;--> statement-breakpoint
|
ALTER TABLE "books"."shelf_works" ADD CONSTRAINT "shelf_works_shelf_id_shelves_id_fkey" FOREIGN KEY ("shelf_id") REFERENCES "books"."shelves"("id") ON DELETE CASCADE;--> statement-breakpoint
|
||||||
ALTER TABLE "books"."shelf_works" ADD CONSTRAINT "shelf_works_work_id_works_id_fkey" FOREIGN KEY ("work_id") REFERENCES "books"."works"("id") ON DELETE CASCADE;
|
ALTER TABLE "books"."shelf_works" ADD CONSTRAINT "shelf_works_work_id_works_id_fkey" FOREIGN KEY ("work_id") REFERENCES "books"."works"("id") ON DELETE CASCADE;
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
@@ -144,3 +173,18 @@ BEGIN
|
|||||||
PERFORM meta.sync();
|
PERFORM meta.sync();
|
||||||
END IF;
|
END IF;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
|
--> statement-breakpoint
|
||||||
|
-- Hand-written: updated_at trigger and explicit grants (default privileges from the books migration cover new tables too).
|
||||||
|
CREATE TRIGGER touch_updated_at BEFORE UPDATE ON books.sessions FOR EACH ROW EXECUTE FUNCTION meta.touch_updated_at();
|
||||||
|
--> statement-breakpoint
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'personal_app') THEN
|
||||||
|
GRANT SELECT, INSERT, UPDATE, DELETE ON books.sessions TO personal_app;
|
||||||
|
GRANT USAGE, SELECT ON SEQUENCE books.sessions_id_seq TO personal_app;
|
||||||
|
END IF;
|
||||||
|
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'personal_ro') THEN
|
||||||
|
GRANT SELECT ON books.sessions TO personal_ro;
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"version": "8",
|
"version": "8",
|
||||||
"dialect": "postgres",
|
"dialect": "postgres",
|
||||||
"id": "f239c655-63c8-4807-b44f-b7698330d30a",
|
"id": "b9c155ef-74b1-4481-acaa-7649155ee04f",
|
||||||
"prevIds": [
|
"prevIds": [
|
||||||
"ffad1d0e-51e0-4302-9ab2-022eba184390"
|
"46aa2cce-9f94-40c6-ae0d-1489f5164c74"
|
||||||
],
|
],
|
||||||
"ddl": [
|
"ddl": [
|
||||||
{
|
{
|
||||||
@@ -5265,6 +5265,45 @@
|
|||||||
"schema": "money",
|
"schema": "money",
|
||||||
"table": "accounts"
|
"table": "accounts"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"typeSchema": null,
|
||||||
|
"notNull": false,
|
||||||
|
"dimensions": 0,
|
||||||
|
"default": null,
|
||||||
|
"generated": null,
|
||||||
|
"identity": null,
|
||||||
|
"name": "bank_balance_cents",
|
||||||
|
"entityType": "columns",
|
||||||
|
"schema": "money",
|
||||||
|
"table": "accounts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"typeSchema": null,
|
||||||
|
"notNull": false,
|
||||||
|
"dimensions": 0,
|
||||||
|
"default": null,
|
||||||
|
"generated": null,
|
||||||
|
"identity": null,
|
||||||
|
"name": "bank_balance_type",
|
||||||
|
"entityType": "columns",
|
||||||
|
"schema": "money",
|
||||||
|
"table": "accounts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "timestamp with time zone",
|
||||||
|
"typeSchema": null,
|
||||||
|
"notNull": false,
|
||||||
|
"dimensions": 0,
|
||||||
|
"default": null,
|
||||||
|
"generated": null,
|
||||||
|
"identity": null,
|
||||||
|
"name": "bank_balance_at",
|
||||||
|
"entityType": "columns",
|
||||||
|
"schema": "money",
|
||||||
|
"table": "accounts"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "timestamp with time zone",
|
"type": "timestamp with time zone",
|
||||||
"typeSchema": null,
|
"typeSchema": null,
|
||||||
Reference in New Issue
Block a user