org.flywaydb.core.api.migration.Context Java Examples
The following examples show how to use
org.flywaydb.core.api.migration.Context.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: V2_35_1__Add_teav_btree_index.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void migrate( Context context ) { try (Statement statement = context.getConnection().createStatement()) { statement .execute( "alter table trackedentityattributevalue alter column value set data type varchar(1200)" ); statement.execute( "create index in_trackedentity_attribute_value on trackedentityattributevalue using btree (trackedentityattributeid, lower(value)) " ); } catch ( SQLException e ) { String message = "Could not perform upgrade of table 'trackedentityattributevalue'. " + String.format( "Column 'value' should be altered to data type varchar(%s) and receive a new index. ", TEA_VALUE_MAX_LENGTH ) + String.format( "For more information, please see the following post: '%s'. ", COP_POST_URL ) + String.format( "Error message was: %s", e.getMessage() ); log.warn( message ); } }
Example #2
Source File: V19__CreateUserSessions.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try(Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("user_sessions")) .column(field("user_session_id", SQLDataType.BIGINT.identity(true))) .column(field("user_id", SQLDataType.BIGINT.nullable(false))) .column(field("token", SQLDataType.VARCHAR(36).nullable(false))) .column(field("remote_address", SQLDataType.VARCHAR(255))) .column(field("user_agent", SQLDataType.VARCHAR(255))) .column(field("created_at", SQLDataType.TIMESTAMP.nullable(false))) .constraints( constraint().primaryKey(field("user_session_id")), constraint().unique(field("token")), constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #3
Source File: V8__CreateRolePermissions.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("role_permissions")) .column(field("role_id", SQLDataType.BIGINT.nullable(false))) .column(field("permission_id", SQLDataType.BIGINT.nullable(false))) .constraints( constraint().primaryKey(field("role_id"), field("permission_id")), constraint().foreignKey(field("role_id")).references(table("roles"), field("role_id")).onDeleteCascade(), constraint().foreignKey(field("permission_id")).references(table("permissions"), field("permission_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #4
Source File: V5__CreatePermissions.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("permissions")) .column(field("permission_id", SQLDataType.BIGINT.identity(true))) .column(field("name", SQLDataType.VARCHAR(100).nullable(false))) .column(field("description", SQLDataType.VARCHAR(100).nullable(false))) .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false))) .constraints( constraint().primaryKey(field("permission_id")), constraint().unique(field("name")) ).getSQL(); stmt.execute(ddl); } }
Example #5
Source File: V14__CreateCertificateCredentials.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try(Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("certificate_credentials")) .column(field("user_id", SQLDataType.BIGINT.nullable(false))) .column(field("client_dn", SQLDataType.VARCHAR(150).nullable(false))) .column(field("certificate", SQLDataType.BLOB.nullable(false))) .constraints( constraint().primaryKey(field("user_id")), constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #6
Source File: V15__CreateOidcUsers.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try(Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("oidc_users")) .column(field("oidc_provider_id", SQLDataType.BIGINT.nullable(false))) .column(field("user_id", SQLDataType.BIGINT.nullable(false))) .column(field("oidc_sub", SQLDataType.VARCHAR(255).nullable(false))) .constraints( constraint().primaryKey(field("oidc_provider_id"), field("user_id")), constraint().foreignKey(field("oidc_provider_id")).references(table("oidc_providers"), field("oidc_provider_id")).onDeleteCascade(), constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #7
Source File: V2_35_2__Update_data_sync_job_parameters_with_system_setting_value.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int fetchDataValuesPageSizeFromSystemSettings( final Context context ) throws SQLException { int dataValuesPageSize = 0; String sql = "SELECT value FROM systemsetting WHERE name = '" + DATA_VALUES_SYNC_PAGE_SIZE_KEY +"';"; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( sql ); ) { if ( rs.next() ) { dataValuesPageSize = (Integer) SerializationUtils.deserialize( rs.getBytes( "value" ) ); } log.info( "Value found in SystemSettings: dataValuePageSize: " + dataValuesPageSize ); } return dataValuesPageSize; }
Example #8
Source File: V6__CreateRealms.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("realms")) .column(field("realm_id", SQLDataType.BIGINT.identity(true))) .column(field("name", SQLDataType.VARCHAR(100).nullable(false))) .column(field("url", SQLDataType.VARCHAR(100).nullable(false))) .column(field("application_id", SQLDataType.BIGINT.nullable(false))) .column(field("description", SQLDataType.VARCHAR(100).nullable(false))) .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false))) .constraints( constraint().primaryKey(field("realm_id")), constraint().unique(field("name")), constraint().foreignKey(field("application_id")).references(table("applications"), field("application_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #9
Source File: V2_35_2__Update_data_sync_job_parameters_with_system_setting_value.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int fetchDatavaluesPageSizeFromMetadataSyncJobConfiguration( final Context context ) throws SQLException, JsonProcessingException { int dataValuesPageSize = 0; String sql = "SELECT jobconfigurationid, jsonbjobparameters FROM jobconfiguration " + "WHERE jobtype = '" + JobType.META_DATA_SYNC.name() + "';"; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( sql ); ) { if ( rs.next()) { MetadataSyncJobParameters jobparams = reader .readValue( rs.getString( "jsonbjobparameters" ) ); dataValuesPageSize = jobparams.getDataValuesPageSize(); log.info( "Value found in Metadata sync job configuration: dataValuePageSize: " + dataValuesPageSize ); } } return dataValuesPageSize; }
Example #10
Source File: V18__CreateUserLocks.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try(Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("user_locks")) .column(field("user_id", SQLDataType.BIGINT.nullable(false))) .column(field("lock_level", SQLDataType.VARCHAR(10).nullable(false))) .column(field("locked_at", SQLDataType.TIMESTAMP.nullable(false))) .constraints( constraint().primaryKey(field("user_id")), constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #11
Source File: V4__CreateRoles.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("roles")) .column(field("role_id", SQLDataType.BIGINT.identity(true))) .column(field("name", SQLDataType.VARCHAR(100).nullable(false))) .column(field("description", SQLDataType.VARCHAR(100).nullable(false))) .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false))) .constraints( constraint().primaryKey(field("role_id")), constraint().unique(field("name")) ).getSQL(); stmt.execute(ddl); } }
Example #12
Source File: V7__CreateMemberships.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("memberships")) .column(field("user_id", SQLDataType.BIGINT.nullable(false))) .column(field("group_id", SQLDataType.BIGINT.nullable(false))) .constraints( constraint().primaryKey(field("user_id"), field("group_id")), constraint().foreignKey(field("user_id")).references(table("users"), field("user_id")).onDeleteCascade(), constraint().foreignKey(field("group_id")).references(table("groups"), field("group_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #13
Source File: V9__CreateAssinments.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("assignments")) .column(field("group_id", SQLDataType.BIGINT.nullable(false))) .column(field("role_id", SQLDataType.BIGINT.nullable(false))) .column(field("realm_id", SQLDataType.BIGINT.nullable(false))) .constraints( constraint().primaryKey(field("group_id"), field("role_id"), field("realm_id")), constraint().foreignKey(field("group_id")).references(table("groups"), field("group_id")).onDeleteCascade(), constraint().foreignKey(field("role_id")).references(table("roles"), field("role_id")).onDeleteCascade(), constraint().foreignKey(field("realm_id")).references(table("realms"), field("realm_id")).onDeleteCascade() ).getSQL(); stmt.execute(ddl); } }
Example #14
Source File: V13__CreateOidcProviders.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try(Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("oidc_providers")) .column(field("oidc_provider_id", SQLDataType.BIGINT.identity(true))) .column(field("name", SQLDataType.VARCHAR(100).nullable(false))) .column(field("client_id", SQLDataType.VARCHAR(100).nullable(false))) .column(field("client_secret", SQLDataType.VARCHAR(100).nullable(false))) .column(field("scope", SQLDataType.VARCHAR(100))) .column(field("response_type", SQLDataType.VARCHAR(100))) .column(field("authorization_endpoint", SQLDataType.VARCHAR(100).nullable(false))) .column(field("token_endpoint", SQLDataType.VARCHAR(100).nullable(false))) .column(field("token_endpoint_auth_method", SQLDataType.VARCHAR(10).nullable(false))) .constraints( constraint().primaryKey(field("oidc_provider_id")), constraint().unique(field("name")) ).getSQL(); stmt.execute(ddl); } }
Example #15
Source File: V22__AlterInvitations.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try(Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.alterTable(table("oidc_invitations")) .renameColumn(field("oidc_sub")).to(field("oidc_payload", SQLDataType.CLOB)) .getSQL(); if (create.configuration().dialect() == SQLDialect.MYSQL) { Matcher m = Pattern.compile("\\s+RENAME\\s+COLUMN\\s+(\\w+)\\s+TO\\s+", Pattern.CASE_INSENSITIVE).matcher(ddl); StringBuffer sb = new StringBuffer(); if (m.find()) { m.appendReplacement(sb, " change " + m.group(1) + " "); m.appendTail(sb); sb.append(" text not null"); ddl = sb.toString(); } } stmt.execute(ddl); } }
Example #16
Source File: V3__CreateApplications.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("applications")) .column(field("application_id", SQLDataType.BIGINT.identity(true))) .column(field("name", SQLDataType.VARCHAR(100).nullable(false))) .column(field("virtual_path", SQLDataType.VARCHAR(50).nullable(false))) .column(field("pass_to", SQLDataType.VARCHAR(255).nullable(false))) .column(field("top_page", SQLDataType.VARCHAR(255).nullable(false))) .column(field("description", SQLDataType.VARCHAR(100).nullable(false))) .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false))) .constraints( constraint().primaryKey(field("application_id")), constraint().unique(field("name")), constraint().unique(field("virtual_path")) ).getSQL(); stmt.execute(ddl); } }
Example #17
Source File: V1__CreateUsers.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("users")) .column(field("user_id", SQLDataType.BIGINT.identity(true))) .column(field("account", SQLDataType.VARCHAR(100).nullable(false))) .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false))) .constraints( constraint().primaryKey(field("user_id")), constraint().unique(field("account")) ).getSQL(); stmt.execute(ddl); stmt.execute( create.createIndex(name("idx_users_01")) .on(table("users"), field("account")) .getSQL() ); } }
Example #18
Source File: V2__CreateGroups.java From bouncr with Eclipse Public License 1.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); String ddl = create.createTable(table("groups")) .column(field("group_id", SQLDataType.BIGINT.identity(true))) .column(field("name", SQLDataType.VARCHAR(100).nullable(false))) .column(field("description", SQLDataType.VARCHAR(100).nullable(false))) .column(field("write_protected", SQLDataType.BOOLEAN.nullable(false))) .constraints( constraint().primaryKey(field("group_id")), constraint().unique(field("name")) ).getSQL(); stmt.execute(ddl); } }
Example #19
Source File: R__Hibernate_Sequence.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { logger.info("About to check if mssql hibernate_sequence needs fix from table to a sequence"); try { JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true)); // in case we have old wrongly created table, this command should succeed jdbcTemplate.execute("select 1 from hibernate_sequence"); fixHibernateSequence = true; logger.info("Looks like we have hibernate_sequence table, initiate fix"); } catch (Exception e) { logger.debug("Unable to query hibernate_sequence table, looks like we have a proper sequence", e); } // will result call to get commands from this class and then we choose which ones to run super.migrate(context); }
Example #20
Source File: V2_30_0__Populate_dhis2_schema_if_empty_database.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void migrate( Context context ) throws Exception { try ( Statement select = context.getConnection().createStatement() ) { try ( ResultSet rows = select.executeQuery( CHECK_EMPTY_DB_QUERY ) ) { if ( rows.next() ) { boolean nonEmptyDatabase = rows.getBoolean( 1 ); if ( !nonEmptyDatabase ) { Connection mConnection = context.getConnection(); JdbcSqlFileExecutor runner = new JdbcSqlFileExecutor( mConnection, false, true ); Resource resource = new ClassPathResource( BASE_SCHEMA_SQL_LOCATION ); InputStream resourceInputStream = resource.getInputStream(); runner.runScript( new BufferedReader( new InputStreamReader( resourceInputStream ) ) ); } } } } }
Example #21
Source File: R__Hibernate_Sequence.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@Override public void migrate(Context context) throws Exception { logger.info("About to check if mssql hibernate_sequence needs fix from table to a sequence"); try { JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true)); // in case we have old wrongly created table, this command should succeed jdbcTemplate.execute("select 1 from hibernate_sequence"); fixHibernateSequence = true; logger.info("Looks like we have hibernate_sequence table, initiate fix"); } catch (Exception e) { logger.debug("Unable to query hibernate_sequence table, looks like we have a proper sequence", e); } // will result call to get commands from this class and then we choose which ones to run super.migrate(context); }
Example #22
Source File: V20190406_1__MigrateBugRelation.java From mycollab with GNU Affero General Public License v3.0 | 6 votes |
public void migrate(Context context) { JdbcTemplate jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true)); SimpleJdbcInsert insertOp = new SimpleJdbcInsert(jdbcTemplate).withTableName("m_prj_ticket_relation"); List<Map<String, Object>> rows = jdbcTemplate.queryForList("SELECT * FROM m_tracker_related_bug"); rows.forEach(row -> { Map<String, Object> parameters = new HashMap<>(6); parameters.put("ticketId", row.get("bugid")); parameters.put("ticketType", "Project-Bug"); parameters.put("type", "Project-Bug"); parameters.put("typeId", row.get("relatedid")); parameters.put("rel", row.get("relatetype")); parameters.put("comment", row.get("comment")); insertOp.execute(parameters); }); jdbcTemplate.execute("DROP TABLE `m_tracker_related_bug`;"); }
Example #23
Source File: V004__UPDATE_REVIEWS.java From blog-tutorials with MIT License | 6 votes |
public void migrate(Context context) throws Exception { // either create a Spring JdbcTemplate or use native JDBC // new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), // true)); try (Statement select = context.getConnection().createStatement()) { try (ResultSet rows = select.executeQuery("SELECT id, name, publisher FROM book")) { while (rows.next()) { Long id = rows.getLong(1); String bookName = rows.getString(2); String publisher = rows.getString(3); try (PreparedStatement preparedUpdate = context.getConnection() .prepareStatement("UPDATE book SET name = ?, publisher = ? WHERE id = ?")) { preparedUpdate.setString(1, bookName.toUpperCase()); preparedUpdate.setString(2, publisher.toUpperCase()); preparedUpdate.setLong(3, id); preparedUpdate.executeUpdate(); } } } } }
Example #24
Source File: V2__Add_Descriptions_OriginalDefinition.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Override public void migrate(Context context) throws Exception { runner.execute(context.getConnection(), Arrays.asList( SqlCommand.from(ALTER_STREAM_DEFINITION_TABLE_DESC), SqlCommand.from(ALTER_STREAM_DEFINITION_TABLE_ORIG_DEF), SqlCommand.from(ALTER_TASK_DEFINITION_TABLE), SqlCommand.from(UPDATE_STREAM_DEFINITION_TABLE_ORIG_DEF), SqlCommand.from(CREATE_TASK_METADATA_TABLE), SqlCommand.from(CREATE_TASK_METADATA_SEQUENCE))); }
Example #25
Source File: V2__Add_Descriptions_And_OriginalDefinition.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Override public void migrate(Context context) throws Exception { runner.execute(context.getConnection(), Arrays.asList( SqlCommand.from(ALTER_STREAM_DEFINITION_TABLE_DESC), SqlCommand.from(ALTER_STREAM_DEFINITION_TABLE_ORIG_DEF), SqlCommand.from(ALTER_TASK_DEFINITION_TABLE), SqlCommand.from(UPDATE_STREAM_DEFINITION_TABLE_ORIG_DEF), SqlCommand.from(CREATE_TASK_METADATA_TABLE), SqlCommand.from(CREATE_TASK_METADATA_SEQUENCE), SqlCommand.from(INSERT_TASK_METADATA_SEQUENCE))); }
Example #26
Source File: V1__CreateEmp.java From enkan with Eclipse Public License 1.0 | 5 votes |
@Override public void migrate(Context context) throws Exception { try(Statement stmt = context.getConnection().createStatement()) { stmt.execute("CREATE TABLE emp(" + "emp_no identity," + "name VARCHAR(100)" + ")"); } }
Example #27
Source File: V2_33_13__Migrate_text_based_system_settings_to_use_enums.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void migrate( final Context context ) throws Exception { update( context, "systemsetting", "systemsettingid", "keyCacheStrategy", CacheStrategy.class ); update( context, "systemsetting", "systemsettingid", "keyAnalysisDisplayProperty", DisplayProperty.class ); update( context, "systemsetting", "systemsettingid", "keyAnalysisRelativePeriod", RelativePeriodEnum.class ); update( context, "usersetting", "userinfoid", "keyAnalysisDisplayProperty", DisplayProperty.class ); }
Example #28
Source File: V2_31_4__Add_defaults_for_validationstrategy.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void migrate( Context context ) throws Exception { List<Integer> programStageIds = new ArrayList<>(); String sql = "SELECT programstageid FROM programstage ps JOIN program p ON p.programid = ps.programid " + "WHERE p.type = 'WITHOUT_REGISTRATION'"; try ( Statement stmt = context.getConnection().createStatement(); ResultSet rs = stmt.executeQuery( sql ); ) { while ( rs.next() ) { programStageIds.add( rs.getInt( "programstageid" ) ); } } if( programStageIds.size() > 0 ) { String inStatement = StringUtils.join( programStageIds, "," ); sql = "UPDATE programstage SET validationstrategy = 'ON_UPDATE_AND_INSERT' " + "WHERE programstageid IN (" + inStatement + ")"; try (Statement stmt = context.getConnection().createStatement()) { stmt.executeUpdate( sql ); } } }
Example #29
Source File: V1__CreateDept.java From enkan with Eclipse Public License 1.0 | 5 votes |
@Override public void migrate(Context context) throws Exception { try(Statement stmt = context.getConnection().createStatement()) { stmt.execute("CREATE TABLE dept(" + "dept_no identity," + "name VARCHAR(100)" + ")"); } }
Example #30
Source File: V1__CreateUserLicense.java From bouncr with Eclipse Public License 1.0 | 5 votes |
@Override public void migrate(Context context) throws Exception { Connection connection = context.getConnection(); try (Statement stmt = connection.createStatement()) { DSLContext create = DSL.using(connection); createUserLicense(create, stmt); createLastActivity(create, stmt); } }