Skip to content

Commit

Permalink
Bug #513: Changed to MySQL compatible syntax on 'ADD COLUMN IF NOT EX…
Browse files Browse the repository at this point in the history
…ISTS' in internal grate tables (#515)

* Fixed syntax so that it is MySQL compatible
* Renamed MariaDb GrateStructure/up/01_version_add_status_column.sql to 01b_version_add_status_column.sql
  to avoid issues with changed one-time scripts (actually running it is idempotent)

fixes #513
  • Loading branch information
erikbra authored May 7, 2024
1 parent 3e8d3d8 commit dae0b17
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- The MariaDB version below is more elegant, but it is not compatible with MySQL.
-- ALTER TABLE {{SchemaName}}_{{VersionTable}}
-- ADD COLUMN IF NOT EXISTS status varchar(50) NULL;;

-- MySQL does not support the IF NOT EXISTS clause for ADD COLUMN, as MariaDB does.
-- So, instead of the MariaDB version, we need to use a handler to ignore the error if the column already exists.
-- This is a bit of a hack, but it works.
-- The MariaDB version is more elegant, but it is not compatible with MySQL.
CREATE PROCEDURE create_{{SchemaName}}_{{VersionTable}}()
BEGIN
DECLARE CONTINUE HANDLER FOR 1060 BEGIN END;
ALTER TABLE {{SchemaName}}_{{VersionTable}}
ADD COLUMN status varchar(50) NULL;
END;
CALL create_{{SchemaName}}_{{VersionTable}}();

DROP PROCEDURE create_{{SchemaName}}_{{VersionTable}}

0 comments on commit dae0b17

Please sign in to comment.