CloseableLiquibaseWithClassPathMigrationsFile( ManagedDataSource dataSource, Database database, String file ) throws LiquibaseException, SQLException { super(file, new ClassLoaderResourceAccessor(), database, dataSource); }
public CloseableLiquibase(ManagedDataSource dataSource, String migrations) throws LiquibaseException, ClassNotFoundException, SQLException { super(migrations, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection())); this.dataSource = dataSource; }
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); } }
@Override public ResourceAccessor create() { return new ClassLoaderResourceAccessor(); } }
/** * A reference to the changelog file. Can be in any format supported by liquibase (currently SQL,Yaml,XML or JSON) * * @param resource a resource that will be read from classpath using Class.getResource(String) * @return the same builder */ public Builder withChangelogResource(final String resource) { this.databaseChangeLog = resource; this.resourceAccessor = new ClassLoaderResourceAccessor(); return this; }
CloseableLiquibaseWithClassPathMigrationsFile( ManagedDataSource dataSource, Database database, String file ) throws LiquibaseException, SQLException { super(file, new ClassLoaderResourceAccessor(), database, dataSource); }
protected ServiceLocator(PackageScanClassResolver classResolver) { this.classResolver = classResolver; setResourceAccessor(new ClassLoaderResourceAccessor()); }
@Produces @LiquibaseType public ResourceAccessor create() { return new ClassLoaderResourceAccessor(getClass().getClassLoader()); } }
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 ServiceLocator() { this.classResolver = defaultClassLoader(); setResourceAccessor(new ClassLoaderResourceAccessor()); }
Class.forName("org.postgresql.Driver"); Connection connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/postgres", "postgres", "123456a@"); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.update(new Contexts(), new LabelExpression());
// 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(""); } }
@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 ); }
@Produces @LiquibaseType public ResourceAccessor create() { return new ClassLoaderResourceAccessor(getClass().getClassLoader()); }
@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); }
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 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()); } }