mabel/migrations/20230628223219_create-base.up.sql
Hamcha 81134dc0dd
Some checks failed
continuous-integration/drone/push Build is failing
add cursor and move to uuidv7
2023-07-13 17:43:05 +02:00

47 lines
1.2 KiB
SQL

CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- noqa: RF05
CREATE TABLE users (
id UUID PRIMARY KEY,
name VARCHAR UNIQUE NOT NULL,
email VARCHAR,
password VARCHAR,
display_name VARCHAR,
bio TEXT,
roles UUID [] NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now(),
modified_at TIMESTAMP,
deleted_at TIMESTAMP
);
CREATE TABLE sites (
id UUID PRIMARY KEY,
owner UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
name VARCHAR UNIQUE NOT NULL,
title VARCHAR NOT NULL,
description TEXT,
created_at TIMESTAMP NOT NULL DEFAULT now(),
modified_at TIMESTAMP,
deleted_at TIMESTAMP
);
CREATE TABLE pages (
id UUID PRIMARY KEY,
site UUID NOT NULL REFERENCES sites (id) ON DELETE CASCADE,
author UUID REFERENCES users (id) ON DELETE SET NULL,
slug VARCHAR NOT NULL,
title VARCHAR NOT NULL,
description TEXT,
tags VARCHAR [] NOT NULL,
blocks JSONB NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now(),
modified_at TIMESTAMP,
deleted_at TIMESTAMP
);
CREATE TABLE audit (
actor UUID REFERENCES users (id) ON DELETE SET NULL,
object UUID,
action VARCHAR NOT NULL,
data JSONB,
created_at TIMESTAMP
);