]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-704: Separate db drop scripts from db create scripts. Run drop scripts only...
authorRay Lee <ray.lee@lyrasis.org>
Fri, 16 Aug 2019 19:26:10 +0000 (12:26 -0700)
committerRay Lee <ray.lee@lyrasis.org>
Fri, 16 Aug 2019 19:26:10 +0000 (12:26 -0700)
build.xml
services/common-api/src/main/java/org/collectionspace/services/common/api/JEEServerDeployment.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
src/main/resources/db/postgresql/drop_cspace_db.sql [new file with mode: 0644]
src/main/resources/db/postgresql/drop_nuxeo_db.sql [new file with mode: 0644]
src/main/resources/db/postgresql/init_cspace_db.sql

index 373cf7730fccaeb5e5b16387cb84ba2cc4309c5a..a2cd3e2b3ac0c1fb5fd53d3d3deb4f226fda71f0 100644 (file)
--- a/build.xml
+++ b/build.xml
                </exec>
        </target>
 
-       <target name="recreate_nuxeo_db" if="${create_db.recreate}" description="recreate nuxeo database">
-               <echo>Recreating nuxeo databases with credentials ${db.csadmin.user}:${db.csadmin.user.password}</echo>
-               <sql driver="${db.jdbc.driver.class}" url="${db.jdbc.csadmin.url}" userid="${db.csadmin.user}" password="${db.csadmin.user.password}" autocommit="true" src="${db.script.dir}/init_nuxeo_db.sql">
+       <target name="drop_nuxeo_db" if="${create_db.recreate}" description="drop nuxeo database">
+               <echo>Dropping nuxeo databases with credentials ${db.csadmin.user}:${db.csadmin.user.password}</echo>
+               <sql driver="${db.jdbc.driver.class}" url="${db.jdbc.csadmin.url}" userid="${db.csadmin.user}" password="${db.csadmin.user.password}" autocommit="true" src="${db.script.dir}/drop_nuxeo_db.sql">
                        <classpath>
                                <pathelement path="${db.driver.jar}" />
                        </classpath>
                </sql>
        </target>
 
-       <target name="create_nuxeo_db" depends="recreate_nuxeo_db">
+       <target name="create_nuxeo_db" depends="drop_nuxeo_db">
                <ant antfile="services/build.xml" target="create_nuxeo_db" inheritAll="false" />
        </target>
 
-       <target name="recreate_cspace_db" if="${create_db.recreate}" description="recreate cspace database">
-               <echo>Recreating the cspace database with credentials ${db.csadmin.user}:${db.csadmin.user.password}</echo>
-               <sql driver="${db.jdbc.driver.class}" url="${db.jdbc.csadmin.url}" userid="${db.csadmin.user}" password="${db.csadmin.user.password}" autocommit="true" src="${db.script.dir}/init_cspace_db.sql">
+       <target name="drop_cspace_db" if="${create_db.recreate}" description="drop cspace database">
+               <echo>Dropping the cspace database with credentials ${db.csadmin.user}:${db.csadmin.user.password}</echo>
+               <sql driver="${db.jdbc.driver.class}" url="${db.jdbc.csadmin.url}" userid="${db.csadmin.user}" password="${db.csadmin.user.password}" autocommit="true" src="${db.script.dir}/drop_cspace_db.sql">
                        <classpath>
                                <pathelement path="${db.driver.jar}" />
                        </classpath>
                </sql>
        </target>
 
-       <target name="create_cspace_db" depends="recreate_cspace_db">
+       <target name="create_cspace_db" depends="drop_cspace_db">
+               <echo>Creating the cspace database with credentials ${db.csadmin.user}:${db.csadmin.user.password}</echo>
+               <!--
+                       The SQL create role/database statements may fail if the cspace role/database already exists. Since the goal of this target
+                       is for the cspace role and database to be created, it's fine if they already exist, so onerror is set to "continue".
+               -->
+               <sql driver="${db.jdbc.driver.class}" url="${db.jdbc.csadmin.url}" userid="${db.csadmin.user}" password="${db.csadmin.user.password}" autocommit="true" src="${db.script.dir}/init_cspace_db.sql" onerror="continue">
+                       <classpath>
+                               <pathelement path="${db.driver.jar}" />
+                       </classpath>
+               </sql>
                <ant antfile="services/build.xml" target="create_cspace_db" inheritAll="false" />
        </target>
 
        <target name="setup_initdb.sql" description="copy init_db scripts, replacing keywords">
                <mkdir dir="${jee.server.cspace}/cspace/services/db/postgresql"/>
                <copy todir="${jee.server.cspace}/cspace/services/db/postgresql">
-                       <fileset dir="${jee.server.cspace}/cspace/services/db/postgresql" includes="init_cspace_db.sql, init_nuxeo_db.sql">
+                       <fileset dir="${jee.server.cspace}/cspace/services/db/postgresql" includes="drop_cspace_db.sql, init_cspace_db.sql, drop_nuxeo_db.sql">
                                <present targetdir="${src}/main/resources/db/postgresql" />
                        </fileset>
                        <globmapper from="*" to="*.bak" />
index 3f6fd9c2463d1ad89789e0b4c3082620b1379455..13cff814cf9861e43bfc4c606914c39617ee4051 100644 (file)
@@ -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";
 }
index ac9024188a457b77164f1bfefc9a5f3db65357c6..4b21b24065abe687e3657669f8f6f3c7b1e0a488 100644 (file)
@@ -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 (file)
index 0000000..9227425
--- /dev/null
@@ -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 (file)
index 0000000..79ca626
--- /dev/null
@@ -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.)
index 41df9d11ba11ad30f74f1befb479bce92d39b878..bdca213ba6e70fd32911492336c3af974771b1bc 100644 (file)
@@ -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;
 
 --