I'm trying to construct a set of database migrations, in which I'm hoping to include some polyfill functions for MySQL versions prior to MySQL 8. I've found a way to use conditional comments to only run code if it is above the given version, but how can I do the opposite, and only run the code if it is, for example, any version below 8?
These migrations will be in a .sql
file with multiple statements, so the solution need not be contained to a single statement.
My current ideas are:
- Somehow use an if/else or case/when statement to run the code, if it's possible to do checking within a statement, like this (pseudocode):
SELECT "statements that will be run for any version up here" AS example;
IF @version < 80000
SELECT "This only gets run on versions prior to 8" AS example;
ELSE
/* do nothing */
END
- Stop execution of the script early without raising an error, perhaps using the conditional comments (again, pseudocode):
SELECT "statements that will be run for any version up here" AS example;
/*!80000 EXIT */
/* only MySQL 5 code after this */
SELECT "This only gets run on versions prior to 8" AS example;
- Some other method?
So, basically, how can I only run code for versions of MySQL less than version 8? If option 1, how should I check the version and conditionally execute statements? If option 2, how can I stop execution of multiple statements, without raising an error, like a MySQL equivalent to a BREAK
statement? Or otherwise, is there some better method I haven't found yet?