tijl.dev-core/migrations/00000001_init.up.sql
tijl 3732fb2fa4
Some checks failed
build / build (push) Failing after 0s
database + auth
2024-08-21 17:31:03 +02:00

32 lines
1020 B
SQL

CREATE TABLE users (
id SERIAL PRIMARY KEY,
uid VARCHAR UNIQUE NOT NULL, -- username as unique identifier
email VARCHAR NOT NULL,
email_verified BOOLEAN NOT NULL,
full_name VARCHAR NOT NULL,
username VARCHAR NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE TABLE sessions (
id SERIAL PRIMARY KEY,
uid VARCHAR NOT NULL,
token VARCHAR NOT NULL UNIQUE NOT NULL,
expires TIMESTAMP,
last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
FOREIGN KEY (uid) REFERENCES users (uid)
);
CREATE TABLE session_ips (
id SERIAL PRIMARY KEY,
session_id INTEGER NOT NULL,
ip_address VARCHAR NOT NULL,
agent VARCHAR NOT NULL,
access_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
FOREIGN KEY (session_id) REFERENCES sessions (id),
CONSTRAINT session_ips_unique UNIQUE (session_id, ip_address)
);