Changeset 1365
- Timestamp:
- Jan 11, 2011, 6:26:47 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/DatabaseUpgrade.groovy
r1255 r1365 1 1 import groovy.sql.Sql 2 2 import dbnp.studycapturing.Study 3 import org.codehaus.groovy.grails.commons.ConfigurationHolder 3 4 4 5 /** … … 23 24 groovy.sql.Sql sql = new groovy.sql.Sql(dataSource) 24 25 26 // get configuration 27 def config = ConfigurationHolder.config 28 def db = config.dataSource.driverClassName 29 25 30 // execute per-change check and upgrade code 26 changeStudyDescription(sql) // r1245 / r1246 31 changeStudyDescription(sql, db) // r1245 / r1246 32 changeStudyDescriptionToText(sql, db) // r1327 27 33 } 28 34 … … 31 37 * @param sql 32 38 */ 33 public static void changeStudyDescription(sql ) {39 public static void changeStudyDescription(sql, db) { 34 40 // check if we need to perform this upgrade 35 41 if (sql.firstRow("SELECT count(*) as total FROM template_field WHERE templatefieldentity='dbnp.studycapturing.Study' AND templatefieldname='Description'").total > 0) { … … 72 78 } 73 79 } 80 81 /** 82 * execute database change r1327 if required 83 * @param sql 84 */ 85 public static void changeStudyDescriptionToText(sql, db) { 86 // are we running postgreSQL ? 87 if (db == "org.postgresql.Driver") { 88 // check if column 'description' in table 'study' is not of type 'text' 89 if (sql.firstRow("SELECT count(*) as total FROM information_schema.columns WHERE columns.table_schema::text = 'public'::text AND columns.table_name='study' AND column_name='description' AND data_type != 'text'").total > 0) { 90 // grom that we are performing the upgrade 91 "performing database upgrade: study description to text".grom() 92 93 // database upgrade required 94 try { 95 // change the datatype of study::description to text 96 sql.execute("ALTER TABLE study ALTER COLUMN description TYPE text") 97 } catch (Exception e) { 98 "changeStudyDescriptionToText database upgrade failed: " + e.getMessage() 99 } 100 } 101 } 102 } 74 103 }
Note: See TracChangeset
for help on using the changeset viewer.