pg_v_man/assets/db/01_init.sql
2025-02-14 08:44:34 +01:00

59 lines
1.2 KiB
SQL

CREATE PUBLICATION v_man_1 FOR ALL TABLES;
create extension pgcrypto;
create table users (
id bigint primary key generated always as identity,
username text not null unique,
email text not null unique,
password_hash text not null
);
create table categories (
id bigint primary key generated always as identity,
name text not null unique
);
create table lists (
id bigint primary key generated always as identity,
user_id bigint not null references users (id),
name text not null
);
create table tasks (
id bigint primary key generated always as identity,
list_id bigint not null references lists (id),
category_id bigint references categories (id),
title text not null,
description text,
due_date date,
priority int,
completed boolean default false
);
INSERT INTO
users (username, email, password_hash)
VALUES
(
'ted.tester',
'ted.tester@example.com',
crypt ('password', gen_salt ('bf'))
);
INSERT INTO
categories (name)
VALUES
('Groceries'),
('Work'),
('Personal'),
('Other');
INSERT INTO
public.lists (user_id, name)
VALUES
(1, 'Groceries');
INSERT INTO
public.tasks (list_id, category_id, title)
VALUES
(1, 1, 'Orange Juice');