private void initDatabaseSchema() throws SQLException, LiquibaseException { if (config.hasKey("database.changelog")) { ResourceAccessor resourceAccessor = new FileSystemResourceAccessor(); Database database = DatabaseFactory.getInstance().openDatabase( config.getString("database.url"), config.getString("database.user"), config.getString("database.password"), config.getString("database.driver"), null, null, null, resourceAccessor); Liquibase liquibase = new Liquibase( config.getString("database.changelog"), resourceAccessor, database); liquibase.clearCheckSums(); liquibase.update(new Contexts()); } }
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); } }
return new Liquibase(changeLogFile, new CompositeResourceAccessor(openmrsFO, fsFO), database);
@Override protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException { String changeLog = (changeLogFile == null) ? "" : changeLogFile.trim(); return new Liquibase(changeLog, fo, db); }
@Before public void createTestData() throws Exception { Handle handle = dbiProvider.get().open(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection())); Liquibase liquibase = new Liquibase("singularity_test.sql", new FileSystemResourceAccessor(), database); liquibase.update((String) null); try { database.close(); } catch (Throwable t) { } handle.close(); }
public Liquibase createLiquibaseInstance(Database database) throws LiquibaseException { return new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database); }
public Liquibase createLiquibaseInstance(Database database) throws LiquibaseException { return new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database); }
private Liquibase createLiquibase(final Connection connection) { try { JdbcConnection conn = new JdbcConnection(connection); Database database = resolveDatabase(connection); database.setConnection(conn); if (defaultSchemaName != null) { database.setDefaultSchemaName(defaultSchemaName); } return new Liquibase(changeLog, resourceAccessor, database); } catch (LiquibaseException e) { throw new IllegalStateException("Could not initialize Liquibase", e); } }
protected Liquibase createLiquibase(Connection c) throws LiquibaseException { Liquibase liquibase = new Liquibase(config.getChangeLog(), resourceAccessor, createDatabase(c)); if (config.getParameters() != null) { for(Map.Entry<String, String> entry: config.getParameters().entrySet()) { liquibase.setChangeLogParameter(entry.getKey(), entry.getValue()); } } if (config.isDropFirst()) { liquibase.dropAll(); } return liquibase; }
/** * Construct a liquibase wrapper for sql connection. * Closing the wrapper will not call {@link Connection#close()}. * @param connection database connection * @throws LiquibaseException error */ public LiquibaseWrapper(Connection connection) throws LiquibaseException{ database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); ResourceAccessor ra = new ClassResourceAccessor(LiquibaseWrapper.class); liquibase = new Liquibase(CHANGELOG_RESOURCE, ra, database); }
@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 void applyChangelog( final Connection c, final String contexts, final ResourceAccessor resourceAccessor, final String changelogFile ) throws LiquibaseException { liquibase.Liquibase liquibase = null; final Database database = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation(new JdbcConnection(c)); liquibase = new liquibase.Liquibase(changelogFile, resourceAccessor, database); liquibase.update(contexts); } }
@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 ); }
@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 setUp(LiquibaseBuildDefinition definition) { try { Connection con = getNewConnection(definition); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(con)); ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(); liquibase = new Liquibase(definition.getChangeLogFile(), resourceAccessor, database); LOGGER.info("Setting up database {} on {}", definition.getName(), hostname); liquibase.update(""); closeConnectionQuietly(con); } catch (LiquibaseException | SQLException e) { throw new EnvironmentBuilderException("Database setup has failed", e); } }
@Override public Liquibase getLiquibaseForCustomUpdate(Connection connection, String defaultSchema, String changelogLocation, ClassLoader classloader, String changelogTableName) throws LiquibaseException { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); if (defaultSchema != null) { database.setDefaultSchemaName(defaultSchema); } ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(classloader); database.setDatabaseChangeLogTableName(changelogTableName); logger.debugf("Using changelog file %s and changelogTableName %s", changelogLocation, database.getDatabaseChangeLogTableName()); return new Liquibase(changelogLocation, 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); }
@Test public void shouldLoadInitialDataSetInEmptyDatabase() throws LiquibaseException, SQLException, ClassNotFoundException { // given Class.forName("org.h2.Driver"); conn = DriverManager.getConnection("jdbc:h2:mem:testdata", "sa", ""); database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn)); Liquibase liquibase = new Liquibase("liquibase/auto.db.changelog-initialrun.xml", new ClassLoaderResourceAccessor(), database); //when liquibase.update(new Contexts(), new LabelExpression()); // then must not fail if(conn !=null) { conn.close(); } }
private static void initializeEmptyTables() throws Exception { try (Connection connection = getConnection()) { ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(); JdbcConnection jdbcConnection = new JdbcConnection(connection); Liquibase liquibase = new Liquibase("schema.sql", resourceAccessor, jdbcConnection); liquibase.update(new Contexts()); } }
@Before public void createTestData() throws Exception { Handle handle = dbiProvider.get().open(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection())); Liquibase liquibase = new Liquibase("singularity_test.sql", new FileSystemResourceAccessor(), database); liquibase.update((String) null); try { database.close(); } catch (Throwable t) { } handle.close(); }