critch/migrations/20241113160730_critch.sql

48 lines
1.4 KiB
MySQL
Raw Permalink Normal View History

2024-11-13 20:00:15 +00:00
create extension if not exists "uuid-ossp";
create table artists (
2024-11-14 21:43:54 +00:00
artist_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 (
2024-11-14 21:43:54 +00:00
artwork_id integer primary key generated always as identity,
2024-11-13 20:00:15 +00:00
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,
2024-11-14 21:43:54 +00:00
foreign key (artist_id) references artists(artist_id)
2024-11-13 20:00:15 +00:00
);
create table comments (
2024-11-14 21:43:54 +00:00
comment_id integer unique not null,
2024-11-13 20:00:15 +00:00
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,
2024-11-14 21:43:54 +00:00
primary key (comment_id, artwork_id),
foreign key (artwork_id) references artworks(artwork_id)
2024-11-13 20:00:15 +00:00
);
create table comment_relations (
2024-11-14 17:59:21 +00:00
artwork_id integer,
2024-11-14 21:43:54 +00:00
foreign key (artwork_id) references artworks(artwork_id),
2024-11-13 20:00:15 +00:00
in_reply_to_id integer,
2024-11-14 21:43:54 +00:00
foreign key (in_reply_to_id) references comments(comment_id),
2024-11-13 20:00:15 +00:00
comment_id integer,
2024-11-14 21:43:54 +00:00
foreign key (comment_id) references comments(comment_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-14 21:43:54 +00:00
file_id uuid primary key default gen_random_uuid(),
2024-11-13 20:00:15 +00:00
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,
2024-11-14 21:43:54 +00:00
foreign key (artwork_id) references artworks(artwork_id)
2024-11-13 20:00:15 +00:00
);