lockserver/db/migrations/1_init.sql
Finn 054008eb1f Initial commit
Connects to zwave-js, syncs all locks and codeslots with database, and records an event log. No support for updating code slots.
2024-04-08 21:25:36 -07:00

35 lines
798 B
SQL

-- +goose Up
-- +goose StatementBegin
PRAGMA foreign_keys = ON;
CREATE TABLE locks (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
zwave_device_id INTEGER NOT NULL UNIQUE
);
CREATE TABLE lock_code_slots (
id INTEGER PRIMARY KEY,
lock INTEGER NOT NULL REFERENCES locks(id),
code TEXT NOT NULL,
slot INTEGER NOT NULL,
name TEXT NOT NULL,
enabled BOOLEAN NOT NULL DEFAULT 0,
UNIQUE (lock, slot)
);
CREATE TABLE lock_log (
lock INTEGER NOT NULL REFERENCES locks(id),
timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
state TEXT NOT NULL,
code INTEGER REFERENCES lock_code_slots(id)
);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE lock_log;
DROP TABLE lock_code_slots;
DROP TABLE locks;
-- +goose StatementEnd