tijl.dev-core/migrations/00000001_init.up.sql

32 lines
1020 B
MySQL
Raw Normal View History

2024-08-21 01:08:47 +02:00
CREATE TABLE users (
id SERIAL PRIMARY KEY,
uid VARCHAR UNIQUE NOT NULL, -- username as unique identifier
2024-08-21 17:31:03 +02:00
email VARCHAR NOT NULL,
email_verified BOOLEAN NOT NULL,
full_name VARCHAR NOT NULL,
username VARCHAR NOT NULL,
2024-08-21 01:08:47 +02:00
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
2024-08-21 17:31:03 +02:00
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
2024-08-21 01:08:47 +02:00
);
CREATE TABLE sessions (
id SERIAL PRIMARY KEY,
2024-08-21 17:31:03 +02:00
uid VARCHAR NOT NULL,
token VARCHAR NOT NULL UNIQUE NOT NULL,
2024-08-21 01:08:47 +02:00
expires TIMESTAMP,
2024-08-21 17:31:03 +02:00
last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
2024-08-21 01:08:47 +02:00
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
2024-08-21 17:31:03 +02:00
FOREIGN KEY (uid) REFERENCES users (uid)
2024-08-21 01:08:47 +02:00
);
CREATE TABLE session_ips (
id SERIAL PRIMARY KEY,
session_id INTEGER NOT NULL,
2024-08-21 17:31:03 +02:00
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)
2024-08-21 01:08:47 +02:00
);