Search code examples
grailsgrails-ormgrails-domain-class

Should a table be automatically generated when a domain class is created?


I'm working through this tuturial and got as far as section 5.2. The tutorial states that if the command:

$ ./grailsw create-domain-class Vehicle

is used, then a table should be generated, however upon going to the console, http://localhost:8080/dbconsole/ and logging in there is no sign of the table.

I tried editing the application.yml (which to my limited and early understanding, implements in Grails 3 what was formerly in dataSource.groovy, from what I've read). Mine looks like this:

environments:
    development:
        dataSource:
            dbCreate: update
            url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    test:
        dataSource:
            dbCreate: update
            url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    production:
        dataSource:
            dbCreate: update
            url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

However, upon restarting the app and adding new domain classes, I'm still not seeing tables being created. I'm using Grails version 3.3.9 and Groovy version 2.4.15. Are tables usually created automatically with the domainClass? According to the docs, the table should be created automatically with this setup...


Solution

  • Turns out that the table was being created after all. My mistake was logging in via the console using the default placeholder JDBC URL.

    When I replaced it with the url in the application.yml, I was presented with the correct table.