Files
story/migrations/000063_ble_binding.up.sql
Codex Local bf1233d5df
ci / verify (push) Canceled after 0s
feat: expand companion platform, device controls, and memoir workflows
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
2026-10-08 10:06:44 +08:00

23 lines
1.0 KiB
PL/PgSQL

BEGIN;
CREATE TABLE device_ble_binding (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
token_hash char(64) NOT NULL UNIQUE,
device_id uuid NOT NULL,
tenant_id uuid NOT NULL,
user_id uuid NOT NULL REFERENCES user_account(id),
household_id uuid NOT NULL,
subject_id uuid NOT NULL,
expected_generation bigint NOT NULL,
status text NOT NULL DEFAULT 'PENDING' CHECK(status IN ('PENDING','COMMITTED','CANCELLED')),
expires_at timestamptz NOT NULL,
binding_id uuid REFERENCES device_binding(id),
created_at timestamptz NOT NULL DEFAULT now(),
completed_at timestamptz,
FOREIGN KEY(device_id,tenant_id) REFERENCES device(id,tenant_id),
FOREIGN KEY(household_id,tenant_id) REFERENCES household(id,tenant_id),
FOREIGN KEY(subject_id,tenant_id) REFERENCES subject_profile(id,tenant_id)
);
CREATE INDEX device_ble_binding_device ON device_ble_binding(device_id,created_at DESC);
CREATE UNIQUE INDEX device_ble_binding_one_pending_actor ON device_ble_binding(device_id,user_id) WHERE status='PENDING';
COMMIT;