Skip to content

Commit

Permalink
Custom schema support
Browse files Browse the repository at this point in the history
  • Loading branch information
ximtech committed Oct 21, 2023
1 parent efa665a commit e6d1546
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ docker run -p 5432:5432 -e PROFILE=docker-dev ximtech/altium-migrator
-e ALTIUM_DB_DATASOURCE='jdbc:postgresql://host.docker.internal:5432/altium-components' \
-e ALTIUM_DB_USERNAME='postgres' \
-e ALTIUM_DB_PASSWORD='postgres' \
-e LIQUIBASE_LIQUIBASE_SCHEMA_NAME=components \
ximtech/altium-migrator:latest
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import liquibase.Contexts;
import liquibase.Liquibase;
import liquibase.database.core.PostgresDatabase;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.LiquibaseException;
import liquibase.resource.DirectoryResourceAccessor;
Expand All @@ -27,6 +28,9 @@ public class LiquibaseMigrationService {
@Value("${migration.root.folder}/${git.repository.directory.name}")
private String migrationRootFolder;

@Value("${db.schema.name}")
private String defaultSchemaName;

private final DataSource dataSource;

@SneakyThrows
Expand All @@ -36,7 +40,10 @@ public void processDataMigration() {
File changelogDirectory = new File(migrationRootFolder);
try (Connection connection = this.dataSource.getConnection()) {
DirectoryResourceAccessor resourceAccessor = new DirectoryResourceAccessor(changelogDirectory);
liquibase = new Liquibase(dbChangelogFileName, resourceAccessor, new JdbcConnection(connection));
PostgresDatabase postgresDatabase = new PostgresDatabase();
postgresDatabase.setConnection(new JdbcConnection(connection));
postgresDatabase.setDefaultSchemaName(defaultSchemaName);
liquibase = new Liquibase(dbChangelogFileName, resourceAccessor, postgresDatabase);
Contexts contexts = new Contexts();
liquibase.update(contexts);
connection.commit();
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ git.repository.url: "https://github.com/ximtech/altium-library"
git.repository.directory.name: "migrations"

migration.root.folder: "src/main/resources/db"
db.changelog.file.name: "db.changelog-master.xml"
db.changelog.file.name: "db.changelog-master.xml"
db.schema.name: ${LIQUIBASE_LIQUIBASE_SCHEMA_NAME:public}

0 comments on commit e6d1546

Please sign in to comment.