source: trunk/grails-app/conf/DatabaseUpgrade.groovy @ 1247

Last change on this file since 1247 was 1247, checked in by work@…, 10 years ago
  • adding initial version of automatic database upgrade script
File size: 1.1 KB
Line 
1import groovy.sql.Sql
2
3/**
4 * A script to automatically perform database changes
5 *
6 * @Author      Jeroen Wesbeek
7 * @Since       20101209
8 *
9 * Revision information:
10 * $Rev$
11 * $Author$
12 * $Date$
13 */
14class DatabaseUpgrade {
15        /**
16         * handle database upgrades
17         *
18         * @param dataSource
19         */
20        public static void handleUpgrades(dataSource) {
21                // gromming debug message
22                "handeling database upgrades".grom()
23
24                // get a sql instance
25                groovy.sql.Sql sql = new groovy.sql.Sql(dataSource)
26
27                // check for study description change from template
28                // to required domain field (r1245 and r1246)
29                changeStudyDescription(sql)
30        }
31
32        /**
33         * execute database change r1245 / r1246 if required
34         * @param sql
35         */
36        public static void changeStudyDescription(sql) {
37                "changeStudyDescription".grom()
38                // check if we need to perform this upgrade
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!"
43                }
44        }
45}
Note: See TracBrowser for help on using the repository browser.