Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge schema files and increase schema version for v1.1.1 #630

Merged
merged 2 commits into from
Aug 7, 2023

Conversation

julianbrost
Copy link
Contributor

@julianbrost julianbrost commented Aug 3, 2023

This PR merges the currently existing 1.2.0.sql schema upgrade files into 1.1.1.sql and updates the schema version as removing the NOT NULL constraint from customvar_flat.flatvalue is not compatible (Icinga DB v1.1.1 would crash on the old schema version).

fixes #602

Full schema vs. upgrade diffs

Both only differ in the contents of the icingadb_schema table (as expected).

PostgreSQL

$ dropdb idb_a; createdb idb_a; psql -qv ON_ERROR_STOP=1 idb_a < schema/pgsql/schema.sql                                                         
$ dropdb idb_b; createdb idb_b; { git show v1.1.0:schema/pgsql/schema.sql; cat schema/pgsql/upgrades/1.1.1.sql } | psql -qv ON_ERROR_STOP=1 idb_b
$ diff -u <(pg_dump -O idb_a) <(pg_dump -O idb_b) 
--- /proc/self/fd/11	2023-08-07 13:10:29.825577141 +0200
+++ /proc/self/fd/12	2023-08-07 13:10:29.828910489 +0200
@@ -4216,7 +4216,8 @@
 --
 
 COPY public.icingadb_schema (id, version, "timestamp") FROM stdin;
-1	2	1691406616634
+1	1	1691406625123
+2	2	1691406625189
 \.
 
 
@@ -4488,7 +4489,7 @@
 -- Name: icingadb_schema_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
 --
 
-SELECT pg_catalog.setval('public.icingadb_schema_id_seq', 1, true);
+SELECT pg_catalog.setval('public.icingadb_schema_id_seq', 2, true);
 
 
 --

MariaDB

$ mariadb -e 'drop database if exists idb_a; create database idb_a;' && mariadb idb_a < schema/mysql/schema.sql
$ mariadb -e 'drop database if exists idb_b; create database idb_b;' && { git show v1.1.0:schema/mysql/schema.sql; cat schema/mysql/upgrades/1.1.1.sql } | mariadb idb_b 
$ diff -us <(mariadb-dump idb_a) <(mariadb-dump idb_b)
--- /proc/self/fd/11	2023-08-07 13:11:46.345922801 +0200
+++ /proc/self/fd/12	2023-08-07 13:11:46.349256149 +0200
@@ -1,6 +1,6 @@
 -- MariaDB dump 10.19-11.0.2-MariaDB, for Linux (x86_64)
 --
--- Host: localhost    Database: idb_a
+-- Host: localhost    Database: idb_b
 -- ------------------------------------------------------
 -- Server version	11.0.2-MariaDB
 
@@ -965,7 +965,7 @@
   `version` smallint(5) unsigned NOT NULL,
   `timestamp` bigint(20) unsigned NOT NULL,
   PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -975,7 +975,8 @@
 LOCK TABLES `icingadb_schema` WRITE;
 /*!40000 ALTER TABLE `icingadb_schema` DISABLE KEYS */;
 INSERT INTO `icingadb_schema` VALUES
-(1,4,20230807131045000);
+(1,3,20230807131051000),
+(2,4,20230807131051000);
 /*!40000 ALTER TABLE `icingadb_schema` ENABLE KEYS */;
 UNLOCK TABLES;
 

Diff of old files and 1.1.1.sql in this PR

Apart from the extra insert for the schema version and an empty line, the new 1.1.1.sql files are identical to concatenating the previous 1.1.1.sql and 1.2.0.sql.

PostgreSQL

$ diff -us <(git show main:schema/pgsql/upgrades/1.1.1.sql main:schema/pgsql/upgrades/1.2.0.sql) schema/pgsql/upgrades/1.1.1.sql
--- /proc/self/fd/11	2023-08-07 13:13:57.379849934 +0200
+++ schema/pgsql/upgrades/1.1.1.sql	2023-08-07 13:09:01.491846009 +0200
@@ -1,5 +1,6 @@
 ALTER TABLE notification ALTER COLUMN name TYPE varchar(767);
 COMMENT ON COLUMN notification.name IS '255+1+255+1+255, i.e. "host.name!service.name!notification.name"';
+
 ALTER TABLE customvar_flat ALTER COLUMN flatvalue DROP NOT NULL;
 
 CREATE INDEX idx_customvar_flat_flatname_flatvalue ON customvar_flat(flatname, flatvalue);
@@ -24,3 +25,6 @@
   ALTER COLUMN event_type TYPE history_type USING event_type::text::history_type,
   ALTER COLUMN event_type SET DEFAULT 'state_change'::history_type;
 DROP TYPE history_type_old;
+
+INSERT INTO icingadb_schema (version, timestamp)
+  VALUES (2, extract(epoch from now()) * 1000);

MySQL/MariaDB

$ diff -us <(git show main:schema/mysql/upgrades/1.1.1.sql main:schema/mysql/upgrades/1.2.0.sql) schema/mysql/upgrades/1.1.1.sql
--- /proc/self/fd/11	2023-08-07 13:13:45.516462753 +0200
+++ schema/mysql/upgrades/1.1.1.sql	2023-08-07 13:09:01.491846009 +0200
@@ -1,6 +1,7 @@
 ALTER TABLE notification
     MODIFY COLUMN name varchar(767) NOT NULL COMMENT '255+1+255+1+255, i.e. "host.name!service.name!notification.name"',
     MODIFY COLUMN name_ci varchar(767) COLLATE utf8mb4_unicode_ci NOT NULL;
+
 ALTER TABLE customvar_flat MODIFY COLUMN flatvalue text DEFAULT NULL;
 
 ALTER TABLE customvar_flat
@@ -31,3 +32,6 @@
     DROP COLUMN event_type,
     CHANGE COLUMN event_type_new event_type enum('state_change', 'ack_clear', 'downtime_end', 'flapping_end', 'comment_remove', 'comment_add', 'flapping_start', 'downtime_start', 'ack_set', 'notification') NOT NULL;
 UNLOCK TABLES;
+
+INSERT INTO icingadb_schema (version, timestamp)
+  VALUES (4, CURRENT_TIMESTAMP() * 1000);

@julianbrost julianbrost added this to the 1.1.1 milestone Aug 3, 2023
@cla-bot cla-bot bot added the cla/signed label Aug 3, 2023
@julianbrost julianbrost linked an issue Aug 3, 2023 that may be closed by this pull request
2 tasks
Base automatically changed from history-event-type-order to main August 7, 2023 11:08
Initially, we planed a 1.2.0 release instead of 1.1.1 so over time, both schema
upgrade files appeared. Merge them to clean up in preparation for the 1.1.1
release.

Changes were generated using these commands:

    { echo; cat schema/mysql/upgrades/1.2.0.sql } >> schema/mysql/upgrades/1.1.1.sql
    { echo; cat schema/pgsql/upgrades/1.2.0.sql } >> schema/pgsql/upgrades/1.1.1.sql
    git rm schema/mysql/upgrades/1.2.0.sql
    git rm schema/pgsql/upgrades/1.2.0.sql
The removal of the `NOT NULL` constraint on `customvar_flat`.`flat_value` makes
the schema upgrade a hard requirement for 1.1.1.
@julianbrost julianbrost marked this pull request as ready for review August 7, 2023 12:48
@julianbrost julianbrost merged commit 57f4f78 into main Aug 7, 2023
@julianbrost julianbrost deleted the schema-version branch August 7, 2023 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema version for the next release
2 participants