migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Use native DELIMITER

Open chb0github opened this issue 8 years ago • 5 comments

following on #88 mybatis should honor native DB delimiters in order to support stored procedures and such.

Benefits to this approach

  1. In the unlikely event that a migration goes wrong the original SQL script can be run with the native client
  2. Reduces the friction to adoption by those familiar with the native tooling due to 1)
  3. use of migrate script may generate a script that is intended to be run with a native client. However, without the native delimiter this would not be possible.

Since all DBs potentially (likely) use different delimiters, basically either a simple Map<String,Consumer<String>> need be implemented where the key is the command word to check to see if it's a delimiter word and the consumer is what should be done with the word to correctly process it. This follows the Command Pattern

a sketched implementation:


Map<String,Consumer<String>> COMMANDS = new HashMap<>();
COMMANDS.put("DELIMITER", c -> this.delimiter = c); // mysql version
COMMANDS.put("CHANGE", c -> this.delimiter = c.split(" ")[1]); // ORACLE version CHANGE / %

Consumer<String> whatToDo = COMMANDS.getOrDefault(command,c -> sendToDb(c));
whatToDo.accept(command);

An alternative implementation might require deeper logical inspection with the application of a series of predicates. Hopefully that's not necessary

chb0github avatar Oct 18 '17 16:10 chb0github

Both of your ideas require to implement database dependent patterns (dialects) in Migrations code and we do not do that.

Instead, I plan to add a new option delimiter_prefix or delimiter_pattern. This will work with any database without modifying Migrations code.

In your case, the configuration will look like...

delimiter_prefix=DELIMITER 

This meets your requirement, doesn't it?

harawata avatar Oct 18 '17 16:10 harawata

My case? Sure. The general case? No. For oracle, the syntax is

SET CMDS[EP] {; | c | ON | OFF}

example:

SET CMDSEP ON
SET CMDSEP "!"
SHOW CMDSEP! SHOW BUFFER!

So, while it won't be easy (hence the suggestion of using predicates and an AbstractFactory) what you have won't work.

chb0github avatar Oct 18 '17 16:10 chb0github

Hi @chb0github ,

Sorry for a late reply. At this point, I am not sure if there is a universal solution that does not involve dialect or similar. Please use hooks for now.

harawata avatar Oct 24 '17 15:10 harawata

How about we leave the issue open as a feature request? Closing an issue means it's not an issue any more and becomes less visible.

And, as I suggested: A dialectic approach is the right approach but is definitely involved

chb0github avatar Oct 24 '17 16:10 chb0github

Okay.

harawata avatar Oct 24 '17 16:10 harawata