Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce stored procedures to drop columns on MySql #2403

Merged

Conversation

jonasPoehler
Copy link
Contributor

Hello Rob,

this PR would re-introduce using stored procedures to drop columns in migration scripts on MySql database platforms as originally introduced in #1451. With #1802 the original code was reverted for MySql, because some migration runners other than Ebean's could not interpret the init-script. I have modified the orignal change so that Ebean's default behaviour stays as it is (generating simple alter table ... drop ... calls) but now there is an option available to generate the init-script as well as use the stored procedure to drop the columns while before dropping all constraints.
I guess that for quite a lot of people using MySql (or MariaDB) with Ebean and its migration runner, this would be a major improvement and less hassle when dropping columns.
Additionally I added a test, which checks for the correct procedure calls in generated SQL and I didn't have to change anything for the other migration tests.
If this would get merged, I would also like to provide documentation for the website, so that there is a place where you can actually stumble upon this feature or reference to in case of a question e.g. on the forum. I already sketched out a paragraph for the documentation here, but I would open a PR once this one is finalized.

Looking forward to your feedback and all the best!
Jonas

@jonasPoehler
Copy link
Contributor Author

@rbygrave were you already able to have a look at this? I would appreciate some feedback.

@@ -187,7 +190,7 @@ private DdlRunner createDdlRunner(boolean expectErrors, String scriptName) {

protected void runDropSql(Connection connection) throws IOException {
if (!createOnly) {
if (extraDdl && jaxbPresent) {
if (extraDdl && jaxbPresent && useMigrationStoredProcedures) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look correct - useMigrationStoredProcedures must NOT be here.

@@ -210,7 +213,7 @@ protected void runCreateSql(Connection connection) throws IOException {
if (extraDdl && jaxbPresent) {
if (currentModel().isTablePartitioning()) {
String extraPartitioning = ExtraDdlXmlReader.buildPartitioning(platform);
if (extraPartitioning != null && !extraPartitioning.isEmpty()) {
if (extraPartitioning != null && !extraPartitioning.isEmpty() && useMigrationStoredProcedures) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look correct for Postgres at least - useMigrationStoredProcedures check must NOT be here.

if (extraDdl != null) {
List<DdlScript> ddlScript = extraDdl.getDdlScript();
for (DdlScript script : ddlScript) {
if (!script.isDrop() && matchPlatform(dbPlatform.getPlatform(), script.getPlatforms())) {
writeExtraDdl(migrationDir, script);
if (script.isInit()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth refactoring this if/else

} else {
this.runDdl = config.isDdlRun();
this.ddlAutoCommit = databasePlatform.isDdlAutoCommit();
this.useMigrationStoredProcedures = config.getDatabasePlatform().isUseMigrationStoredProcedures();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.getDatabasePlatform() -> databasePlatform

rbygrave added a commit that referenced this pull request Jan 21, 2022
@rbygrave rbygrave merged commit 4f70c09 into ebean-orm:master Jan 21, 2022
@rbygrave rbygrave added this to the 12.14.2 milestone Jan 21, 2022
@jonasPoehler
Copy link
Contributor Author

Thank you @rbygrave for taking time to review and merge this. The changes look fine to me, I guess some of the problems were relicts from the previous implementation and so it was good to have them cleaned up 👍🏿.

@rbygrave
Copy link
Member

Yes, apologies that it took so long to get to that. I had a review partially done but not submitted for a few months there - oh well, sorted now :)

@rPraml rPraml deleted the pr/enh/stored_procedures_mysql_drop_column branch January 23, 2023 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants