{"id":3734,"date":"2011-05-04T00:49:07","date_gmt":"2011-05-03T19:19:07","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3734"},"modified":"2011-05-04T00:52:19","modified_gmt":"2011-05-03T19:22:19","slug":"grails-domain-class-and-ddl-sql-file-using-schema-export","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/","title":{"rendered":"Grails domain class and DDL sql file using schema-export"},"content":{"rendered":"<p>While debugging a domain and its database schema I found an interesting <code>grails command line Gant script<\/code>: <a href=\"http:\/\/www.grails.org\/doc\/latest\/ref\/Command%20Line\/schema-export.html\" target=\"_blank\"><strong>schema-expor<\/strong>t<\/a>.<\/p>\n<p>One of the great <code>Grails command line Gant script<\/code> to generate<code> SQL scripts(DDL) <\/code> which is executed against your database to model your <code>grails domain<\/code>. You can control the environment and the output file to generate the SQL script. Without going into much details lets see an example. Here is the only domain in my <code>grails project<\/code> :<\/p>\n<p>[groovy]<br \/>\nClass Person{<br \/>\n\tString name<br \/>\n\tInteger age<\/p>\n<p>static hasMany=[emails:String]<br \/>\n}<br \/>\n[\/groovy]<\/p>\n<p>And here is the script I used<\/p>\n<p>[shell]<br \/>\ngrails schema-export<br \/>\n[\/shell]<\/p>\n<p>Here is the content of generated DDL file which is created in project&#8217;s target folder with name ddl.sql by default(obviously data source settings of Development environment).<\/p>\n<p>[sql]<br \/>\nalter table person_emails drop foreign key FKADA31081669C99A9;<br \/>\ndrop table if exists person;<br \/>\ndrop table if exists person_emails;<br \/>\ncreate table person (id bigint not null auto_increment, version bigint not null, name varchar(255) not null, primary key (id)) ENGINE=InnoDB;<br \/>\ncreate table person_emails (person_id bigint, emails_string varchar(255)) ENGINE=InnoDB;<br \/>\nalter table person_emails add index FKADA31081669C99A9 (person_id), add constraint FKADA31081669C99A9 foreign key (person_id) references person (id);<br \/>\n[\/sql]<\/p>\n<p>You can also specify the environment (e.g. <code>prod<\/code>) whose <code>data source<\/code> settings will be used to generate DDL and output to a different file(e.g. <code>prodDDL.sql<\/code>) like :<\/p>\n<p>[shell]<br \/>\ngrails prod schema-export prodDDL.sql<br \/>\n[\/shell]<\/p>\n<p>Full documentation ca be found here <a href=\"http:\/\/www.grails.org\/doc\/latest\/ref\/Command%20Line\/schema-export.html\" target=\"_blank\"><strong>schema-expor<\/strong>t<\/a>.<\/p>\n<p>Hope it encourage you to read the <strong><a href=\"http:\/\/www.grails.org\/doc\/latest\/\">Grails documentation<\/a><\/strong> in spare time to find and share <strong>hidden features of grails<\/strong>.<\/p>\n<p>~~~~Cheers ~~~~<\/p>\n<p>Bhagwat Kumar<br \/>\nbhagwat(at)intelligrape(dot)com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Grails Schema-export GANT script to generate DDL sql file of the grails project domains.<\/p>\n<p>eg.<br \/>\n   grails prod schema-export myProd.sql<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":15,"footnotes":""},"categories":[7],"tags":[563,562,561,559,4840,560,558],"class_list":["post-3734","post","type-post","status-publish","format-standard","hentry","category-grails","tag-datasource","tag-domain-ddl","tag-environment","tag-gant-script","tag-grails","tag-schema-export","tag-sql"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Bhagwat Kumar\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#article\",\"name\":\"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog\",\"headline\":\"Grails domain class and DDL sql file using schema-export\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2011-05-04T00:49:07+05:30\",\"dateModified\":\"2011-05-04T00:52:19+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#webpage\"},\"articleSection\":\"Grails, datasource, domain DDL, environment, GANT script, Grails, schema-export, SQL\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#listItem\",\"name\":\"Grails domain class and DDL sql file using schema-export\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#listItem\",\"position\":3,\"name\":\"Grails domain class and DDL sql file using schema-export\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/\",\"name\":\"Bhagwat Kumar\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d6c506f803fe26906ef802b1eaee463146e449a8b5b3d1f7e4ebc715b933d620?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Bhagwat Kumar\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/\",\"name\":\"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog\",\"description\":\"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/grails-domain-class-and-ddl-sql-file-using-schema-export\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/bhagwat\\\/#author\"},\"datePublished\":\"2011-05-04T00:49:07+05:30\",\"dateModified\":\"2011-05-04T00:52:19+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog","description":"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql","canonical_url":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#article","name":"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog","headline":"Grails domain class and DDL sql file using schema-export","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2011-05-04T00:49:07+05:30","dateModified":"2011-05-04T00:52:19+05:30","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#webpage"},"articleSection":"Grails, datasource, domain DDL, environment, GANT script, Grails, schema-export, SQL"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/www.tothenew.com\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#listItem","name":"Grails domain class and DDL sql file using schema-export"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#listItem","position":3,"name":"Grails domain class and DDL sql file using schema-export","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/","name":"Bhagwat Kumar","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d6c506f803fe26906ef802b1eaee463146e449a8b5b3d1f7e4ebc715b933d620?s=96&d=mm&r=g","width":96,"height":96,"caption":"Bhagwat Kumar"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/","name":"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog","description":"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/bhagwat\/#author"},"datePublished":"2011-05-04T00:49:07+05:30","dateModified":"2011-05-04T00:52:19+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog","og:description":"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql","og:url":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Grails domain class and DDL sql file using schema-export | TO THE NEW Blog","twitter:description":"Grails Schema-export GANT script to generate DDL sql file of the grails project domains. eg. grails prod schema-export myProd.sql","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"3734","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 18:10:53","updated":"2024-02-29 09:29:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGrails domain class and DDL sql file using schema-export\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Grails","link":"https:\/\/www.tothenew.com\/blog\/category\/grails\/"},{"label":"Grails domain class and DDL sql file using schema-export","link":"https:\/\/www.tothenew.com\/blog\/grails-domain-class-and-ddl-sql-file-using-schema-export\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3734"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3734\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}