Templates/Operations & logistics

Sensor readings (Cassandra) database schema

Time series per device and day, newest first, with the latest reading kept in a table of its own.

3 tables, 0 references

Opens as a new diagram you can change. Free.

Tables

readings_by_device

One partition per device and day keeps partitions bounded.

  • device_iduuid not null
  • daydate not null
  • recorded_attimestamp not null
  • temperaturedouble
  • humiditydouble
  • batteryint

latest_reading_by_device

The last reading per device, overwritten on each write.

  • device_iduuid not null
  • recorded_attimestamp
  • temperaturedouble
  • humiditydouble

devices_by_site

Which devices a site has, for dashboards.

  • site_iduuid not null
  • device_iduuid not null
  • nametext
  • tagsset<text>

As CQL schema

The diagram also exports Sample rows (INSERT).

-- Sensor readings (Cassandra): Cassandra / ScyllaDB schema.

CREATE TABLE IF NOT EXISTS readings_by_device (
  device_id uuid,
  day date,
  recorded_at timestamp,
  temperature double,
  humidity double,
  battery int,
  PRIMARY KEY ((device_id, day), recorded_at)
) WITH CLUSTERING ORDER BY (recorded_at DESC)
  AND default_time_to_live = 7776000
  AND comment = 'One partition per device and day keeps partitions bounded.';

CREATE TABLE IF NOT EXISTS latest_reading_by_device (
  device_id uuid,
  recorded_at timestamp,
  temperature double,
  humidity double,
  PRIMARY KEY (device_id)
) WITH comment = 'The last reading per device, overwritten on each write.';

CREATE TABLE IF NOT EXISTS devices_by_site (
  site_id uuid,
  device_id uuid,
  name text,
  tags set<text>,
  PRIMARY KEY (site_id, device_id)
) WITH CLUSTERING ORDER BY (device_id ASC)
  AND comment = 'Which devices a site has, for dashboards.';

More Operations & logistics templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.