femto-backend/Femto.Database/Migrations/20250425121459_Init.sql
2025-05-15 17:47:20 +02:00

63 lines
No EOL
1.5 KiB
SQL

-- Migration: Init
-- Created at: 25/04/2025 12:14:59
CREATE SCHEMA blog;
CREATE TABLE blog.author
(
id uuid PRIMARY KEY,
username varchar(64) UNIQUE NOT NULL
);
CREATE TABLE blog.post
(
id uuid PRIMARY KEY,
content text NOT NULL,
posted_on timestamptz NOT NULL DEFAULT now(),
author_id uuid NOT NULL REFERENCES blog.author (id) on DELETE CASCADE
);
CREATE TABLE blog.post_media
(
id uuid PRIMARY KEY,
post_id uuid NOT NULL REFERENCES blog.post (id) ON DELETE CASCADE,
url text NOT NULL,
type varchar(64),
width int,
height int,
ordering int NOT NULL
);
CREATE TYPE outbox_status AS ENUM ('pending', 'completed', 'failed');
CREATE TABLE blog.outbox
(
id uuid PRIMARY KEY,
event_type text NOT NULL,
aggregate_id uuid NOT NULL,
payload jsonb NOT NULL,
created_at timestamp DEFAULT now() NOT NULL,
processed_at timestamp,
next_retry_at timestamp,
retry_count int DEFAULT 0 NOT NULL,
last_error text,
status outbox_status DEFAULT 'pending' NOT NULL
);
CREATE SCHEMA media;
CREATE TABLE media.saved_blob
(
id uuid PRIMARY KEY,
uploaded_on timestamp DEFAULT now() NOT NULL,
type varchar(64) NOT NULL,
size int
);
CREATE SCHEMA authn;
CREATE TABLE authn.user_identity
(
);