I'm trying to do CREATE PROCEDURE IF NOT EXISTS
in MySQL. However it looks like MySQL does not natively support this, which seems like a major oversight to me.
I've created a Spring Batch Java application which contains business schema definitions, which includes both table definitions and the stored procedure definitions. The table definitions are fine, since they say CREATE TABLE IF NOT EXISTS
. I would like the stored procedure definitions to be the same, since this business schema script will be run any time the application is launched.
MySQL does have DROP PROCEDURE IF EXISTS
, but I worry that running that before a create runs into a possible race condition. What if I've got multiple instances of this application running, and one of the other instances is running one of the stored procedures when I do the DROP and subsequent CREATE? That seems like an all around bad idea. I don't want it to interrupt anything already running.
Someone else must have encountered this same problem by now. What's the solution?