Agile Database Modelling
 New GORM Features in Grails 1.4

         Prepared for SF Grails Café Centro
                    March 2011
                 by Christian Hang




      Thanks to Taulia for hosting and food!!
Agenda

 New (GORM) Features in Grails 1.4
 Quick intro to H2
 Reverse Engineering
 Database Migrations
 Other new Grails 1.4 features
 Summary
New (GORM) Features in Grails 1.4

 Replace HQSQL with H2
   Best-of-bread in-memory DB
   Built-in web console
New (GORM) Features in Grails 1.4

 Replace HQSQL with H2
   Best-of-breed in-memory DB
   Built-in web console
 Reverse Engineering
   Based on Hibernate's reverse engineering
   Create GORM classes from existing DB
New (GORM) Features in Grails 1.4

 Replace HQSQL with H2
   Best-of-bread in-memory DB
   Built-in web console
 Reverse Engineering
    Based on Hibernate's reverse engineering
    Create GORM classes from existing DB
 Database Migrations
   Based on Liquibase
   "Revision" the DB
   Allows track/rollback schema changes
Current Status

  No hard dependencies on Grails 1.4
  Everything available as plugins today
  Both main features developed by Burt Beckwith
Current Status

  No hard dependencies on Grails 1.4
  Everything available as plugins today
  Both main features developed by Burt Beckwith
  H2 plugin or JAR dependency
    com.h2database:h2:1.2.147
Current Status

  No hard dependencies on Grails 1.4
  Everything available as plugins today
  Both main features developed by Burt Beckwith
  H2 plugin or JAR dependency
    com.h2database:h2:1.2.147
  Reverse Engineering
    http://grails-plugins.github.com/grails-db-reverse-engineer/
    grails install-plugin db-reverse-engineer
    latest version 0.3
Current Status

  No hard dependencies on Grails 1.4
  Everything available as plugins today
  Both main features developed by Burt Beckwith
  H2 plugin or JAR dependency
    com.h2database:h2:1.2.147
  Reverse Engineering
    http://grails-plugins.github.com/grails-db-reverse-engineer/
    grails install-plugin db-reverse-engineer
    latest version 0.3
  Database Migrations
    http://grails-plugins.github.com/grails-database-migration/
    grails install-plugin database-migration
    latest version 0.2
Take your DB tools with you
H2 in Grails 1.4

  Replaces HSQLDB
  support in-memory, file-based, clustered DB
  comes with a build-in web console
    http://localhost:8080/appname/dbconsole
  Available as (insecure) plugin today
Use legacy databases
in Grails even faster!
Reverse Engineering

 Existing DB + Grails command = GORM classes
Reverse Engineering

 Existing DB + Grails command = GORM classes
 Uses DB connection from DataSource.groovy
 Configuration in grails-app/conf/Config.groovy
 Started with grails db-reverse-engineer
Reverse Engineering

   Existing DB + Grails command = GORM classes
   Uses DB connection from DataSource.groovy
   Configuration in grails-app/conf/Config.groovy
   Started with grails db-reverse-engineer
   Detailed configuration available
      covers many-to-many relations
      include/exclude tables, columns etc.
   Creates belongsTo, hasMany and constraints
Simplest configuration:
grails.plugin.reveng.packageName = com.acme.db
Demo Reverse Engineering
The good and the bad

 Recognizes length limitations & constraints
 Creates relates between entities
 Even handles composite primary keys
The good and the bad

 Recognizes length limitations & constraints
 Creates relates between entities
 Even handles composite primary keys
 Careful: Will probably not get it 100% correct!
 Always review generated classes
The good and the bad

 Recognizes length limitations & constraints
 Creates relates between entities
 Even handles composite primary keys
 Careful: Will probably not get it 100% correct!
 Always review generated classes
 Still helps to save a lot of work
Your source code is in VCS,
but do you version your DB?
Database Migrations

 Liquibase: verbose XML schema changesets
Database Migrations

    Liquibase: verbose XML schema changesets
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
       http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
  <changeSet author="christianhang (generated)" id="1300172497244-1">
       <createTable tableName="BLURB">
         <column autoIncrement="true" name="ID" type="BIGINT">
            <constraints nullable="false" primaryKey="true"
               primaryKeyName="CONSTRAINT_3"/>
         </column>
         <column name="VERSION" type="BIGINT">
            <constraints nullable="false"/>
         </column>
         <column name="CONTENT" type="VARCHAR(100000)"/>
         <column name="NAME" type="VARCHAR(255)">
            <constraints nullable="false"/>
         </column>
       </createTable>
  </changeSet>
  ....
Database Migrations

 Liquibase: verbose XML schema changesets
 Plugin: Groovy changesets & automation
Database Migrations

       Liquibase: verbose XML schema changesets
       Plugin: Groovy changesets & automation
  databaseChangeLog = {

changeSet(author: "christianhang (generated)", id: "1300168672278-1") {
createTable(tableName: "BLURB") {
column(autoIncrement: "true", name: "ID", type: "BIGINT") {
constraints(nullable: "false", primaryKey: "true",
                        primaryKeyName: "CONSTRAINT_3")
}

column(name: "VERSION", type: "BIGINT") {
constraints(nullable: "false")
}

column(name: "CONTENT", type: "VARCHAR(100000)")

column(name: "NAME", type: "VARCHAR(255)") {
constraints(nullable: "false")
}
}
}
     ...
Database Migrations

    Liquibase: verbose XML schema changesets
    Plugin: Groovy changesets & automation
Automatically generate changelogs
    grails dbm-generate-changelog changelog.groovy
grails dbm-gorm-diff


Apply changelogs to database
grails dbm-changelog-sync changelog.groovy
grails dbm-update

Rollback changes
grails dbm-rollback-count
grails dbm-rollback-to-date
Database Migrations

 Liquibase: verbose XML schema changesets
 Plugin: Groovy changesets & automation
 Two options
    track changes manually (changeset first)
    create automatic diffs (GORM first)
Database Migrations

 Liquibase: verbose XML schema changesets
 Plugin: Groovy changesets & automation
 Two options
    track changes manually (changeset first)
    create automatic diffs (GORM first)
 Allows to track schema changes in VCS
    Create DB from scratch
    Apply/rollback incremental changes
Database Migrations

 Liquibase: verbose XML schema changesets
 Plugin: Groovy changesets & automation
 Two options
    track changes manually (changeset first)
    create automatic diffs (GORM first)
 Allows to track schema changes in VCS
    Create DB from scratch
    Apply/rollback incremental changes
 Possibilities:
    Simplifies development with changing DB
    Manage updates to production DB
Demo Database Migrations
Issues to watch out for

  BACKUP your database!
  Always review automatic changesets!
Issues to watch out for

  BACKUP your database!
  Always review automatic changesets!
  Indexes, triggers etc. might be missed
  Checksum errors
     Changes tracked by filename in
    grails-app/conf/migrations/xxxx.groovy
    It doesn't like changeset changes
Summary

 New goodies before Grails 1.4 release
 Lots of automation when working with databases
 Reverse Engineering simplifies app setup
 Best practice: Version your DB
References

http://grails-plugins.github.com/grails-db-reverse-
engineer/docs/manual/index.html

http://grails-plugins.github.com/grails-db-reverse-
engineer/docs/manual/index.html

http://fbflex.wordpress.com/2011/01/19/working-with-the-grails-
database-migration-plugin/

http://burtbeckwith.com/blog/?p=376
Contact
 Email: christian.hang@gmail.com
 Twitter: @livingtocode
 Blog: livingtocode.com




                                          http://sfgrails.com
                                          @sfgrails


Thanks to Taulia for hosting and food!!

More Related Content

PPTX
Flyway (33rd Degree)
PPTX
Stack Overflow - It's all about performance / Marco Cecconi (Stack Overflow)
PDF
Grails Plugin Best Practices
PDF
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
PDF
Spring MVC to iOS and the REST
PDF
My "Perfect" Toolchain Setup for Grails Projects
PPT
Orchestration with Chef
PDF
Building Grails Plugins - Tips And Tricks
Flyway (33rd Degree)
Stack Overflow - It's all about performance / Marco Cecconi (Stack Overflow)
Grails Plugin Best Practices
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Spring MVC to iOS and the REST
My "Perfect" Toolchain Setup for Grails Projects
Orchestration with Chef
Building Grails Plugins - Tips And Tricks

What's hot (20)

PPTX
Working with Git
PPT
Building and Deployment of Drupal sites with Features and Context
PDF
Dropwizard and Groovy
PPT
Taking your module from Drupal 6 to Drupal 7
PPT
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
PDF
A year in the life of a Grails startup
PDF
Apache Lucene for Java EE Developers
PDF
Drupal 6 to 7 migration guide
PDF
BOSH / CF Deployment in modern ways #cf_tokyo
PDF
AWS Summit Berlin 2012 Talk on Web Data Commons
PDF
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
PDF
Gradle ex-machina
PDF
The Play Framework at LinkedIn
PPTX
Migration from Legacy CMS to Drupal
PPTX
Outputting Their Full Potential: Using Outputs for Site Redesigns and Develo...
PPTX
Faster java ee builds with gradle [con4921]
PPTX
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
PDF
GR8Conf 2011: Adopting Grails
PDF
Webinar slides: Managing MySQL Replication for High Availability
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
Working with Git
Building and Deployment of Drupal sites with Features and Context
Dropwizard and Groovy
Taking your module from Drupal 6 to Drupal 7
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
A year in the life of a Grails startup
Apache Lucene for Java EE Developers
Drupal 6 to 7 migration guide
BOSH / CF Deployment in modern ways #cf_tokyo
AWS Summit Berlin 2012 Talk on Web Data Commons
Google AppEngine (GAE/J) - Introduction and Overview from a Java Guy
Gradle ex-machina
The Play Framework at LinkedIn
Migration from Legacy CMS to Drupal
Outputting Their Full Potential: Using Outputs for Site Redesigns and Develo...
Faster java ee builds with gradle [con4921]
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
GR8Conf 2011: Adopting Grails
Webinar slides: Managing MySQL Replication for High Availability
Full stack development with node and NoSQL - All Things Open - October 2017
Ad

Similar to Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup 2011-03 (20)

PPT
Liquibase – a time machine for your data
PDF
Liquibase - Open Source version control for your database
PDF
Igalia Focus and Goals 2020 (2019 WebKit Contributors Meeting)
PDF
What’s New in Rails 5.0?
PPT
Grails Plugins
ODP
Handling Database Deployments
PDF
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
PPT
Evolutionary Database Design
PDF
Борис Трофимов. Continuous Database migration-это просто!
PDF
Continuous DB migration based on carbon5 framework
PPTX
Intro to Rails Give Camp Atlanta
PPTX
Liquibase
PDF
Grails 3.0 Preview
PDF
Big Bang And Beyond: Migrating Between Server and Cloud
KEY
Sane SQL Change Management with Sqitch
ODP
Quickr
PDF
Take your database source code and data under control
PDF
Offline strategies for HTML5 web applications - pfCongres2012
PDF
Digital Fabrication Studio v.0.2: Information
PPTX
Database Change Management as a Service
Liquibase – a time machine for your data
Liquibase - Open Source version control for your database
Igalia Focus and Goals 2020 (2019 WebKit Contributors Meeting)
What’s New in Rails 5.0?
Grails Plugins
Handling Database Deployments
FIWARE Global Summit - A Multi-database Plugin for the Orion FIWARE Context B...
Evolutionary Database Design
Борис Трофимов. Continuous Database migration-это просто!
Continuous DB migration based on carbon5 framework
Intro to Rails Give Camp Atlanta
Liquibase
Grails 3.0 Preview
Big Bang And Beyond: Migrating Between Server and Cloud
Sane SQL Change Management with Sqitch
Quickr
Take your database source code and data under control
Offline strategies for HTML5 web applications - pfCongres2012
Digital Fabrication Studio v.0.2: Information
Database Change Management as a Service
Ad

Recently uploaded (20)

PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Flame analysis and combustion estimation using large language and vision assi...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
DOCX
search engine optimization ppt fir known well about this
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Two-dimensional Klein-Gordon and Sine-Gordon numerical solutions based on dee...
PPTX
Modernising the Digital Integration Hub
PPTX
The various Industrial Revolutions .pptx
PPT
What is a Computer? Input Devices /output devices
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Configure Apache Mutual Authentication
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Architecture types and enterprise applications.pdf
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPT
Geologic Time for studying geology for geologist
Module 1.ppt Iot fundamentals and Architecture
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Flame analysis and combustion estimation using large language and vision assi...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
search engine optimization ppt fir known well about this
Taming the Chaos: How to Turn Unstructured Data into Decisions
A contest of sentiment analysis: k-nearest neighbor versus neural network
Two-dimensional Klein-Gordon and Sine-Gordon numerical solutions based on dee...
Modernising the Digital Integration Hub
The various Industrial Revolutions .pptx
What is a Computer? Input Devices /output devices
1 - Historical Antecedents, Social Consideration.pdf
Benefits of Physical activity for teenagers.pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Configure Apache Mutual Authentication
A comparative study of natural language inference in Swahili using monolingua...
Architecture types and enterprise applications.pdf
Developing a website for English-speaking practice to English as a foreign la...
Geologic Time for studying geology for geologist

Agile Database Modeling with Grails - Preview of GORM 1.4 - SF Grails Meetup 2011-03

  • 1. Agile Database Modelling New GORM Features in Grails 1.4 Prepared for SF Grails Café Centro March 2011 by Christian Hang Thanks to Taulia for hosting and food!!
  • 2. Agenda New (GORM) Features in Grails 1.4 Quick intro to H2 Reverse Engineering Database Migrations Other new Grails 1.4 features Summary
  • 3. New (GORM) Features in Grails 1.4 Replace HQSQL with H2 Best-of-bread in-memory DB Built-in web console
  • 4. New (GORM) Features in Grails 1.4 Replace HQSQL with H2 Best-of-breed in-memory DB Built-in web console Reverse Engineering Based on Hibernate's reverse engineering Create GORM classes from existing DB
  • 5. New (GORM) Features in Grails 1.4 Replace HQSQL with H2 Best-of-bread in-memory DB Built-in web console Reverse Engineering Based on Hibernate's reverse engineering Create GORM classes from existing DB Database Migrations Based on Liquibase "Revision" the DB Allows track/rollback schema changes
  • 6. Current Status No hard dependencies on Grails 1.4 Everything available as plugins today Both main features developed by Burt Beckwith
  • 7. Current Status No hard dependencies on Grails 1.4 Everything available as plugins today Both main features developed by Burt Beckwith H2 plugin or JAR dependency com.h2database:h2:1.2.147
  • 8. Current Status No hard dependencies on Grails 1.4 Everything available as plugins today Both main features developed by Burt Beckwith H2 plugin or JAR dependency com.h2database:h2:1.2.147 Reverse Engineering http://grails-plugins.github.com/grails-db-reverse-engineer/ grails install-plugin db-reverse-engineer latest version 0.3
  • 9. Current Status No hard dependencies on Grails 1.4 Everything available as plugins today Both main features developed by Burt Beckwith H2 plugin or JAR dependency com.h2database:h2:1.2.147 Reverse Engineering http://grails-plugins.github.com/grails-db-reverse-engineer/ grails install-plugin db-reverse-engineer latest version 0.3 Database Migrations http://grails-plugins.github.com/grails-database-migration/ grails install-plugin database-migration latest version 0.2
  • 10. Take your DB tools with you
  • 11. H2 in Grails 1.4 Replaces HSQLDB support in-memory, file-based, clustered DB comes with a build-in web console http://localhost:8080/appname/dbconsole Available as (insecure) plugin today
  • 12. Use legacy databases in Grails even faster!
  • 13. Reverse Engineering Existing DB + Grails command = GORM classes
  • 14. Reverse Engineering Existing DB + Grails command = GORM classes Uses DB connection from DataSource.groovy Configuration in grails-app/conf/Config.groovy Started with grails db-reverse-engineer
  • 15. Reverse Engineering Existing DB + Grails command = GORM classes Uses DB connection from DataSource.groovy Configuration in grails-app/conf/Config.groovy Started with grails db-reverse-engineer Detailed configuration available covers many-to-many relations include/exclude tables, columns etc. Creates belongsTo, hasMany and constraints Simplest configuration: grails.plugin.reveng.packageName = com.acme.db
  • 17. The good and the bad Recognizes length limitations & constraints Creates relates between entities Even handles composite primary keys
  • 18. The good and the bad Recognizes length limitations & constraints Creates relates between entities Even handles composite primary keys Careful: Will probably not get it 100% correct! Always review generated classes
  • 19. The good and the bad Recognizes length limitations & constraints Creates relates between entities Even handles composite primary keys Careful: Will probably not get it 100% correct! Always review generated classes Still helps to save a lot of work
  • 20. Your source code is in VCS, but do you version your DB?
  • 21. Database Migrations Liquibase: verbose XML schema changesets
  • 22. Database Migrations Liquibase: verbose XML schema changesets <?xml version="1.0" encoding="UTF-8" standalone="no"?> <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"> <changeSet author="christianhang (generated)" id="1300172497244-1"> <createTable tableName="BLURB"> <column autoIncrement="true" name="ID" type="BIGINT"> <constraints nullable="false" primaryKey="true" primaryKeyName="CONSTRAINT_3"/> </column> <column name="VERSION" type="BIGINT"> <constraints nullable="false"/> </column> <column name="CONTENT" type="VARCHAR(100000)"/> <column name="NAME" type="VARCHAR(255)"> <constraints nullable="false"/> </column> </createTable> </changeSet> ....
  • 23. Database Migrations Liquibase: verbose XML schema changesets Plugin: Groovy changesets & automation
  • 24. Database Migrations Liquibase: verbose XML schema changesets Plugin: Groovy changesets & automation databaseChangeLog = { changeSet(author: "christianhang (generated)", id: "1300168672278-1") { createTable(tableName: "BLURB") { column(autoIncrement: "true", name: "ID", type: "BIGINT") { constraints(nullable: "false", primaryKey: "true", primaryKeyName: "CONSTRAINT_3") } column(name: "VERSION", type: "BIGINT") { constraints(nullable: "false") } column(name: "CONTENT", type: "VARCHAR(100000)") column(name: "NAME", type: "VARCHAR(255)") { constraints(nullable: "false") } } } ...
  • 25. Database Migrations Liquibase: verbose XML schema changesets Plugin: Groovy changesets & automation Automatically generate changelogs grails dbm-generate-changelog changelog.groovy grails dbm-gorm-diff Apply changelogs to database grails dbm-changelog-sync changelog.groovy grails dbm-update Rollback changes grails dbm-rollback-count grails dbm-rollback-to-date
  • 26. Database Migrations Liquibase: verbose XML schema changesets Plugin: Groovy changesets & automation Two options track changes manually (changeset first) create automatic diffs (GORM first)
  • 27. Database Migrations Liquibase: verbose XML schema changesets Plugin: Groovy changesets & automation Two options track changes manually (changeset first) create automatic diffs (GORM first) Allows to track schema changes in VCS Create DB from scratch Apply/rollback incremental changes
  • 28. Database Migrations Liquibase: verbose XML schema changesets Plugin: Groovy changesets & automation Two options track changes manually (changeset first) create automatic diffs (GORM first) Allows to track schema changes in VCS Create DB from scratch Apply/rollback incremental changes Possibilities: Simplifies development with changing DB Manage updates to production DB
  • 30. Issues to watch out for BACKUP your database! Always review automatic changesets!
  • 31. Issues to watch out for BACKUP your database! Always review automatic changesets! Indexes, triggers etc. might be missed Checksum errors Changes tracked by filename in grails-app/conf/migrations/xxxx.groovy It doesn't like changeset changes
  • 32. Summary New goodies before Grails 1.4 release Lots of automation when working with databases Reverse Engineering simplifies app setup Best practice: Version your DB
  • 34. Contact Email: christian.hang@gmail.com Twitter: @livingtocode Blog: livingtocode.com http://sfgrails.com @sfgrails Thanks to Taulia for hosting and food!!