Skip to content
Newer
Older
100644 79 lines (63 sloc) 2.43 KB
835947f @burtbeckwith cleanup
burtbeckwith authored
1 /*
2 * Copyright 2004-2005 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
17 import grails.util.GrailsUtil
3e17890 1.1 branch is now trunk
graeme authored
18
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
19 import org.hibernate.tool.hbm2ddl.SchemaExport as HibernateSchemaExport
20
21 includeTargets << grailsScript('_GrailsBootstrap')
3e17890 1.1 branch is now trunk
graeme authored
22
835947f @burtbeckwith cleanup
burtbeckwith authored
23 /**
24 * @author Burt Beckwith
25 */
26
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
27 target(schemaExport: 'Run Hibernate SchemaExport') {
55b34b5 @burtbeckwith GRAILS-7051 added --datasource option to export ddl for a particular …
burtbeckwith authored
28 depends checkVersion, configureProxy, enableExpandoMetaClass, bootstrap
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
29
30 String filename = "${grailsSettings.projectTargetDir}/ddl.sql"
31 boolean export = false
32 boolean stdout = false
33
34 for (arg in argsMap.params) {
35 switch(arg) {
36 case 'export': export = true; break
37 case 'generate': export = false; break
38 case 'stdout': stdout = true; break
39 default: filename = arg
3e17890 1.1 branch is now trunk
graeme authored
40 }
41 }
42
55b34b5 @burtbeckwith GRAILS-7051 added --datasource option to export ddl for a particular …
burtbeckwith authored
43 String datasourceSuffix = argsMap.datasource ? '_' + argsMap.datasource : ''
44
3e17890 1.1 branch is now trunk
graeme authored
45 def file = new File(filename)
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
46 ant.mkdir dir: file.parentFile
3e17890 1.1 branch is now trunk
graeme authored
47
55b34b5 @burtbeckwith GRAILS-7051 added --datasource option to export ddl for a particular …
burtbeckwith authored
48 def configuration = appCtx.getBean('&sessionFactory' + datasourceSuffix).configuration
3e17890 1.1 branch is now trunk
graeme authored
49
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
50 def schemaExport = new HibernateSchemaExport(configuration)
6af2113 @graemerocher fix for GRAILS-5479 "SchemaExport script has hard-coded configuration…
graemerocher authored
51 .setHaltOnError(true)
52 .setOutputFile(file.path)
53 .setDelimiter(';')
3e17890 1.1 branch is now trunk
graeme authored
54
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
55 String action = export ? "Exporting" : "Generating script to ${file.path}"
55b34b5 @burtbeckwith GRAILS-7051 added --datasource option to export ddl for a particular …
burtbeckwith authored
56 String ds = argsMap.datasource ? "for DataSource '$argsMap.datasource'" : "for the default DataSource"
57 println "$action in environment '$grailsEnv' $ds"
3e17890 1.1 branch is now trunk
graeme authored
58
59 if (export) {
6af2113 @graemerocher fix for GRAILS-5479 "SchemaExport script has hard-coded configuration…
graemerocher authored
60 // 1st drop, warning exceptions
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
61 schemaExport.execute stdout, true, true, false
3e17890 1.1 branch is now trunk
graeme authored
62 schemaExport.exceptions.clear()
63 // then create
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
64 schemaExport.execute stdout, true, false, true
3e17890 1.1 branch is now trunk
graeme authored
65 }
66 else {
67 // generate
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
68 schemaExport.execute stdout, false, false, false
3e17890 1.1 branch is now trunk
graeme authored
69 }
70
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
71 if (schemaExport.exceptions) {
72 def e = schemaExport.exceptions[0]
73 GrailsUtil.deepSanitize e
74 e.printStackTrace()
3e17890 1.1 branch is now trunk
graeme authored
75 }
76 }
77
9618e6a @burtbeckwith removed unnecessary code that rebuilds a configuration since the one …
burtbeckwith authored
78 setDefaultTarget schemaExport
Something went wrong with that request. Please try again.