Files
HamHam/migrations/0001_initial.sql
T

15 lines
1.2 KiB
SQL

CREATE TABLE recipes (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), title text NOT NULL,
title_key text NOT NULL UNIQUE, published boolean NOT NULL DEFAULT false,
data jsonb NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX recipes_published_created ON recipes (published, created_at DESC);
CREATE INDEX recipes_data ON recipes USING gin (data);
CREATE TABLE admins (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), username text NOT NULL UNIQUE, password text NOT NULL);
CREATE TABLE sessions (token text PRIMARY KEY, admin_id uuid NOT NULL REFERENCES admins(id) ON DELETE CASCADE, expires timestamptz NOT NULL);
CREATE INDEX sessions_expires ON sessions (expires);
CREATE TABLE login_limits (key text PRIMARY KEY, count integer NOT NULL, reset timestamptz NOT NULL);
CREATE TABLE settings (key text PRIMARY KEY, value jsonb NOT NULL);
INSERT INTO settings VALUES ('categories', '["Alltagsküche", "Vegetarisch", "Für Gäste", "Süßes"]'), ('tags', '["Schnell", "Familienliebling", "Meal Prep"]'), ('household', '"Unsere Küche"');
CREATE TABLE media (name text PRIMARY KEY, created_at timestamptz NOT NULL DEFAULT now());