diff --git a/forward_engineering/configs/templates.js b/forward_engineering/configs/templates.js index 7553136..81e9238 100644 --- a/forward_engineering/configs/templates.js +++ b/forward_engineering/configs/templates.js @@ -1,5 +1,5 @@ module.exports = { - createSchema: 'CREATE USER ${schemaName} NO AUTHENTICATION', + createSchema: 'CREATE USER${ifNotExists} ${schemaName} NO AUTHENTICATION', comment: '\nCOMMENT ON ${object} ${objectName} IS ${comment};\n', diff --git a/forward_engineering/ddlProvider.js b/forward_engineering/ddlProvider.js index 3d38cbe..f3ab116 100644 --- a/forward_engineering/ddlProvider.js +++ b/forward_engineering/ddlProvider.js @@ -134,15 +134,22 @@ module.exports = (baseProvider, options, app) => { }; }, - createSchema({schemaName, ifNotExist}) { - const schemaStatement = wrapIfNotExists( - assignTemplates(templates.createSchema, { - schemaName: wrapInQuotes(schemaName), - }), + createSchema({schemaName, ifNotExist, dbVersion}) { + const usingTryCatchWrapper = shouldUseTryCatchIfNotExistsWrapper(dbVersion); + const schemaStatement = assignTemplates(templates.createSchema, { + schemaName: wrapInQuotes(schemaName), + ifNotExists: !usingTryCatchWrapper && ifNotExist ? ' IF NOT EXISTS' : '', + }); + + if (!usingTryCatchWrapper) { + return schemaStatement + ';'; + } + + return wrapIfNotExists( + schemaStatement, ifNotExist, 1920, ); - return schemaStatement; }, hydrateColumn({columnDefinition, jsonSchema, schemaData, definitionJsonSchema = {}}) {