This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
rust-web/migrations/0_init_schema.sql
2024-06-02 18:08:22 -07:00

29 lines
724 B
SQL

-- Create questions table
CREATE TABLE IF NOT EXISTS questions (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL
);
-- Create tags table
CREATE TABLE IF NOT EXISTS tags (
id SERIAL PRIMARY KEY,
label TEXT UNIQUE NOT NULL
);
-- Create question_tag table
CREATE TABLE IF NOT EXISTS question_tag (
question_id INT REFERENCES questions(id),
tag_id INT REFERENCES tags(id),
PRIMARY KEY (question_id, tag_id),
FOREIGN KEY (question_id) REFERENCES questions(id),
FOREIGN KEY (tag_id) REFERENCES tags(id)
);
-- Create answers table
CREATE TABLE IF NOT EXISTS answers (
id SERIAL PRIMARY KEY,
question_id INT REFERENCES questions(id),
content TEXT NOT NULL
);