grails-database-migration icon indicating copy to clipboard operation
grails-database-migration copied to clipboard

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

Open tircnf opened this issue 1 year ago • 8 comments

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

Task List

  • [ X] Steps to reproduce provided
  • [ ] Stacktrace (if present) provided
  • [ ] Example that reproduces the problem uploaded to Github
  • [ X] Full description of the issue provided (see below)

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

  • Operating System: any
  • Grails Version: 6.1.1
  • Plugin Version: 4.2.1
  • Database: mysql
  • JDK Version: 11

tircnf avatar Feb 01 '24 16:02 tircnf

@tircnf Did you get any resolution for this issue?

RxL-Nikhil-Kanyal avatar May 15 '24 06:05 RxL-Nikhil-Kanyal

@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.

tircnf avatar May 31 '24 06:05 tircnf

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.

matrei avatar May 31 '24 13:05 matrei

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.

tircnf avatar Aug 20 '24 14:08 tircnf

@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.

matrei avatar Aug 20 '24 15:08 matrei

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

jdaugherty avatar Aug 20 '24 16:08 jdaugherty

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..

herrmartins avatar Aug 31 '24 16:08 herrmartins

@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

jamesfredley avatar Sep 03 '24 15:09 jamesfredley