Grails - DB migration for Quartz plug-in persistence - grails

We would like to use the Quartz plug-in persistent mode for working in a cluster. Our DB schema is maintained using the DB-migration plug-in, and therefore we can not use the provided SQL script for updating the DB.
Is there a db-migration script (i.e. - a Groovy file) that creates the tables, that we can use? Can someone that managed to run the migration share one with us?
Alternatively - is there another way to create the tables, when working in DB migration mode?
Thanks

Maybe instead of trying to convert the scripts you could use them directly by either considering this: http://www.liquibase.org/manual/formatted_sql_changelogs or this:http://www.liquibase.org/manual/custom_sql_file. I think you can use liquibase's include tag with the sql change log. Basically just copy and paste the contents and run them using one of the 2 methods I listed above. If you use the second method, maybe you don't need to copy and paste anything and just directly reference it?

Related

Is there a Grails 3 profile for creating a batch application?

I'd like to create a batch application that has GORM hooked in, etc. Is there a Grails 3 profile for creating a batch (not web) application? Is there some other pattern for using Grails/GORM in a batch context?
EDIT: None of the profiles with 'grails list-profiles' would seem to apply. I've not had luck searching for how to do this, so maybe no one uses this pattern and uses a simple Gradle build instead.
If you want to use the GORM outside grails, I suggest you check the latest GORM documentation. You can creeate a simple groovy app and receive information from the command line and use the GORM functionality inside of it.

Where is the appropriate place for SQL scripts in a Grails project

I've got a Grails plugin that exports domain objects so that several applications can share the same schema. We have a few SQL scripts for setting up some complex triggers, views and other functions that just don't really belong in GORM/Hibernate, at least not elegantly. I'd like to store the scripts inside the same project. Is the "scripts" folder (the one containing _[Un]Install/Upgrade.groovy) the best place for this? I saw a StackOverflow answer that was building a catalog from scripts stored in grails-app/conf/sql. But I'm not actually trying to execute them from within the a project.
The absolute best solution for anything database related is to use the database migration plugin. This way you can ensure that any database your application is pointed to (dev, test, prod, etc.) will have the same information/schema/functions/procedures etc.
Personal preference. I usually add a 'database' dir for all that kind of stuff. The 'scripts' dir is for Grails scripts, at least in 1.x and 2.x. See Creating Gant Scripts or the create-script command for more on those. In Grails 3 these kind of scripts have been moved to src/main/scripts.

data source location

I'm currently working with the Grails tool suit with eclipse. I created an an application, defined a domain class and my app works great. My question is, when I deploy my war file how is the database stored? Do I link my data source file to an sql database url. If so upon running my app the first time does Grails create the database for you? You probably understand my question by now. How does this work?
I've looked at this documentation and cant find how grails goes about with creating the database I defined.
http://grails.org/doc/latest/guide/conf.html#dataSourcesAndEnvironments
First off, with the exception of H2 Grails does not setup your database. You will need to setup the database, and configure your datasource to connect to the database.
That said, Grails will manage (as best it can) the schema for your database based upon your Domain classes. This is the default behavior when dbCreate is set to "update" in your DataSource.groovy file.
I would recommend reading through the great online documentation regarding database configuration and settings.
You also have more advanced tools available to you such as the database migration plugin should you need that level of control and flexibility.
In DataSource.groovy (under the conf dir) you find the definition of a H2 db. You could configure a mysql db, oracle, mongodb and so on database.
You also could specify which database use in dev, test and prod enviroments.
when you run your default rails app. The grails environment creates a in memory database for your app. It is created every time you restart your project.
In case you want to have your persistent database like mysql, mongodb etc.
What you need to do is (mysql for example)
Add a mysql dependency in BuildConfig.groovy like runtime 'mysql:mysql-connector-java:5.1.27'
Add Database and driver settings in DataSource.groovy. Now you can have different databases for different environments i.e. prod, test and dev modes. You can do this by having global setting for database or by defining settings for each mode separately.
In order to view your database from your running app you can use link http://localhost:8080/app/dbconsole just enter your database password and username. You will be able to do all your db related queries here. In case you are using grails default in memory database just use hit enter the default values that are there in DataSource.groovy for database

Creating general purpose gant scripts

Is it possible to create gant scripts to automate generalized processes.
e.g. Grails provides a default script 'create-app' to create a project using a tomcat container. Now suppose that I want to write my own script that could create projects using jboss as a server. I would like to save this script in a generalized manner so that I can use it to create more projects, rather than save it under some specific projet.
Is it possible to do that?
Yes, save it in $HOME/.grails/scripts. This way it will be available to all Grails installs.
Note that the naming convention is important; if the script starts with an underscore, it cannot be called directly as a script, only included in others (e.g. to store common code and methods). If it ends in an underscore, it can be called outside of a project (e.g. the create-app script is named CreateApp_.groovy). If there's no leading or trailing underscore then it can be called from within a project.

Grails - Calling scripts within DB Migration changelog

While using the DB Migration plugin I came across an interesting question. In our regular war deployments, time and again, we need to run certain scripts for data updates to accommodate our changed code. While we can still run these externally, we were trying to find a way to add them as a part of DB Migration process.
Now one set of these scripts can be converted into migration scripts and added inside the grailsChange section and and they run pretty seamlessly. There is another set of scripts though, which are problematic because of a couple of reasons.
These scripts are run time and again so we would have to keep changing the id with every run as we don't want to duplicate the code, thus losing the original changes.
We pass params to these scripts from the command line and by the method above we have to add them to the scripts themselves just causing maintainability issues.
So my question would be, is there a more elegant way to trigger external grails or groovy scripts from within the DB migration scripts such that every time we need to run a script file, we can create the changelog with the updated call and tag it with the app.
I think there was a post on stackoverflow regarding this a while back, but I cannot for the love of my life, find it any more. Any help regarding this would be appreciated.
Thanks
Are the scripts something you could add into bootstrap.groovy? That would probably be the simplest. Just use groovy.sql.Sql to run the scripts.
Another more functional and flexible option would be to create a service to run the scripts (groovy.sql.Sql) and a domain class to track the scripts that have been run. You could trigger the service in the bootstrap.groovy file and the service could look at some migrations domain class you set up to see if the script has been run. You could even go as far to secure a front end to this mechanism to upload a script file to execute at runtime.
Let me know more details of what you want and I can try to be more detailed in my response.

Resources