From 8d70236ef5f2b60e68dc77911750e715762942f0 Mon Sep 17 00:00:00 2001 From: Thomas Stallinger Date: Sun, 12 Jul 2026 14:33:31 +0200 Subject: [PATCH] feat: add PostgreSQL persistence foundation --- migrations/0001_initial_schema.sql | 68 ++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 69 insertions(+) create mode 100644 migrations/0001_initial_schema.sql diff --git a/migrations/0001_initial_schema.sql b/migrations/0001_initial_schema.sql new file mode 100644 index 0000000..2ce2746 --- /dev/null +++ b/migrations/0001_initial_schema.sql @@ -0,0 +1,68 @@ +BEGIN; + +CREATE TABLE organizations ( + id UUID PRIMARY KEY, + name TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE devices ( + id UUID PRIMARY KEY, + organization_id UUID NOT NULL + REFERENCES organizations(id) + ON DELETE RESTRICT, + device_fingerprint TEXT NOT NULL UNIQUE, + hostname TEXT, + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_seen TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE hardware_snapshots ( + id UUID PRIMARY KEY, + device_id UUID NOT NULL + REFERENCES devices(id) + ON DELETE CASCADE, + collected_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + architecture TEXT NOT NULL, + manufacturer TEXT, + product_name TEXT, + product_version TEXT, + system_uuid TEXT, + system_serial TEXT, + board_vendor TEXT, + board_name TEXT, + board_serial TEXT, + bios_vendor TEXT, + bios_version TEXT, + boot_mode TEXT, + secure_boot TEXT, + tpm_version TEXT, + cpu_model TEXT, + cpu_logical_count INTEGER, + memory_bytes BIGINT +); + +CREATE TABLE network_interfaces ( + id UUID PRIMARY KEY, + hardware_snapshot_id UUID NOT NULL + REFERENCES hardware_snapshots(id) + ON DELETE CASCADE, + name TEXT NOT NULL, + type TEXT NOT NULL, + mac_address TEXT NOT NULL +); + +CREATE TABLE storage_devices ( + id UUID PRIMARY KEY, + hardware_snapshot_id UUID NOT NULL + REFERENCES hardware_snapshots(id) + ON DELETE CASCADE, + name TEXT NOT NULL, + model TEXT, + serial TEXT, + size_bytes BIGINT NOT NULL, + transport TEXT +); + +COMMIT; diff --git a/requirements.txt b/requirements.txt index 185360b..051c487 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ starlette==1.3.1 typing-inspection==0.4.2 typing_extensions==4.15.0 uvicorn==0.49.0 +psycopg[binary]==3.3.4