-- https://github.com/EarthScope/mseedindex/wiki/Database-Schema
-- Time series index schema for PostgreSQL
-- Version 1.1

CREATE TABLE tsindex
(
  id bigserial,
  network character text NOT NULL,
  station character text NOT NULL,
  location character text NOT NULL,
  channel character text NOT NULL,
  quality character text NOT NULL,
  version smallint,
  starttime timestamp with time zone NOT NULL,
  endtime timestamp with time zone NOT NULL,
  samplerate numeric NOT NULL,
  filename character text NOT NULL,
  byteoffset bigint NOT NULL,
  bytes bigint NOT NULL,
  hash character text,
  timeindex hstore,
  timespans numrange[],
  timerates numeric[],
  format character text,
  filemodtime timestamp with time zone NOT NULL,
  updated timestamp with time zone NOT NULL,
  scanned timestamp with time zone NOT NULL
);

-- Suggested indexes

CREATE INDEX tsindex_filename_idx
  ON tsindex
  USING btree
  (filename);

CREATE INDEX tsindex_nslcq_idx
  ON tsindex
  USING btree
  (network, station, location, channel, quality);

CREATE INDEX tsindex_starttime_idx
  ON tsindex
  USING btree
  (starttime);

CREATE INDEX tsindex_endtime_idx
  ON tsindex
  USING btree
  (endtime);

CREATE INDEX tsindex_updated_idx
  ON tsindex
  USING btree
  (updated);

