Changeset 1248 for trunk/grails-app/conf
- Timestamp:
- Dec 9, 2010, 4:12:03 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/DatabaseUpgrade.groovy
r1247 r1248 1 1 import groovy.sql.Sql 2 import dbnp.studycapturing.Study 2 3 3 4 /** … … 35 36 */ 36 37 public static void changeStudyDescription(sql) { 37 "changeStudyDescription".grom()38 38 // check if we need to perform this upgrade 39 39 if (sql.firstRow("SELECT count(*) as total FROM template_field WHERE templatefieldentity='dbnp.studycapturing.Study' AND templatefieldname='Description'").total > 0) { 40 println "perform upgrade!" 41 } else { 42 println "upgrade not necessary!" 40 // grom that we are performing the upgrade 41 "performing database upgrade: study description".grom() 42 43 // database upgrade required 44 try { 45 println "PERFORMING DATABASE UPGRADE!!!" 46 // get the template field id 47 def id = sql.firstRow("SELECT id FROM template_field WHERE templatefieldentity='dbnp.studycapturing.Study' AND templatefieldname='Description'").id 48 49 // iterate through all obsolete study descriptions 50 sql.eachRow("SELECT study_id, template_text_fields_elt as description FROM study_template_text_fields WHERE template_text_fields_idx='Description'") { row -> 51 // migrate the template description to the study object itself 52 // so we don't have to bother with sql injections, etc 53 def study = Study.findById( row.study_id ) 54 study.setFieldValue('description', row.description) 55 if (!(study.validate() && study.save())) { 56 throw new Exception("could not save study with id ${row.study_id}") 57 } 58 } 59 60 // delete all obsolete descriptions 61 //sql.execute("DELETE FROM study_template_text_fields WHERE template_text_fields_idx='Description'") 62 63 // and delete the obsolete template field 64 //sql.execute("DELETE FROM template_field WHERE id=${id}") 65 } catch (Exception e) { 66 "changeStudyDescription database upgrade failed: " + e.getMessage() 67 } 43 68 } 44 69 }
Note: See TracChangeset
for help on using the changeset viewer.