first commit

This commit is contained in:
2026-02-22 00:15:25 +07:00
commit 39fc9e9e3f
25 changed files with 2116 additions and 0 deletions
@@ -0,0 +1,7 @@
BEGIN;
DROP INDEX IF EXISTS idx_refresh_tokens_user_id;
DROP TABLE IF EXISTS refresh_tokens;
DROP TABLE IF EXISTS users;
COMMIT;
@@ -0,0 +1,23 @@
BEGIN;
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE refresh_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
token TEXT NOT NULL UNIQUE,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_refresh_tokens_user_id ON refresh_tokens(user_id);
COMMIT;
@@ -0,0 +1,11 @@
BEGIN;
DROP INDEX IF EXISTS idx_question_options_question;
DROP INDEX IF EXISTS idx_questions_form_id;
DROP INDEX IF EXISTS idx_forms_user_id;
DROP TABLE IF EXISTS question_options;
DROP TABLE IF EXISTS questions;
DROP TABLE IF EXISTS forms;
DROP TYPE IF EXISTS question_type;
COMMIT;
@@ -0,0 +1,47 @@
BEGIN;
CREATE TYPE question_type AS ENUM (
'short_text',
'long_text',
'multiple_choice',
'checkbox',
'dropdown',
'date',
'rating'
);
CREATE TABLE forms (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title TEXT NOT NULL,
description TEXT,
response_count INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE questions (
id UUID NOT NULL DEFAULT gen_random_uuid(),
form_id UUID NOT NULL REFERENCES forms(id) ON DELETE CASCADE,
type question_type NOT NULL,
title TEXT NOT NULL,
required BOOLEAN NOT NULL DEFAULT false,
position INTEGER NOT NULL,
PRIMARY KEY (form_id, id)
);
CREATE TABLE question_options (
id SERIAL PRIMARY KEY,
form_id UUID NOT NULL,
question_id UUID NOT NULL,
label TEXT NOT NULL,
position INTEGER NOT NULL,
FOREIGN KEY (form_id, question_id)
REFERENCES questions(form_id, id) ON DELETE CASCADE
);
CREATE INDEX idx_forms_user_id ON forms(user_id);
CREATE INDEX idx_questions_form_id ON questions(form_id);
CREATE INDEX idx_question_options_question ON question_options(form_id, question_id);
COMMIT;