CREATE TYPE battery_status_enum AS ENUM ('unknown', 'unplugged', 'charging', 'full');

CREATE TABLE locations (
    tst bigint PRIMARY KEY,
    lat numeric(9,6) NOT NULL,
    lon numeric(9,6) NOT NULL,
    acc numeric(7,2) NOT NULL,
    alt numeric(7,2),
    vel numeric(7,2),
    batt smallint NOT NULL,
    bear numeric(6,3),
    bs battery_status_enum DEFAULT 'unknown' NOT NULL,
    CONSTRAINT Location_battery_level_check CHECK ((batt >= 0) AND (batt <= 100)),
    CONSTRAINT Location_bearing_check CHECK ((bear >= (0)::numeric) AND (bear <= (360)::numeric))
)
WITH (oids = false);

CREATE INDEX locations_timestamp ON locations USING btree (tst);