James Fredley
10/09/2025, 9:58 PMuser
10/09/2025, 9:58 PMdatabase-migration plugin and required Liquibase dependencies to your build.gradle, and ensure your migration files are in grails-app/migrations. Set migration options in application.groovy or application.yml under the grails.plugin.databasemigration prefix, such as changelogFileName and updateOnStart for auto-running migrations at startup. Example:
dependencies {
implementation 'org.apache.grails:grails-data-hibernate5-dbmigration:7.0.0-RC2'
implementation "org.liquibase:liquibase-core:4.27.0"
implementation "org.liquibase.ext:liquibase-hibernate5:4.27.0"
}
grails.plugin.databasemigration.changelogFileName = 'changelog.groovy'
grails.plugin.databasemigration.updateOnStart = true
For more details or step-by-step setup, would you like a full example or explanation of migration scripts and changelog management?
Sources:
- Grails Database Migration Plugin Manual π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.user
10/09/2025, 9:58 PMuser
10/09/2025, 9:58 PMbuild.gradle, add the plugin and Liquibase dependencies: groovy buildscript { dependencies { // Add the database migration plugin classpath 'org.apache.grails:grails-data-hibernate5-dbmigration:7.0.0-RC2' } } dependencies { implementation 'org.apache.grails:grails-data-hibernate5-dbmigration:7.0.0-RC2' // Recommended: add Liquibase dependencies directly implementation "org.liquibase:liquibase-core:4.27.0" implementation "org.liquibase.ext:liquibase-hibernate5:4.27.0" } Make sure to check for the latest versions as needed. ### 2. Configure the Migrations Folder Tell Gradle where your migration files will be. Place this before the dependencies block: groovy sourceSets { main { resources { srcDir 'grails-app/migrations' } } } This ensures your migration scripts are included in the build process. ### 3. Configure the Plugin In application.groovy or application.yml, set the plugin configuration. For example, to run migrations automatically on startup using a root changelog file: yaml grails: plugin: databasemigration: updateOnStart: true updateOnStartFileName: changelog.groovy Or in Groovy config: groovy grails.plugin.databasemigration.updateOnStart = true grails.plugin.databasemigration.updateOnStartFileName = 'changelog.groovy' You can further customize the configuration, such as specifying contexts, changelog locations, or handling multiple data sources. See the [configuration options](https://docs.grails.org/latest/grails-data/hibernate5/manual/index.html#configuration) for more details. ### 4. Generate and Apply Changelogs - To generate an initial changelog from your domain classes: bash grails dbm-generate-gorm-changelog changelog.groovy - To apply migrations: bash grails dbm-update ### 5. Source Control Commit your changelog files and code to source control so other developers can synchronize their databases. --- Note: The process for Grails 7 is consistent with Grails 6 and recent versions, as the plugin and its configuration have not changed significantly in the available documentation. If you need more advanced configuration (multiple datasources, contexts, etc.), refer to the [plugin configuration section](https://docs.grails.org/latest/grails-data/hibernate5/manual/index.html#configuration). References: [Database Migration Plugin - Getting Started](https://docs.grails.org/latest/grails-data/hibernate5/manual/index.html#gettingStarted) [Database Migration Plugin - Configuration](https://docs.grails.org/latest/grails-data/hibernate5/manual/index.html#configuration)user
10/09/2025, 9:59 PMdbm-generate-changelog or dbm-generate-gorm-changelog scripts to create your initial changelog files. This method allows you to generate changelogs directly from your database or domain classes, depending on your preference. For example: 1. Generate Changelog from Database: bash grails dbm-generate-changelog changelog.groovy This creates a changelog based on the current state of your database. 2. Generate Changelog from Domain Classes: bash grails dbm-generate-gorm-changelog changelog.groovy This creates a changelog based on your domain class definitions. Once the changelog is created, you can manually inspect and adjust the generated changesets to ensure they meet your requirements. Then, use the dbm-update script to apply the changes to your database: bash grails dbm-update Additionally, you can configure multiple datasources for migrations by specifying settings like updateAllOnStart or updateOnStartContexts in application.yml. This is particularly useful for applications with multitenancy or multiple database schemas. This approach provides more control over the initial setup and is ideal for projects where the database schema is already established or requires careful migration planning. Would you like to explore how to manage multiple datasources or use contexts for selective migrations? Sources: - [Database Migration Plugin General Usage](https://docs.grails.org/latest/grails-data/hibernate5/manual/index.html#generalUsage) - [Database Migration Plugin Configuration](https://docs.grails.org/latest/grails-data/hibernate5/manual/index.html#databaseMigration)sbglasius
10/10/2025, 7:17 AMuser
10/10/2025, 7:17 AM./gradlew dbmUpdate to apply migrations, or ./gradlew dbmGenerateChangelog -Pargs="changelog.groovy" to generate a changelog file.
Each Grails CLI command like grails dbm-update maps to a Gradle task such as dbmUpdate. You can list all available tasks with ./gradlew tasks. Would you like a full mapping of Grails CLI commands to Gradle tasks or more usage examples?
Sources:
- Restoration of Grails Shell CLI
- Database Migration Plugin Manual π 0 button π 0 button π‘ Hint: Mention @runllm in the thread for followups.user
10/10/2025, 7:17 AMrunCommand Gradle task for executing Grails-specific commands. This method is particularly useful for commands that are not directly mapped to Gradle tasks or when you need to pass complex arguments. For example:
1. Run dbm-update using runCommand:
./gradlew runCommand -Pargs="dbm-update"
2. Generate a changelog using runCommand:
./gradlew runCommand -Pargs="dbm-generate-changelog changelog.groovy"
This approach ensures compatibility with Grails commands that rely on the Grails runtime environment, as runCommand starts the Grails application context. It is particularly useful for commands that require access to GORM mappings or other application-specific configurations.
Additionally, if your Grails application is part of a multi-project Gradle setup (e.g., using the Angular profile), you can specify the subproject when running the command:
./gradlew server:runCommand -Pargs="dbm-update"
This method provides flexibility and ensures that commands are executed within the correct application context. Would you like to explore how to create custom commands for specific migration tasks?
Sources:
- Creating Custom Commands
- Restoration of Grails Shell CLI π 1 button π 0 button π‘ Hint: Mention @User in the thread for followups.