diff options
Diffstat (limited to 'src/hydrilla/proxy/tables.sql')
-rw-r--r-- | src/hydrilla/proxy/tables.sql | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/hydrilla/proxy/tables.sql b/src/hydrilla/proxy/tables.sql index fc7c65c..0c604fc 100644 --- a/src/hydrilla/proxy/tables.sql +++ b/src/hydrilla/proxy/tables.sql @@ -132,7 +132,9 @@ CREATE TABLE items( ); CREATE TABLE mapping_statuses( - -- The item with this id shall be a mapping ("type" = 'M'). + -- The item with this id shall be a mapping ("type" = 'M'). For each + -- mapping row in "items" there must be an accompanying row in this + -- table. item_id INTEGER PRIMARY KEY, -- "enabled" determines whether mapping's status is ENABLED, @@ -142,19 +144,32 @@ CREATE TABLE mapping_statuses( -- EXACT_VERSION, is to be updated only with versions from the same -- REPOSITORY or is NOT_FROZEN at all. frozen CHAR(1) NULL, + -- The last 2 fields defined below shall be updated when dependency tree + -- is recomputed. + -- When "required" is TRUE, the mapping is assumed to either be enabled + -- or be (directly or indirectly) required by another mapping which is + -- enabled (i.e. has "enabled" set to 'E'). + required BOOLEAN NOT NULL, + -- Only one version of a mapping is allowed to be active at any time. + -- "active_version_id" indicates which version it is. Only a mapping + -- version referenced by "active_version_id" is allowed to have rows + -- in the "payloads" table reference it. active_version_id INTEGER NULL, CHECK (enabled IN ('E', 'D', 'N')), CHECK ((frozen IS NULL) = (enabled != 'E')), CHECK (frozen IS NULL OR frozen in ('E', 'R', 'N')), - CHECK (enabled != 'E' OR active_version_id IS NOT NULL) - CHECK (enabled != 'D' OR active_version_id IS NULL) + CHECK (enabled != 'E' OR required), + CHECK (enabled != 'D' OR NOT required), + CHECK (not required OR active_version_id IS NOT NULL), + CHECK (enabled != 'D' OR active_version_id IS NULL), FOREIGN KEY (item_id) REFERENCES items (item_id) ON DELETE CASCADE, FOREIGN KEY (active_version_id, item_id) REFERENCES item_versions (item_version_id, item_id) + ON DELETE SET NULL ); CREATE TABLE item_versions( @@ -163,7 +178,7 @@ CREATE TABLE item_versions( item_id INTEGER NOT NULL, version VARCHAR NOT NULL, repo_iteration_id INTEGER NOT NULL, - definition TEXT NOT NULL, + definition BLOB NOT NULL, UNIQUE (item_id, version, repo_iteration_id), -- Constraint below needed to allow foreign key from "mapping_statuses". @@ -189,8 +204,10 @@ FROM GROUP BY r.repo_id, r.name, r.url, r.deleted, r.last_refreshed; --- Every time a repository gets refreshed, or a mapping gets enabled/disabled, --- all dependencies the "payloads" table and those that reference it are +-- Every time a repository gets refreshed or a mapping gets enabled/disabled, +-- the dependency tree is recomputed. In the process the "payloads" table gets +-- cleare and repopulated together with the "resolved_depended_resources" that +-- depends on it. CREATE TABLE payloads( payload_id INTEGER PRIMARY KEY, |