31 lines
880 B
SQL
31 lines
880 B
SQL
CREATE TABLE users (
|
|
id SERIAL PRIMARY KEY,
|
|
uid VARCHAR UNIQUE NOT NULL, -- username as unique identifier
|
|
email VARCHAR UNIQUE,
|
|
full_name VARCHAR,
|
|
displayname VARCHAR,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE sessions (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INTEGER NOT NULL,
|
|
title VARCHAR,
|
|
token VARCHAR NOT NULL UNIQUE,
|
|
password VARCHAR,
|
|
last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
expires TIMESTAMP,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
|
);
|
|
|
|
CREATE TABLE session_ips (
|
|
id SERIAL PRIMARY KEY,
|
|
session_id INTEGER NOT NULL,
|
|
ip_address INET NOT NULL,
|
|
access_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (session_id) REFERENCES sessions (id)
|
|
);
|
|
|