From: Ray Lee Date: Fri, 16 Aug 2019 19:26:10 +0000 (-0700) Subject: DRYD-704: Separate db drop scripts from db create scripts. Run drop scripts only... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=fbc445a974889058bf80524c1ea330a3af5c5008;p=tmp%2Fjakarta-migration.git DRYD-704: Separate db drop scripts from db create scripts. Run drop scripts only when recreate_db is true; always run create scripts. --- diff --git a/build.xml b/build.xml index 373cf7730..a2cd3e2b3 100644 --- a/build.xml +++ b/build.xml @@ -255,29 +255,39 @@ - - Recreating nuxeo databases with credentials ${db.csadmin.user}:${db.csadmin.user.password} - + + Dropping nuxeo databases with credentials ${db.csadmin.user}:${db.csadmin.user.password} + - + - - Recreating the cspace database with credentials ${db.csadmin.user}:${db.csadmin.user.password} - + + Dropping the cspace database with credentials ${db.csadmin.user}:${db.csadmin.user.password} + - + + Creating the cspace database with credentials ${db.csadmin.user}:${db.csadmin.user.password} + + + + + + @@ -298,7 +308,7 @@ - + diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/JEEServerDeployment.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/JEEServerDeployment.java index 3f6fd9c24..13cff814c 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/JEEServerDeployment.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/JEEServerDeployment.java @@ -21,21 +21,21 @@ public interface JEEServerDeployment { public final static String NUXEO_SERVER_DIR = "nuxeo-server"; public final static String NUXEO_CONFIG_DIR = CONFIG_DIR_NAME; public final static String NUXEO_SERVER_CONFIG_DIR = NUXEO_SERVER_DIR + File.separator + NUXEO_CONFIG_DIR; - + // The file name parts for a Nuxeo repository configuration file. These end up in tomcat/nuxeo-server/config dir public final static String NUXEO_REPO_CONFIG_FILENAME_SUFFIX = "-repo-config.xml"; public final static String NUXEO_PROTOTYPE_REPO_CONFIG_FILENAME = "proto" + NUXEO_REPO_CONFIG_FILENAME_SUFFIX; - - // The file name parts for a Nuxeo datasource configuration file. These end up in tomcat/nuxeo-server/config dir + + // The file name parts for a Nuxeo datasource configuration file. These end up in tomcat/nuxeo-server/config dir public final static String NUXEO_DATASOURCE_CONFIG_FILENAME_SUFFIX = "-datasource-config.xml"; public final static String NUXEO_PROTOTYPE_DATASOURCE_FILENAME = "proto" + NUXEO_DATASOURCE_CONFIG_FILENAME_SUFFIX; - + // The file name parts for Nuxeo's Elasticsearch configuration - public final static String NUXEO_ELASTICSEARCH_CONFIG_FILENAME = "elasticsearch-config.xml"; + public final static String NUXEO_ELASTICSEARCH_CONFIG_FILENAME = "elasticsearch-config.xml"; public final static String NUXEO_PROTO_ELASTICSEARCH_CONFIG_FILENAME = "proto-" + NUXEO_ELASTICSEARCH_CONFIG_FILENAME; public final static String NUXEO_PROTO_ELASTICSEARCH_EXTENSION_FILENAME = "proto-elasticsearch-extension.xml"; - + public final static String NUXEO_PLUGINS_DIR = "plugins"; public final static String NUXEO_SERVER_PLUGINS_DIR = NUXEO_SERVER_DIR + File.separator + NUXEO_PLUGINS_DIR; - public final static String NUXEO_DB_INIT_SCRIPT_FILENAME = "init_nuxeo_db.sql"; + public final static String NUXEO_DB_DROP_SCRIPT_FILENAME = "drop_nuxeo_db.sql"; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index ac9024188..4b21b2406 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -196,7 +196,7 @@ public class ServiceMain { // to include DROP statements for each of the Nuxeo-managed // database names and for each relevant datasource user. String[] dataSourceNames = {JDBCTools.NUXEO_DATASOURCE_NAME, JDBCTools.NUXEO_READER_DATASOURCE_NAME}; - updateInitializationScript(getNuxeoDatabasesInitScriptFilename(), + updateInitializationScript(getNuxeoDatabasesDropScriptFilename(), dbsCheckedOrCreated, dataSourceNames); // @@ -642,9 +642,9 @@ public class ServiceMain { * @return the full path to the Nuxeo databases initialization script file. * Returns an empty String for the path if the database scripts path is null or empty. */ - private String getNuxeoDatabasesInitScriptFilename() { + private String getNuxeoDatabasesDropScriptFilename() { return Tools.notBlank(getDatabaseScriptsPath()) ? - getDatabaseScriptsPath() + File.separator + JEEServerDeployment.NUXEO_DB_INIT_SCRIPT_FILENAME : ""; + getDatabaseScriptsPath() + File.separator + JEEServerDeployment.NUXEO_DB_DROP_SCRIPT_FILENAME : ""; } /** diff --git a/src/main/resources/db/postgresql/drop_cspace_db.sql b/src/main/resources/db/postgresql/drop_cspace_db.sql new file mode 100644 index 000000000..9227425ce --- /dev/null +++ b/src/main/resources/db/postgresql/drop_cspace_db.sql @@ -0,0 +1,4 @@ +-- drop all the objects before dropping roles +DROP database IF EXISTS @DB_CSPACE_NAME@; + +DROP user IF EXISTS @DB_CSPACE_USER@; diff --git a/src/main/resources/db/postgresql/drop_nuxeo_db.sql b/src/main/resources/db/postgresql/drop_nuxeo_db.sql new file mode 100644 index 000000000..79ca626cb --- /dev/null +++ b/src/main/resources/db/postgresql/drop_nuxeo_db.sql @@ -0,0 +1,7 @@ + +-- drop_nuxeo_db.sql + +-- Beginning with CollectionSpace version 4.1, the contents of the deployed +-- copy of this file are no longer static. Rather, that file's contents are +-- now written during each CollectionSpace system startup, via Services +-- layer code. (Code-written contents appear at the top of that file.) diff --git a/src/main/resources/db/postgresql/init_cspace_db.sql b/src/main/resources/db/postgresql/init_cspace_db.sql index 41df9d11b..bdca213ba 100644 --- a/src/main/resources/db/postgresql/init_cspace_db.sql +++ b/src/main/resources/db/postgresql/init_cspace_db.sql @@ -1,8 +1,3 @@ --- drop all the objects before dropping roles -DROP database IF EXISTS @DB_CSPACE_NAME@; - -DROP USER IF EXISTS @DB_CSPACE_USER@; - CREATE ROLE @DB_CSPACE_USER@ WITH PASSWORD '@DB_CSPACE_PASSWORD@' LOGIN; --