GeneIT/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql

31 lines
924 B
SQL

-- Create tables
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(30) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR NULL,
time_create BIGINT NOT NULL,
reset_password_token VARCHAR(150) NULL,
time_gen_reset_token BIGINT NOT NULL DEFAULT 0,
delete_account_token VARCHAR(150) NULL,
time_gen_delete_account_token BIGINT NOT NULL DEFAULT 0,
time_activate BIGINT NOT NULL DEFAULT 0,
active BOOLEAN NOT NULL DEFAULT TRUE,
admin BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE families (
id SERIAL PRIMARY KEY,
time_create BIGINT NOT NULL,
name VARCHAR(30) NOT NULL,
invitation_code VARCHAR(7) NOT NULL
);
CREATE TABLE memberships (
user_id integer NOT NULL REFERENCES users,
family_id integer NOT NULL REFERENCES families,
time_create BIGINT NOT NULL,
is_admin BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY(user_id, family_id)
);