Files
logbuch/drizzle/0002_glamorous_wild_child.sql
T
Matthias Giesselmann b90ff252d1 Add Logbuch: project update blog with admin, media and API
Public archive with sidebar navigation, project pages, month archive,
search and entry pages with image blocks. Admin area for brands,
projects, post types, users, api clients, media and the entry editor
with drag and drop images, preview per audience, scheduling and
publish checks. Read and write API with bearer tokens, audience
scoping, idempotent creation, OpenAPI document and editorial guide.
Magic link login with configurable allowed domains, whole app behind
the session gate. 456 tests including design rule checks.
2026-07-31 21:33:42 +02:00

28 lines
1.7 KiB
SQL

CREATE TYPE "public"."client_mode" AS ENUM('read', 'write');--> statement-breakpoint
CREATE TYPE "public"."client_scope" AS ENUM('internal', 'customer', 'public');--> statement-breakpoint
CREATE TABLE "api_client" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" text NOT NULL,
"token_hash" text NOT NULL,
"mode" "client_mode" DEFAULT 'read' NOT NULL,
"scope" "client_scope" DEFAULT 'customer' NOT NULL,
"project_id" uuid,
"can_publish" boolean DEFAULT false NOT NULL,
"last_used_at" timestamp with time zone,
"revoked_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "api_client_token_hash_unique" UNIQUE("token_hash")
);
--> statement-breakpoint
CREATE TABLE "post_read" (
"post_id" uuid NOT NULL,
"project_id" uuid NOT NULL,
"external_user_id" text NOT NULL,
"read_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "post_read_post_id_external_user_id_pk" PRIMARY KEY("post_id","external_user_id")
);
--> statement-breakpoint
ALTER TABLE "api_client" ADD CONSTRAINT "api_client_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "post_read" ADD CONSTRAINT "post_read_post_id_post_id_fk" FOREIGN KEY ("post_id") REFERENCES "public"."post"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "post_read" ADD CONSTRAINT "post_read_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "post_read_project_user" ON "post_read" USING btree ("project_id","external_user_id");