0fc4aa7c28
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.
21 lines
1.0 KiB
SQL
21 lines
1.0 KiB
SQL
CREATE TABLE IF NOT EXISTS sensors (
|
|
sensor_id CHAR(36) CONSTRAINT pk_sensors PRIMARY KEY,
|
|
sensor_name VARCHAR(64) NOT NULL,
|
|
sensor_location VARCHAR(64),
|
|
wire_id VARCHAR(64),
|
|
i2c_bus VARCHAR(255),
|
|
i2c_address VARCHAR(12),
|
|
gpio_number VARCHAR(6),
|
|
sensor_model VARCHAR(16) NOT NULL,
|
|
sensor_enabled BOOLEAN DEFAULT TRUE NOT NULL,
|
|
tick_duration VARCHAR(6) NOT NULL,
|
|
device_id CHAR(36) NOT NULL,
|
|
creation_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
update_date TIMESTAMP WITH TIME ZONE
|
|
);
|
|
|
|
ALTER TABLE sensors
|
|
ADD FOREIGN KEY (device_id)
|
|
REFERENCES devices(device_id)
|
|
ON DELETE CASCADE
|
|
ON UPDATE CASCADE; |