Mercurial > dive4elements > river
changeset 161:119048655872
Initial check in of the FLYS database backend.
flys-backend/trunk@1310 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 10 Feb 2011 12:07:35 +0000 |
parents | |
children | 80669241956c |
files | flys-backend/ChangeLog flys-backend/doc/schema/sqlite.sql |
diffstat | 2 files changed, 161 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/ChangeLog Thu Feb 10 12:07:35 2011 +0000 @@ -0,0 +1,4 @@ +2011-02-10 Sascha L. Teichmann: + + * doc/schema/sqlite.sql: Added initial schema for + FLYS database.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/doc/schema/sqlite.sql Thu Feb 10 12:07:35 2011 +0000 @@ -0,0 +1,157 @@ +BEGIN TRANSACTION; + +-- Gewaesser +CREATE TABLE rivers ( + id INTEGER PRIMARY KEY NOT NULL, + name VARCHAR(256) NOT NULL UNIQUE +); + +-- Bruecke, Haefen, etc. +CREATE TABLE attributes ( + id INTEGER PRIMARY KEY NOT NULL, + value VARCHAR(256) NOT NULL UNIQUE +); + +-- segments from/to at a river +CREATE TABLE ranges ( + id INTEGER PRIMARY KEY NOT NULL, + river_id INTEGER NOT NULL REFERENCES river(id), + a NUMERIC NOT NULL, + b NUMERIC, + UNIQUE (river_id, a, b) +); + +-- Lage 'links', 'rechts', etc. +CREATE TABLE positions ( + id INTEGER PRIMARY KEY NOT NULL, + value VARCHAR(256) NOT NULL UNIQUE +); + +-- Some object (eg. Hafen) at a segment of river +-- plus its position. +CREATE TABLE annotations ( + id INTEGER PRIMARY KEY NOT NULL, + range_id INTEGER NOT NULL REFERENCES ranges(id), + attribute_id INTEGER NOT NULL REFERENCES attributes(id), + position_id INTEGER REFERENCES positions(id) +); + +-- Pegel +CREATE TABLE gauges ( + id INTEGER PRIMARY KEY NOT NULL, + name VARCHAR(256) NOT NULL, + river_id INTEGER NOT NULL REFERENCES river(id), + station NUMERIC NOT NULL UNIQUE, + aeo NUMERIC NOT NULL, + + -- Pegelnullpunkt + datum NUMERIC NOT NULL, + -- Streckengueltigkeit + range_id INTEGER NOT NULL REFERENCES ranges (id), + + UNIQUE (name, river_id) +); + +-- Type of a Hauptwert 'W', 'Q', 'D', etc. +CREATE TABLE main_value_types ( + id INTEGER PRIMARY KEY NOT NULL, + name VARCHAR(256) NOT NULL UNIQUE +); + +-- Named type of a Hauptwert (eg. HQ100) +CREATE TABLE named_main_values ( + id INTEGER PRIMARY KEY NOT NULL, + name VARCHAR(256) NOT NULL UNIQUE, + type_id INTEGER NOT NULL REFERENCES main_value_types(id), + UNIQUE (name, type_id) +); + +-- Stammdaten +CREATE TABLE main_values ( + id INTEGER PRIMARY KEY NOT NULL, + gauge_id INTEGER NOT NULL REFERENCES gauges(id), + named_value_id INTEGER NOT NULL REFERENCES named_main_values(id), + value NUMERIC NOT NULL, + + start_time TIMESTAMP DEFAULT NULL, + stop_time TIMESTAMP DEFAULT NULL, + + -- TODO: better checks + CHECK (start_time <= stop_time), + UNIQUE (gauge_id, named_value_id, start_time, stop_time) +); + +-- Abflusstafeln +CREATE TABLE discharge_table ( + id INTEGER PRIMARY KEY NOT NULL, + gauge_id INTEGER NOT NULL REFERENCES gauges(id), + + start_time TIMESTAMP DEFAULT NULL, + stop_time TIMESTAMP DEFAULT NULL, + + -- TODO: better checks + CHECK (start_time <= stop_time), + UNIQUE (gauge_id, start_time, stop_time) +); + +-- Values of the Abflusstafeln +CREATE TABLE discharge_table_values ( + id INTEGER PRIMARY KEY NOT NULL, + table_id INTEGER NOT NULL REFERENCES discharge_table(id), + q NUMERIC NOT NULL, + w NUMERIC NOT NULL, + + UNIQUE (table_id, q, w) +); + +-- WST files +CREATE TABLE wst ( + id INTEGER PRIMARY KEY NOT NULL, + river_id INTEGER NOT NULL REFERENCES river(id), + description VARCHAR(256) NOT NULL, + -- TODO: more meta infos + UNIQUE (river_id, description) +); + +-- columns of WST files +CREATE TABLE wst_column ( + id INTEGER PRIMARY KEY NOT NULL, + wst_id INTEGER NOT NULL REFERENCES wst(id), + name VARCHAR(256) NOT NULL, + description VARCHAR, + + start_time TIMESTAMP DEFAULT NULL, + stop_time TIMESTAMP DEFAULT NULL, + + CHECK (start_time <= stop_time), + UNIQUE (wst_id, name) +); + +-- w values in WST file column +CREATE TABLE wst_column_values ( + id INTEGER PRIMARY KEY NOT NULL, + wst_column_id INTEGER NOT NULL REFERENCES wst_column(id), + position NUMERIC NOT NULL, + w NUMERIC NOT NULL, + + UNIQUE (position, wst_column_id), + UNIQUE (position, wst_column_id, w) +); + +-- bind q values to range +CREATE TABLE wst_q_ranges ( + id INTEGER PRIMARY KEY NOT NULL, + range_id INTEGER NOT NULL REFERENCES ranges(id), + q NUMERIC NOT NULL +); + +-- bind q ranges to wst columns +CREATE TABLE wst_column_q_ranges ( + id INTEGER PRIMARY KEY NOT NULL, + wst_column_id INTEGER NOT NULL REFERENCES wst_column(id), + wst_q_range_id INTEGER NOT NULL REFERENCES wst_q_ranges(id), + + UNIQUE (wst_column_id, wst_q_range_id) +); + +END TRANSACTION;