critch/migrations/20241113160730_critch.sql

48 lines
1.4 KiB
MySQL
Raw Normal View History

2024-11-13 20:00:15 +00:00
create extension if not exists "uuid-ossp";
create table artists (
id integer primary key generated always as identity,
2024-11-14 17:59:21 +00:00
handle varchar(128) not null unique,
name varchar(128),
2024-11-13 20:00:15 +00:00
bio text,
site varchar(256)
);
create table artworks (
id integer primary key generated always as identity,
title varchar(256),
description text,
url_source varchar(256),
2024-11-14 17:59:21 +00:00
created_at timestamp not null default current_timestamp,
2024-11-13 20:00:15 +00:00
artist_id integer not null,
comment_number integer not null default 0,
foreign key (artist_id) references artists(id)
);
create table comments (
id integer unique not null,
text text not null,
2024-11-14 17:59:21 +00:00
artwork_id integer not null,
created_at timestamp not null default current_timestamp,
primary key (id, artwork_id),
foreign key (artwork_id) references artworks(id)
2024-11-13 20:00:15 +00:00
);
create table comment_relations (
2024-11-14 17:59:21 +00:00
artwork_id integer,
foreign key (artwork_id) references artworks(id),
2024-11-13 20:00:15 +00:00
in_reply_to_id integer,
foreign key (in_reply_to_id) references comments(id),
comment_id integer,
foreign key (comment_id) references comments(id),
2024-11-14 17:59:21 +00:00
primary key (artwork_id, in_reply_to_id, comment_id)
2024-11-13 20:00:15 +00:00
);
2024-11-14 17:59:21 +00:00
create table artwork_files (
2024-11-13 20:00:15 +00:00
id uuid primary key default gen_random_uuid(),
alt_text text,
2024-11-14 17:59:21 +00:00
extension varchar(16),
2024-11-13 20:00:15 +00:00
artwork_id integer,
foreign key (artwork_id) references artworks(id)
);