From 9f7efeeb610ae038d1e9ece7a9288718a0bb758c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 2 Oct 2019 09:53:15 +0200 Subject: [PATCH] schema: add postgresql, add migration number --- schema/mysql-migrations/upgrade_168.sql | 21 +++++++++++++++++++++ schema/mysql-migrations/upgrade_xxx.sql | 15 --------------- schema/mysql.sql | 9 +++++++-- schema/pgsql-migrations/upgrade_168.sql | 25 +++++++++++++++++++++++++ schema/pgsql.sql | 21 +++++++++++++++++++-- 5 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 schema/mysql-migrations/upgrade_168.sql delete mode 100644 schema/mysql-migrations/upgrade_xxx.sql create mode 100644 schema/pgsql-migrations/upgrade_168.sql diff --git a/schema/mysql-migrations/upgrade_168.sql b/schema/mysql-migrations/upgrade_168.sql new file mode 100644 index 00000000..27934aed --- /dev/null +++ b/schema/mysql-migrations/upgrade_168.sql @@ -0,0 +1,21 @@ +CREATE TABLE director_datafield_category ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + category_name VARCHAR(255) NOT NULL, + description TEXT DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY category_name (category_name) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE director_datafield + ADD COLUMN category_id INT(10) UNSIGNED DEFAULT NULL AFTER id, + ADD CONSTRAINT director_datafield_category + FOREIGN KEY category (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE +; + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (168, NOW()); diff --git a/schema/mysql-migrations/upgrade_xxx.sql b/schema/mysql-migrations/upgrade_xxx.sql deleted file mode 100644 index 304a7bd2..00000000 --- a/schema/mysql-migrations/upgrade_xxx.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE director_datafield_category ( - id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - category_name VARCHAR(255) NOT NULL, - description TEXT DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY category_name (category_name) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -ALTER TABLE director_datafield - ADD COLUMN category_id INT(10) UNSIGNED DEFAULT NULL AFTER id; - - --- INSERT INTO director_schema_migration --- (schema_version, migration_time) --- VALUES (167, NOW()); diff --git a/schema/mysql.sql b/schema/mysql.sql index f8e9a734..19ffff84 100644 --- a/schema/mysql.sql +++ b/schema/mysql.sql @@ -197,7 +197,12 @@ CREATE TABLE director_datafield ( -- datatype_param? multiple ones? format enum ('string', 'json', 'expression'), PRIMARY KEY (id), - KEY search_idx (varname) + KEY search_idx (varname), + CONSTRAINT director_datalist_value_datalist + FOREIGN KEY category (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE director_datafield_setting ( @@ -1878,4 +1883,4 @@ CREATE TABLE icinga_scheduled_downtime_range ( INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (167, NOW()); + VALUES (168, NOW()); diff --git a/schema/pgsql-migrations/upgrade_168.sql b/schema/pgsql-migrations/upgrade_168.sql new file mode 100644 index 00000000..7525a003 --- /dev/null +++ b/schema/pgsql-migrations/upgrade_168.sql @@ -0,0 +1,25 @@ + +CREATE TABLE director_datafield_category ( + id serial, + category_name character varying(255) NOT NULL, + description text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX datafield_category_name ON director_datafield_category (category_name); + + +ALTER TABLE director_datafield + ADD COLUMN category_id integer DEFAULT NULL, + ADD CONSTRAINT director_datafield_category + FOREIGN KEY (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE INDEX datafield_category ON director_datafield (category_id); + + +INSERT INTO director_schema_migration + (schema_version, migration_time) + VALUES (168, NOW()); diff --git a/schema/pgsql.sql b/schema/pgsql.sql index 86881939..0faed77e 100644 --- a/schema/pgsql.sql +++ b/schema/pgsql.sql @@ -248,18 +248,35 @@ CREATE TABLE director_datalist_entry ( CREATE INDEX datalist_entry_datalist ON director_datalist_entry (list_id); +CREATE TABLE director_datafield_category ( + id serial, + category_name character varying(255) NOT NULL, + description text DEFAULT NULL, + PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX datafield_category_name ON director_datafield_category (category_name); + + CREATE TABLE director_datafield ( id serial, + category_id integer DEFAULT NULL, varname character varying(64) NOT NULL, caption character varying(255) NOT NULL, description text DEFAULT NULL, datatype character varying(255) NOT NULL, -- datatype_param? multiple ones? format enum_property_format, - PRIMARY KEY (id) + PRIMARY KEY (id), + CONSTRAINT director_datafield_category + FOREIGN KEY (category_id) + REFERENCES director_datafield_category (id) + ON DELETE RESTRICT + ON UPDATE CASCADE ); CREATE INDEX search_idx ON director_datafield (varname); +CREATE INDEX datafield_category ON director_datafield (category_id); CREATE TABLE director_datafield_setting ( @@ -2182,4 +2199,4 @@ COMMENT ON COLUMN icinga_scheduled_downtime_range.merge_behaviour IS 'set -> = { INSERT INTO director_schema_migration (schema_version, migration_time) - VALUES (167, NOW()); + VALUES (168, NOW());