Templates/Operations & logistics
IoT telemetry database schema
Devices with sensors streaming readings, thresholds and alerts.
6 tables, 5 relationships
Opens as a new diagram you can change. Free.
Tables
device_types
- iduuid not null
- nametext not null
- firmware_versiontext not null
- created_attimestamptz not null
devices
- iduuid not null
- device_type_id> device_typesuuid not null
- serialtext not null
- locationtext
- last_seen_attimestamptz
- created_attimestamptz not null
sensors
- iduuid not null
- device_id> devicesuuid not null
- metrictext not null
- unittext not null
- created_attimestamptz not null
readings
- iduuid not null
- sensor_id> sensorsuuid not null
- valuefloat8 not null
- recorded_attimestamptz not null
- created_attimestamptz not null
thresholds
- iduuid not null
- sensor_id> sensorsuuid not null
- min_valuefloat8
- max_valuefloat8
- created_attimestamptz not null
alerts
- iduuid not null
- sensor_id> sensorsuuid not null
- messagetext not null
- acknowledged_attimestamptz
- created_attimestamptz not null
As PostgreSQL
The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.
CREATE TABLE "alerts" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"sensor_id" UUID NOT NULL,
"message" TEXT NOT NULL,
"acknowledged_at" TIMESTAMPTZ,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "device_types" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"name" TEXT NOT NULL,
"firmware_version" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "devices" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"device_type_id" UUID NOT NULL,
"serial" TEXT NOT NULL UNIQUE,
"location" TEXT,
"last_seen_at" TIMESTAMPTZ,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "readings" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"sensor_id" UUID NOT NULL,
"value" FLOAT8 NOT NULL,
"recorded_at" TIMESTAMPTZ NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "sensors" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"device_id" UUID NOT NULL,
"metric" TEXT NOT NULL,
"unit" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "thresholds" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"sensor_id" UUID NOT NULL,
"min_value" FLOAT8,
"max_value" FLOAT8,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "devices" ADD CONSTRAINT "fk_devices_device_type_id" FOREIGN KEY ("device_type_id") REFERENCES "device_types" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "sensors" ADD CONSTRAINT "fk_sensors_device_id" FOREIGN KEY ("device_id") REFERENCES "devices" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "readings" ADD CONSTRAINT "fk_readings_sensor_id" FOREIGN KEY ("sensor_id") REFERENCES "sensors" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "thresholds" ADD CONSTRAINT "fk_thresholds_sensor_id" FOREIGN KEY ("sensor_id") REFERENCES "sensors" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "alerts" ADD CONSTRAINT "fk_alerts_sensor_id" FOREIGN KEY ("sensor_id") REFERENCES "sensors" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;More Operations & logistics templates
- Fleet managementVehicles and drivers, trips, maintenance records and fuel logs.
- Shipping & trackingShipments of packages between addresses, carriers and tracking events.
- ManufacturingProducts with bills of materials, work orders routed through machine operations.
- Field serviceCustomer sites, jobs dispatched to technicians, visits and parts used.
- IT asset managementHardware and licences assigned to employees, with a maintenance history.
- Ride hailingRiders request trips, drivers with vehicles accept, then payments and ratings.
- ParkingCar parks with spaces, permits for vehicles and paid parking sessions.
- Construction projectsProjects on sites, contractors, tasks, change orders and inspections.
- Farm managementFields planted with crops, harvests, equipment and livestock.
- Sensor readings (Cassandra)Time series per device and day, newest first, with the latest reading kept in a table of its own.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.