Could you please suggest a service or plugin which generate the corresponding XML Schema for a given Domaing Class or for all Domain Classes of Grails project.
This plugin does exactly what you're asking.
http://grails.org/plugin/domain-schemagen
You just need to type the following command shell from your project root directory:
> grails schema-export
See schema-export documentation for further details
It will generate a DDL file.
From there, you need to convert it into XML (if you really want XML).
I recommend using a database migration to control all the schema generation and to manage future changes. We use Liquibase, it's very easy to use and flexible and there is already a Grails plug in for it. All the changes in Liquibase are managed in XML format.
Also, if I am not mistaken database migrations are going to be integrated in Grails core for version 1.4 so you will be able to use schema migrations without having to install any plug in and I think with this you would be able to manage your changes using DSL as well.
Related
For the last few years I have been a Symfony developer and one of the things I enjoy the most is the fact that I don't have to write/maintain entities by hand.
Through Doctrine (the integrated ORM) I can extract the table metadata and relations through
php app/console doctrine:mapping:import SomeBundle yaml
And then I can generate the ORM entity classes
php app/console generate:doctrine:entities SomeBundle
And I'm friggin' done.
Need to migrate?, no problem. Use this command to create a migration:
doctrine:migrations:diff
And the following to migrate to it:
doctrine:migrations:migrate
For Grails, it seems that there is no straight forward way, unless I go and download the Hibernate tools and a tool like Liquibase.
There seem to be a couple of plugins that did this, but the one for reverse engineering from a database does not seem supported for Grails 3 (db-reverse-engineer) and the one for migrations I tried, but does not seem stable enough (database-migration).
Am I just looking in the wrong place?, if not, how do you as a professional Grails developer solve these needs?
No there is not a straight forward way to make a "round-trip" as you describe in Grails 3.x.
Most plugins aren't going to be 3.x ready yet. 3.x is still quite new.
That said, the reverse engineering plugin isn't designed to be a fully automated one-shot handles everything type of plugin. It's suppose to be a running start that you take the last bit by hand.
The migration plugin on the other hand is fully production ready and very stable in 2.x.
Does Grails 3.0.x no longer have the ability to create wrappers anymore?
The documentation doesn't seem to have the Grails wrapper section anymore.
Is there an alternative way which we can use the gradle wrapper to execute grails commands such as create-controller?
Does Grails 3.0.x no longer have the ability to create wrappers
anymore?
No.
Is there an alternative way which we can use the gradle wrapper to
execute grails commands such as create-controller?
Not for commands like create-controller, no.
We may re-introduce grailsw. File a feature request at https://github.com/grails/grails-core/issues if you would like to track that.
The Grails wrapper is back as of Grails 3.2.3:
http://docs.grails.org/3.2.x/guide/introduction.html#whatsNewGrailsWrapper
I have an app created with Grails 3.1.x, then upgraded to Grails 3.2.6, but the files such as 'grailsw' did not appear in my project root, and I'm not sure how to get them added via some command in the project.
When I create a new app using Grails 3.2.6, the new files are in the project root (grailsw, grailsw.bat, grails-wrapper.jar). I assume they can be copied over to an app like mine: a quick test of this worked for me.
Grails schema-export does a great job of generating the DDL to create database schemas for a particular database. However what I would like to do, is have grails just output the DDL for updates to an already created schema, not the DDL to create it from scratch.
I'm thinking it should be possible, as grails does have the ability to actually update schemas if you specificy dbCreate = "update" in your datasource.
But I just want grails to spit out what it would run, not actually do it, so I can execute it myself through a SQL tool in a controlled manner.
As #GreyBeardedGeek pointed out in a comment, the Database Migration Plugin (which is included by default now) can generate the "schema diff" that you are looking for, and it does substantially more than what the vanilla dbCreate = "update" does, since Grails' native db updating relies only on what Hibernate provides, and it's very conservative in the updates it can do.
In particular, the part of the Database Migration plugin that you are looking for is the dbm-update-sql script, which will give you the SQL that it would run to update the DB to the current schema version.
In general, I would strongly advise using a tool like the Database Migration plugin, since it bundles your DB schema in with your application code and you can easily version them together, and it also includes lots of tooling so that running the updates is much less painful, and allows for rollbacks and custom scripts to massage things as needed.
I like that Ruby On Rails allows you to write a simple schema in which you can create and update a database using. Is there any tool like Ruby On Rails's migration, as I would like to use the method without using Ruby On Rails for my website development?
There's no reason you can't use ActiveRecord::Migration outside of a rails app. In fact, you'll find plenty of examples of people doing this, as in http://exposinggotchas.blogspot.com/2011/02/activerecord-migrations-without-rails.html
If you're using mongo as the persistent store, check out mongrations for this.
I have heard this week on a little conference a talk about a tool called Liquibase, a database change management tool. It is based on Java (I think), but manages the database migrations in an XML file. The change sets you have to write are similar to the migrations you can write with Rails. If you use Liquibase inside an IDE like Eclipse, you get completion for all relevant parts of the change sets. It supports a lot of databases out of the box, so it could be an alternative, especially that nowadays Java is installed everywhere.
I recommend Python Alembic. It's not Ruby though.
Is there an app or a script that is available that will allow me to auto generate grails domain classes based on the tables in an existing database?
Found it... Grails Application Generator available on sourceforge. http://sourceforge.net/projects/grag/