From b6165b02ee2145374272cd08ff0ef91f077c3704 Mon Sep 17 00:00:00 2001 From: uvindra Date: Thu, 13 Aug 2015 18:10:28 +0530 Subject: [PATCH] Fixing SQL compatibility issues and automating distribution of migration client --- .../wso2-api-migration-client/pom.xml | 19 ++++++++++++ .../src/assembly/dist.xml | 29 +++++++++++++++++++ .../migration/client/MigrateFrom18to19.java | 8 ++--- .../apimgt/migration/util/Constants.java | 2 -- .../apimgt/migration/util/ResourceUtil.java | 4 +-- .../constraint/{query.sql => drop-fk.sql} | 0 .../18to19Migration/sql-scripts/h2.sql | 4 +-- .../18to19Migration/sql-scripts/mssql.sql | 4 +-- .../18to19Migration/sql-scripts/mysql.sql | 4 +-- .../18to19Migration/sql-scripts/oracle.sql | 4 +-- .../sql-scripts/postgresql.sql | 4 +-- 11 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/assembly/dist.xml rename modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/constraint/{query.sql => drop-fk.sql} (100%) diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/pom.xml b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/pom.xml index 9fdc860205..52b0add516 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/pom.xml +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/pom.xml @@ -90,6 +90,25 @@ + + org.apache.maven.plugins + maven-assembly-plugin + 2.5.3 + + + dist + package + + attached + + + false + src/assembly/dist.xml + wso2-api-migration-client + + + + diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/assembly/dist.xml b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/assembly/dist.xml new file mode 100644 index 0000000000..88ddad5f7e --- /dev/null +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/assembly/dist.xml @@ -0,0 +1,29 @@ + + dist + + zip + + false + + + ${project.basedir}/src/main/resources/18to19Migration/sql-scripts/constraint/drop-fk.sql + migration-scripts/18-19-migration + + + + + ${project.basedir}/src/main/resources/18to19Migration/sql-scripts + migration-scripts/18-19-migration + + *.sql + + + + ${project.build.directory} + + + *.jar + + + + \ No newline at end of file diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/client/MigrateFrom18to19.java b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/client/MigrateFrom18to19.java index 5d13e21bf4..0641315d4f 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/client/MigrateFrom18to19.java +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/client/MigrateFrom18to19.java @@ -168,7 +168,7 @@ private void populateTenants(TenantManager tenantManager, List tenantLis */ @Override public void databaseMigration(String migrateVersion) throws SQLException { - log.info("Database migration for API Manager 1.8.0 started"); + log.info("Database migration for API Manager " + Constants.VERSION_1_9 + " started"); Connection connection = null; PreparedStatement preparedStatement = null; BufferedReader bufferedReader = null; @@ -312,7 +312,7 @@ public void registryResourceMigration() throws APIMigrationException { * @throws APIMigrationException */ void rxtMigration() throws APIMigrationException { - log.info("Rxt migration for API Manager 1.9.0 started."); + log.info("Rxt migration for API Manager " + Constants.VERSION_1_9 + " started."); boolean isTenantFlowStarted = false; for (Tenant tenant : tenantsArray) { log.debug("Start rxtMigration for tenant " + tenant.getId() + "(" + tenant.getDomain() + ")"); @@ -446,7 +446,7 @@ void copyNewRxtFileToRegistry() throws APIMigrationException { * @throws APIMigrationException */ void swaggerResourceMigration() throws APIMigrationException { - log.info("Swagger migration for API Manager 1.9.0 started."); + log.info("Swagger migration for API Manager " + Constants.VERSION_1_9 + " started."); boolean isTenantFlowStarted = false; for (Tenant tenant : tenantsArray) { @@ -944,7 +944,7 @@ private static JSONObject generatePathsObj(Map apiDefinitionP */ @Override public void cleanOldResources() throws APIMigrationException { - log.info("Resource cleanup started for API Manager 1.9.0"); + log.info("Resource cleanup started for API Manager " + Constants.VERSION_1_9); try { for (Tenant tenant : tenantsArray) { PrivilegedCarbonContext.startTenantFlow(); diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/Constants.java b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/Constants.java index 8734c18fb0..6416abd0ff 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/Constants.java +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/Constants.java @@ -18,8 +18,6 @@ public class Constants { - public static final String VERSION_1_7 = "1.7"; - public static final String VERSION_1_8 = "1.8"; public static final String VERSION_1_9 = "1.9"; public static final String LINE_BREAK = "\\n"; public static final String CONSTRAINT = "constraint"; diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/ResourceUtil.java b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/ResourceUtil.java index 7ae9cece53..12843caa10 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/ResourceUtil.java +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/java/org/wso2/carbon/apimgt/migration/util/ResourceUtil.java @@ -109,13 +109,13 @@ public static String pickQueryFromResources(String migrateVersion, String queryT if (Constants.VERSION_1_9.equalsIgnoreCase(migrateVersion)) { //pick from 18to19Migration/sql-scripts - resourcePath = CarbonUtils.getCarbonHome() + "/migration-scripts/18-19-migration/"; + resourcePath = CarbonUtils.getCarbonHome() + File.separator + "migration-scripts" + File.separator + "18-19-migration" + File.separator; } else { throw new APIMigrationException("No query picked up for the given migrate version. Please check the migrate version."); } if (Constants.CONSTRAINT.equals(queryType)) { - resourcePath = CarbonUtils.getCarbonHome() + "/migration-scripts/18-19-migration/"; + resourcePath = CarbonUtils.getCarbonHome() + File.separator + "migration-scripts" + File.separator + "18-19-migration" + File.separator; //queryTobeExecuted = resourcePath + "drop-fk.sql"; queryTobeExecuted = IOUtils.toString(new FileInputStream(new File(resourcePath + "drop-fk.sql")), "UTF-8"); } else { diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/constraint/query.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/constraint/drop-fk.sql similarity index 100% rename from modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/constraint/query.sql rename to modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/constraint/drop-fk.sql diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/h2.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/h2.sql index e45dfb2b0e..715dc21948 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/h2.sql +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/h2.sql @@ -11,8 +11,8 @@ ALTER TABLE AM_APPLICATION_REGISTRATION ADD INPUTS VARCHAR(256); ALTER TABLE AM_APPLICATION ADD GROUP_ID VARCHAR(100); ALTER TABLE AM_API ADD CONTEXT_TEMPLATE VARCHAR(256); UPDATE AM_API SET CONTEXT_TEMPLATE = CONTEXT WHERE CONTEXT_TEMPLATE IS NULL; -UPDATE AM_API SET CONTEXT = concat(CONTEXT,'/',API_VERSION) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); -UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, ' ', 'am_application_scope') WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; +UPDATE AM_API SET CONTEXT = concat(CONTEXT,concat('/',API_VERSION)) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); +UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, concat(' ', 'am_application_scope')) WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; UPDATE IDN_OAUTH2_ACCESS_TOKEN SET VALIDITY_PERIOD = -2000 WHERE VALIDITY_PERIOD = 9223372036854775807; ALTER TABLE AM_API ADD CREATED_BY VARCHAR(100); ALTER TABLE AM_API ADD CREATED_TIME TIMESTAMP; diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mssql.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mssql.sql index 77aa5023e0..ff4a631f0f 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mssql.sql +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mssql.sql @@ -6,8 +6,8 @@ ALTER TABLE AM_APPLICATION_REGISTRATION ADD TOKEN_SCOPE VARCHAR(256) DEFAULT 'de ALTER TABLE AM_APPLICATION_REGISTRATION ADD INPUTS VARCHAR(256); ALTER TABLE AM_API_LC_EVENT ALTER COLUMN USER_ID VARCHAR(255) NOT NULL; UPDATE AM_API SET CONTEXT_TEMPLATE = CONTEXT WHERE CONTEXT_TEMPLATE IS NULL; -UPDATE AM_API SET CONTEXT = concat(CONTEXT,'/',API_VERSION) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); -UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, ' ', 'am_application_scope') WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; +UPDATE AM_API SET CONTEXT = CONTEXT + '/' + API_VERSION WHERE CONTEXT NOT LIKE '%' + API_VERSION; +UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = TOKEN_SCOPE + ' ' + 'am_application_scope' WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; UPDATE IDN_OAUTH2_ACCESS_TOKEN SET VALIDITY_PERIOD = -2000 WHERE VALIDITY_PERIOD = 9223372036854775807; ALTER TABLE AM_API ADD CREATED_BY VARCHAR(100), CREATED_TIME DATETIME, UPDATED_BY VARCHAR(100), UPDATED_TIME DATETIME; ALTER TABLE AM_SUBSCRIBER ADD CREATED_BY VARCHAR(100), CREATED_TIME DATETIME, UPDATED_BY VARCHAR(100), UPDATED_TIME DATETIME; diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mysql.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mysql.sql index b9e1c95aaa..c40ed2fc35 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mysql.sql +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/mysql.sql @@ -11,8 +11,8 @@ ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN MODIFY COLUMN TOKEN_SCOPE VARCHAR(767); ALTER TABLE AM_SUBSCRIBER MODIFY COLUMN USER_ID VARCHAR(255); ALTER TABLE AM_API ADD CONTEXT_TEMPLATE VARCHAR(256); UPDATE AM_API SET CONTEXT_TEMPLATE = CONTEXT WHERE CONTEXT_TEMPLATE IS NULL; -UPDATE AM_API SET CONTEXT = concat(CONTEXT,'/',API_VERSION) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); -UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, ' ', 'am_application_scope') WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; +UPDATE AM_API SET CONTEXT = concat(CONTEXT,concat('/',API_VERSION)) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); +UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, concat(' ', 'am_application_scope')) WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; UPDATE IDN_OAUTH2_ACCESS_TOKEN SET VALIDITY_PERIOD = -2000 WHERE VALIDITY_PERIOD = 9223372036854775807; ALTER TABLE AM_API ADD (CREATED_BY VARCHAR(100), CREATED_TIME TIMESTAMP, UPDATED_BY VARCHAR(100), UPDATED_TIME TIMESTAMP); ALTER TABLE AM_SUBSCRIBER ADD (CREATED_BY VARCHAR(100), CREATED_TIME TIMESTAMP, UPDATED_BY VARCHAR(100), UPDATED_TIME TIMESTAMP); diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/oracle.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/oracle.sql index 629fd991b5..a02d48f1a4 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/oracle.sql +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/oracle.sql @@ -7,8 +7,8 @@ ALTER TABLE AM_APPLICATION MODIFY NAME VARCHAR2(100); ALTER TABLE AM_SUBSCRIBER MODIFY USER_ID VARCHAR2(255); ALTER TABLE AM_API ADD CONTEXT_TEMPLATE VARCHAR2(256); UPDATE AM_API SET CONTEXT_TEMPLATE = CONTEXT WHERE CONTEXT_TEMPLATE IS NULL; -UPDATE AM_API SET CONTEXT = concat(CONTEXT,'/',API_VERSION) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); -UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, ' ', 'am_application_scope') WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; +UPDATE AM_API SET CONTEXT = concat(CONTEXT,concat('/',API_VERSION)) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); +UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, concat(' ', 'am_application_scope')) WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; UPDATE IDN_OAUTH2_ACCESS_TOKEN SET VALIDITY_PERIOD = -2000 WHERE VALIDITY_PERIOD = 9223372036854775807; ALTER TABLE AM_API ADD (CREATED_BY VARCHAR2(100), CREATED_TIME DATE, UPDATED_BY VARCHAR2(100), UPDATED_TIME DATE); ALTER TABLE AM_SUBSCRIBER ADD (CREATED_BY VARCHAR2(100), CREATED_TIME DATE, UPDATED_BY VARCHAR2(100), UPDATED_TIME DATE); diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/postgresql.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/postgresql.sql index d69615841b..e1456b5613 100644 --- a/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/postgresql.sql +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/wso2-api-migration-client/src/main/resources/18to19Migration/sql-scripts/postgresql.sql @@ -7,8 +7,8 @@ ALTER TABLE AM_APPLICATION_REGISTRATION ADD COLUMN INPUTS VARCHAR(256); ALTER TABLE AM_API_LC_EVENT ALTER COLUMN USER_ID TYPE VARCHAR(255); ALTER TABLE AM_API_LC_EVENT ALTER COLUMN USER_ID SET NOT NULL; UPDATE AM_API SET CONTEXT_TEMPLATE = CONTEXT WHERE CONTEXT_TEMPLATE IS NULL; -UPDATE AM_API SET CONTEXT = concat(CONTEXT,'/',API_VERSION) WHERE CONTEXT NOT LIKE concat('%', API_VERSION); -UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = concat(TOKEN_SCOPE, ' ', 'am_application_scope') WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; +UPDATE AM_API SET CONTEXT = CONTEXT || '/' || API_VERSION WHERE CONTEXT NOT LIKE '%' || API_VERSION; +UPDATE IDN_OAUTH2_ACCESS_TOKEN SET TOKEN_SCOPE = TOKEN_SCOPE || ' ' || 'am_application_scope' WHERE USER_TYPE = 'APPLICATION' AND TOKEN_SCOPE NOT LIKE '%am_application_scope%'; UPDATE IDN_OAUTH2_ACCESS_TOKEN SET VALIDITY_PERIOD = -2000 WHERE VALIDITY_PERIOD = 9223372036854775807; ALTER TABLE AM_API ADD CREATED_BY VARCHAR(100), ADD CREATED_TIME DATE, ADD UPDATED_BY VARCHAR(100), ADD UPDATED_TIME DATE; ALTER TABLE AM_SUBSCRIBER ADD CREATED_BY VARCHAR(100), ADD CREATED_TIME DATE, ADD UPDATED_BY VARCHAR(100), ADD UPDATED_TIME DATE;