CREATE TABLE Measure (
  GatewayId VARCHAR(255) NOT NULL,
  Mid INT NOT NULL,
  Time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  Value FLOAT8 NOT NULL,
  PRIMARY KEY (GatewayId,Mid,Time)
) PARTITION BY RANGE (mid);

CREATE TABLE ValuelessMeasure (
  GatewayId VARCHAR(255) NOT NULL,
  Mid INT NOT NULL,
  Time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  PRIMARY KEY (GatewayId,Mid,Time)
) PARTITION BY RANGE (mid);

CREATE TABLE IF NOT EXISTS GatewayMetricsPacket (
  GatewayId VARCHAR(255) NOT NULL,
  Time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  Metric VARCHAR(255) NOT NULL DEFAULT '',
  PRIMARY KEY (GatewayId, Time)
);

CREATE TABLE IF NOT EXISTS GatewayTestPacket (
  GatewayId VARCHAR(255) NOT NULL,
  Time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  PRIMARY KEY (GatewayId, Time)
);

CREATE TABLE IF NOT EXISTS GatewayLastSeen (
  GatewayId VARCHAR(255) NOT NULL,
  Time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
  PRIMARY KEY (GatewayId)
);
