32 lines
1020 B
SQL
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)
|
|
);
|
|
|