PKGBUILD/pkg/repository/db/postgres/createTableHumidities.sql
Markus Pesch 0fc4aa7c28
fix: postgres columns with timezone
Add timezone for the columns creation_date and update_date, otherwise
it's difficult to compare the times correctly in the unit test.

Furthermore the default value of the creation_date will now be defined
by the postgres implementation of the database interface.
2020-10-07 23:38:27 +02:00

14 lines
715 B
SQL

CREATE TABLE IF NOT EXISTS humidities (
id CHAR(36) CONSTRAINT pk_humidities PRIMARY KEY,
value NUMERIC(10,3) NOT NULL,
date TIMESTAMP WITH TIME ZONE NOT NULL,
sensor_id CHAR(36) NOT NULL,
creation_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
update_date TIMESTAMP WITH TIME ZONE
);
ALTER TABLE humidities
ADD FOREIGN KEY (sensor_id)
REFERENCES sensors(sensor_id)
ON DELETE CASCADE
ON UPDATE CASCADE;