Announcement Announcement Module
Collapse
No announcement yet.
Configuring Grails for Read Only Database Access Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring Grails for Read Only Database Access

    Good Day Folks
    Forgive me if this has been asked before but I have not found a satisfactory answer in my searches:

    - is there a way in Grails configuration to mark the defined datasource as being read only and prevent the application from trying to modify tables at startup ?

    The only way I have managed anything close is to use the Datasources plugin where i have a configuration like :

    Code:
     datasources = {
    
    	datasource(name: 'nicealias') {
    		domainClasses([com.my.domain.class.InsuranceClaim,
    		               com.my.domain.class.Policy])
    		readOnly(true)
    		driverClassName('com.microsoft.sqlserver.jdbc.SQLServerDriver')
    		url('jdbc:sqlserver://localhost:1433;databaseName=ClaimDB')
    		username('password')
    		password('password')
    		dbCreate('update')
    		logSql(true)
    		dialect(org.hibernate.dialect.SQLServerDialect)
    		hibernate {
    			cache {
    				use_second_level_cache(false)
    				use_query_cache(false)
    			}
    		}
    	}
    
    }
    however..is there a way to do it without the Datasources plugin - which I LOVE by the way.

    thanks

  • #2
    This depends. Do you want the database to be read-only for your application? Or do you simply want to prevent Grails from modifying the schema during startup? If the latter, simply remove the 'dbCreate' setting from your DataSource configuration.

    Comment


    • #3
      Peter
      The latter (not modifying the database) I definitely need since I am not creating the database - my client is. So modifications are not really welcome.

      But if you have a solution for preventing grails from ever attempting an update/insert would be interesting. Other than just making sure you never call save on a domain object .. is there a configuration approach to this ?

      thanks for the reply..

      Comment


      • #4
        I don't know of one, sorry. You can probably override the dataSource bean with a read-only setting, but I haven't looked into that or used it before.

        Comment


        • #5
          Is there something I can do to ensure the next release of Grails documentation indicates that you can actually remove the dbCreate setting ?

          Comment


          • #6
            Raise a JIRA issue, or even better, fork the repository from GitHub and send a pull request. grails.org has more info.

            Comment

            Working...
            X