grails / grails-database-migration

Grails® framework Database Migration Plugin
Apache License 2.0
98 stars 115 forks source link

None of the dbm-scripts are working with grails 6. #346

Open tircnf opened 7 months ago

tircnf commented 7 months ago

This is a known issue with all grails plugins after the upgrade to 6.

Task List

Steps to Reproduce

  1. build a grails 6 app
  2. include this plugin.
  3. try any script.

Expected Behaviour

scripts should run.

Actual Behaviour

since the grails 6 upgrade, all plugins with scripts need to change to the new methodology. Documentation needs to be updated.

Environment Information

RxL-Nikhil-Kanyal commented 3 months ago

@tircnf Did you get any resolution for this issue?

tircnf commented 3 months ago

@RxL-Nikhil-Kanyal -- Not really. we haven't upgraded to 6 yet. I think your choices are to either stick with pre-6 grails, wait for the grails team to upgrade the plugin, or dig in and upgrade the plugin to use the new way grails runs scripts.

matrei commented 3 months ago

In Grails 6, the commands are available as Gradle tasks, for example: ./gradlew dbmGenerateChangelog -Pargs="changelog.groovy"

If not already present, add runtimeOnly 'org.grails.plugins:database-migration:4.2.1' to buildSrc dependencies to add the Gradle tasks.

Although, to run the database-migration:4.2.1 commands in Grails 6.2.0 you also need to add org.grails:grails-shell:6.1.2 to the buildSrc dependencies of your project, as grails-shell is still needed for 4.2.1 and was removed in Grails 6.2.0. Or use the 5.0.0-SNAPSHOT version of the database-migration plugin where grails-shell is no longer used.

Another caveat when running commands with 6.2.0 is that there is a bug in grails-bootstrap (after the upgrade to Groovy 3.0.21) when running commands. This bug is fixed by grails/grails-core#13472 and should be included in the next Grails release.

tircnf commented 2 weeks ago

I think the arguments are in the incorrect order. Should it be gradle runCommand -Pargs="dbm-generate-gorm-changelog changelog.groovy"

@matrei -- Are you saying in that last sentence that there is no way to currently get the scripts to run on grails 6.2?

Another caveat when running commands with 6.2.0 is that there is a bug in grails-bootstrap (after the upgrade to Groovy 3.0.21) when running commands. This bug is fixed by https://github.com/grails/grails-core/pull/13472 and should be included in the next Grails release.

matrei commented 2 weeks ago

@tircnf

I think the arguments are in the incorrect order. Should it be gradle runCommand -Pargs="dbm-generate-gorm-changelog changelog.groovy"

You can run commands that way too. Here is a guide on using application commands in Grails 6: https://medium.com/@puneetbehl/a-comprehensive-guide-to-custom-application-command-in-grails-framework-f7496406ac50

Are you saying in that last sentence that there is no way to currently get the scripts to run on grails 6.2?

If you upgrade the Grails version 6.2.1-SNAPSHOT the fix should be in there. There is work going on right now to get a 6.2.1 version released.

jdaugherty commented 2 weeks ago

Alternatively, as a temporary work around, here's a shell function I use to make it easy to call the original scripts:

function _grails() {
  local msg="$*";
  local gradleArgs=`print -l $msg`;
  gradle runCommand "-Pargs=$gradleArgs"
}

Then invoke the scripts like _grails dbm-gorm-diff test.groovy

herrmartins commented 1 week ago

I'm just learning grails now, because I got a job as junior dev in a company.. to learn I begin to use 6 and this issue was just blowing my mind.. HOw can we create an app by the forge app, and just don't work? Begining from the driver.. but ok... grails 6.2.0 I did this: implementation("org.grails:grails-shell:6.1.2") implementation("org.grails.plugins:database-migration:4.2.1")

I do'nt know, if it is good, I don't understand much of the framwork.. it was ok to build like this.. it is running, debugging in vs code..
jamesfredley commented 4 days ago

@herrmartins

You will also need to add the following to buildSrc/build.gradle (the way it comes from forge) or buildscript in your top level build.gradle (the older way).

classpath("org.grails.plugins:database-migration:4.2.1")
classpath("org.grails:grails-shell:6.1.2") // for database-migration

Then you can execute them with Grails Shell. org.grails.plugins:database-migration 4.2.1 and 5.0.0-SNAPSHOT have not been migrated fully to Gradle yet.

If you are using IntelliJ, you can execute via Run Grails Command

dbm-gorm-diff generated.groovy

Otherwise you can add grails wrapper, see https://github.com/orgs/grails/discussions/13583, and execute as

./grailsw dbm-gorm-diff generated.groovy