survey/migrations/20211011041634_survey_admins.sql

40 lines
1.3 KiB
MySQL
Raw Normal View History

2021-10-11 09:56:15 +05:30
-- Add migration script here
CREATE TABLE IF NOT EXISTS survey_admins (
name VARCHAR(100) NOT NULL UNIQUE,
email VARCHAR(100) UNIQUE DEFAULT NULL,
email_verified BOOLEAN DEFAULT NULL,
secret varchar(50) NOT NULL UNIQUE,
password TEXT NOT NULL,
ID SERIAL PRIMARY KEY NOT NULL
);
2021-10-11 13:41:36 +05:30
CREATE TABLE IF NOT EXISTS survey_campaigns (
2021-10-11 09:56:15 +05:30
ID UUID PRIMARY KEY NOT NULL UNIQUE,
user_id INTEGER NOT NULL references survey_admins(ID) ON DELETE CASCADE,
name VARCHAR(200) NOT NULL,
difficulties INTEGER[] NOT NULL,
created_at TIMESTAMPTZ NOT NULL
2021-10-11 13:41:36 +05:30
);
CREATE TABLE IF NOT EXISTS survey_responses (
user_id UUID NOT NULL references survey_users(ID) ON DELETE CASCADE,
campaign_id UUID NOT NULL references survey_campaigns(ID) ON DELETE CASCADE,
device_user_provided VARCHAR(400) NOT NULL,
device_software_recognised VARCHAR(400) NOT NULL,
ID SERIAL PRIMARY KEY NOT NULL,
threads INTEGER
);
CREATE TABLE IF NOT EXISTS survey_benches (
resp_id INTEGER NOT NULL references survey_responses(ID) ON DELETE CASCADE,
difficulty INTEGER NOT NULL,
duration FLOAT(8) NOT NULL
);
CREATE TABLE IF NOT EXISTS survey_response_tokens (
resp_id INTEGER NOT NULL references survey_responses(ID) ON DELETE CASCADE,
user_id UUID NOT NULL references survey_users(ID) ON DELETE CASCADE,
ID UUID PRIMARY KEY NOT NULL UNIQUE
);