2024-04-09 04:25:36 +00:00
|
|
|
-- +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,
|
2024-11-23 03:50:18 +00:00
|
|
|
code INTEGER REFERENCES lock_code_slots(id),
|
|
|
|
issued_code INTEGER REFERENCES issued_codes(id)
|
2024-04-09 04:25:36 +00:00
|
|
|
);
|
2024-04-24 00:34:57 +00:00
|
|
|
|
2024-11-23 03:50:18 +00:00
|
|
|
CREATE TABLE issued_codes (
|
2024-04-24 00:34:57 +00:00
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
name TEXT,
|
|
|
|
code TEXT UNIQUE NOT NULL,
|
|
|
|
start DATETIME,
|
|
|
|
end DATETIME
|
|
|
|
);
|
|
|
|
|
2024-11-23 03:50:18 +00:00
|
|
|
CREATE TABLE issued_code_slots (
|
|
|
|
issued_code REFERENCES issued_codes(id),
|
2024-04-24 00:34:57 +00:00
|
|
|
lock REFERENCES locks(id),
|
|
|
|
slot REFERENCES lock_code_slots(id),
|
|
|
|
|
2024-11-23 03:50:18 +00:00
|
|
|
UNIQUE (issued_code, lock)
|
2024-04-24 00:34:57 +00:00
|
|
|
);
|
2024-04-09 04:25:36 +00:00
|
|
|
-- +goose StatementEnd
|
|
|
|
|
|
|
|
-- +goose Down
|
|
|
|
-- +goose StatementBegin
|
2024-11-23 03:50:18 +00:00
|
|
|
DROP TABLE issued_code_slots;
|
|
|
|
DROP TABLE issued_codes;
|
2024-04-09 04:25:36 +00:00
|
|
|
DROP TABLE lock_log;
|
|
|
|
DROP TABLE lock_code_slots;
|
|
|
|
DROP TABLE locks;
|
|
|
|
-- +goose StatementEnd
|