1
Fork 0
blog-zig-postgres/schema.sql
Leonardo Devai 0735e62a4c Harmonize the blog engine contract across all eight backends
published_at is now the first-publish time (null for drafts, kept across edits
and unpublish/republish), slugs collide to -2/-3 and regenerate on retitle,
every error is {"error"} with 400/401/403/404/405/409 pinned, timestamps are
RFC 3339 UTC. GUIDELINES pins the contract; each backend passes the same 59-check
end-to-end script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01128fhuZbgivaSJvtMf4s1G
2026-09-27 21:25:37 +02:00

23 lines
966 B
SQL

create table if not exists users (
id bigint generated always as identity primary key,
email text not null unique,
password_hash text not null,
created_at timestamptz not null default now()
);
create table if not exists posts (
id bigint generated always as identity primary key,
title text not null,
slug text not null unique,
body text not null,
published boolean not null default false,
author_id bigint not null references users (id) on delete cascade,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
-- When the post was first published, null while a draft. add column if not
-- exists also upgrades databases created before the column existed.
alter table posts add column if not exists published_at timestamptz;
create index if not exists posts_published_at_recent on posts (published_at desc) where published;