Refine search
public CloseableLiquibase(ManagedDataSource dataSource, String migrations) throws LiquibaseException, ClassNotFoundException, SQLException { super(migrations, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection())); this.dataSource = dataSource; }
DatabaseConnection connection = new JdbcConnection(jdbcConnection); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); Liquibase liquibase = new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database); return liquibase;
@Override public Liquibase getLiquibase(Connection connection, String defaultSchema) throws LiquibaseException { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); if (defaultSchema != null) { database.setDefaultSchemaName(defaultSchema); } String changelog = LiquibaseJpaUpdaterProvider.CHANGELOG; ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(getClass().getClassLoader()); logger.debugf("Using changelog file %s and changelogTableName %s", changelog, database.getDatabaseChangeLogTableName()); return new Liquibase(changelog, resourceAccessor, database); }
private static void migrateDb(Connection conn, String logPath, String logTable, String lockTable) throws Exception { LogFactory.getInstance().setDefaultLoggingLevel(LogLevel.WARNING); Database db = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn)); db.setDatabaseChangeLogTableName(logTable); db.setDatabaseChangeLogLockTableName(lockTable); Liquibase lb = new Liquibase(logPath, new ClassLoaderResourceAccessor(), db); lb.update((String) null); }
/** * Run the migrations in the changelog associated with this entity manager */ private void runMigrations(String changelogFile, String url, String user, String password, String context) { if (changelogFile != null) { try (Connection c = DriverManager.getConnection(url, user, password)) { LOG.info("Running Migrations"); // first run the liquibase migrations against the database Liquibase lb = new Liquibase(changelogFile, new ClassLoaderResourceAccessor(), new JdbcConnection(c)); lb.update(context); } catch (LiquibaseException e) { LOG.log(Level.SEVERE, "Liquibase exception thrown while trying to run migrations", e); } catch (SQLException e) { LOG.log(Level.SEVERE, "SQL Exception thrown while trying to open a connection", e); } } else { LOG.info("No changelog file specified, not running migrations."); } }
ResourceAccessor threadClFO = new ClassLoaderResourceAccessor(contextClassLoader); ResourceAccessor clFO = new ClassLoaderResourceAccessor(); database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); database.setDefaultSchemaName(defaultSchema); Liquibase liquibase = new Liquibase(changeLogFile, resourceAccessor, database); liquibase.setChangeLogParameter(param.getKey(), param.getValue()); List<ChangeSet> unrun = liquibase.listUnrunChangeSets(new Contexts(contexts), new LabelExpression(labels)); database.close(); else if (connection != null) connection.close();
@Override public void execute(Connection conn) { try { JdbcConnection jdbcConn = new JdbcConnection(conn); Database db = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcConn); if (dbType == DbType.ORACLE) { db.setDefaultSchemaName(metaDataUserName); ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(); if (dbType == DbType.DERBY || dbType == DbType.H2 || dbType == DbType.HSQL) { resourceAccessor = new ResourceAccessorFilter(resourceAccessor); Liquibase liquibase = new Liquibase(changeLogResourceName, resourceAccessor, db); liquibase.setChangeLogParameter(key, parameters.get(key)); liquibase.update((String)null); } catch (Exception ex) { throw new JuRuntimeException("Couldn't run Liquibase Update %s", ex, changeLogResourceName);
JdbcConnection connection = new JdbcConnection(c); Database database = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation(connection); Liquibase liquibase = new Liquibase(getMigrationPath(), new ClassLoaderResourceAccessor(), database); .getChangeSetStatuses(new Contexts(), new LabelExpression()); new LiquibaseMigrationWatcher(changesets); liquibase.setChangeExecListener(w); liquibase.update(new Contexts(), new LabelExpression());
public void verify(DataSource ds) { boolean throwException = false; Contexts contexts = new Contexts(""); for(LiquibaseConfiguration c : configs) { try(Connection con = ds.getConnection()) { Database db = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(con)); db.setDatabaseChangeLogLockTableName(c.changeLogLockTableName()); db.setDatabaseChangeLogTableName(c.changeLogTableName()); Liquibase liquibase = new ShureviewNonCreationLiquibase(c.liquibaseResource(), new ClassLoaderResourceAccessor(), db); liquibase.getLog(); liquibase.validate(); List<ChangeSet> listUnrunChangeSets = liquibase.listUnrunChangeSets(contexts, new LabelExpression()); if(!listUnrunChangeSets.isEmpty()) { StringWriter writer = new StringWriter(); liquibase.update(contexts, writer); liquibase.futureRollbackSQL(writer); log.warn(writer.toString()); throwException = true; } } catch (SQLException | LiquibaseException e) { throw new RuntimeException("Failed to verify database.", e); } } if(throwException){ throw new RuntimeException("Unrun changesets in chengelog."); } }
// Create the test database with the LiquiBase migrations. @BeforeClass public static void up() throws Exception { ManagedDataSource ds = RULE.getConfiguration().getMainDataSource().build( RULE.getEnvironment().metrics(), "migrations"); try (Connection connection = ds.getConnection()) { Liquibase migrator = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection)); migrator.update(""); } }
final ConnectionProvider connectionProvider = sessionManager.getPersistenceContext(key, ConnectionProvider.class, null)) { final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation( new JdbcConnection(connectionProvider.provide()) { @Override if(database.supportsCatalogs() && StringUtils.isNotEmpty(catalogName)) { database.setDefaultCatalogName(catalogName); database.setOutputDefaultCatalog(true); final Liquibase liquibase = new Liquibase( changeLogFile, new ClassLoaderResourceAccessor(), database); if (expressionVars != null) { for (Map.Entry<Object, Object> var : expressionVars.entrySet()) { liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());
@Override public Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException { config.refresh(); DatabaseConnection dbConnection = new JdbcConnection( dataSource.get().getConnection() ); return new Liquibase( config.get().changeLog().get(), new ClassLoaderResourceAccessor(), dbConnection ); }
public void upgrade(String filename) throws IOException, SQLException { try { Liquibase liquibase = new Liquibase(filename, new ClassLoaderResourceAccessor(getClass() .getClassLoader()), liqubaseConnection); liquibase.update(null); connection.commit(); } catch (LiquibaseException e) { throw new IOException(e); } }
public Liquibase createLiquibaseInstance(Database database) throws LiquibaseException { return new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database); }
CloseableLiquibaseWithClassPathMigrationsFile( ManagedDataSource dataSource, Database database, String file ) throws LiquibaseException, SQLException { super(file, new ClassLoaderResourceAccessor(), database, dataSource); }
private void migrate(){ DataSourceFactory dataSourceFactory = RULE.getConfiguration().dataSourceFactory; Properties info = new Properties(); info.setProperty("user", dataSourceFactory.getUser()); info.setProperty("password", dataSourceFactory.getPassword()); org.h2.jdbc.JdbcConnection h2Conn = new org.h2.jdbc.JdbcConnection(dataSourceFactory.getUrl(), info); JdbcConnection conn = new JdbcConnection(h2Conn); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(conn); Liquibase liquibase = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), database); String ctx = null; liquibase.update(ctx); }
protected void baseLiquibaseInitialization() { ServiceLocator sl = ServiceLocator.getInstance(); sl.setResourceAccessor(new ClassLoaderResourceAccessor(getClass().getClassLoader())); if (!System.getProperties().containsKey("liquibase.scan.packages")) { if (sl.getPackages().remove("liquibase.core")) { sl.addPackageToScan("liquibase.core.xml"); } if (sl.getPackages().remove("liquibase.parser")) { sl.addPackageToScan("liquibase.parser.core.xml"); } if (sl.getPackages().remove("liquibase.serializer")) { sl.addPackageToScan("liquibase.serializer.core.xml"); } sl.getPackages().remove("liquibase.ext"); sl.getPackages().remove("liquibase.sdk"); String lockPackageName = DummyLockService.class.getPackage().getName(); logger.debugf("Added package %s to liquibase", lockPackageName); sl.addPackageToScan(lockPackageName); } LogFactory.setInstance(new LogWrapper()); // Adding PostgresPlus support to liquibase DatabaseFactory.getInstance().register(new PostgresPlusDatabase()); // Adding newer version of MySQL/MariaDB support to liquibase DatabaseFactory.getInstance().register(new UpdatedMySqlDatabase()); // Change command for creating lock and drop DELETE lock record from it SqlGeneratorFactory.getInstance().register(new CustomInsertLockRecordGenerator()); // Use "SELECT FOR UPDATE" for locking database SqlGeneratorFactory.getInstance().register(new CustomLockDatabaseChangeLogGenerator()); }
@Override public Set<InputStream> getResourcesAsStream(String path) throws IOException { return super.getResourcesAsStream(path.replaceFirst("^target/classes/", "")); }
@Override public Set<String> list(String relativeTo, String path, boolean includeFiles, boolean includeDirectories, boolean recursive) throws IOException { Set<String> contents = super.list(relativeTo, path, includeFiles, includeDirectories, recursive); if ((contents == null) || contents.isEmpty()) { contents = super.list(relativeTo, path.replaceFirst("^target/classes/", ""), includeFiles, includeDirectories, recursive); } return contents; } }
public static void main(String[] args) { try { FormEngine formEngine = FormEngines.getDefaultFormEngine(); DataSource dataSource = formEngine.getFormEngineConfiguration().getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseSchema())) { database.setDefaultSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema()); database.setLiquibaseSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema()); } if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseCatalog())) { database.setDefaultCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog()); database.setLiquibaseCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/flowable/form/db/liquibase/flowable-form-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); liquibase.getDatabase().close(); } catch (Exception e) { e.printStackTrace(); } } }