15 lines
782 B
SQL
15 lines
782 B
SQL
CREATE TABLE IF NOT EXISTS push_devices (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
session_id INTEGER NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
|
|
device_id UUID NOT NULL UNIQUE,
|
|
token TEXT NOT NULL UNIQUE CHECK (length(token) BETWEEN 20 AND 4096),
|
|
platform VARCHAR(16) NOT NULL CHECK (platform = 'android'),
|
|
app_version VARCHAR(32) NOT NULL DEFAULT '',
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
last_seen_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_push_devices_user ON push_devices(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_push_devices_session ON push_devices(session_id);
|