I would like to implement an evolution that applies only if a condition is met on a Scala Play framework application. The condition is that the application should be in a certain environment.
I have this evolution right now:
# payments SCHEMA
# --- !Ups
INSERT INTO table1 (id, provider_name, provider_country, provider_code, status, flag)
VALUES (10, 'XXXXX', 'XX', 'XXXXX', '1', '0');
# --- !Downs
DELETE FROM table2
WHERE id = 10;
I want the evolution to run if this condition is met
if(config.env == 'dev'){
//execute evolution
}
How do I achieve this? Is this a function of the evolution or the application logic?
One approach might be to use a stored procedure in conjunction with a db-based app 'setting'. Assume your app had an appSetting table for storing app settings.
Then, something along the following lines would create a tmpLog table (or insert a value into table1) only if appSetting has a value of 'dev' for setting 'environment' at the time of running the evolution:
You don't mention which db you are using. The above is MYSQL syntax. There might be a way to get a config value into the stored proc, perhaps via some sbt magic, but I think we would use the above if we had such a requirement. (BTW The double semicolons are for escaping out a single semicolon so that individual statements of the procedures are not executed when the procedure is being created.)