https://github.com/gitbucket/solidbase
Generic migration tool for RDBMS and other resources based on Liquibase
https://github.com/gitbucket/solidbase
database java liquibase migration
Last synced: 6 months ago
JSON representation
Generic migration tool for RDBMS and other resources based on Liquibase
- Host: GitHub
- URL: https://github.com/gitbucket/solidbase
- Owner: gitbucket
- License: apache-2.0
- Created: 2015-11-06T00:19:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2025-03-22T22:34:41.000Z (7 months ago)
- Last Synced: 2025-04-09T22:18:52.170Z (6 months ago)
- Topics: database, java, liquibase, migration
- Language: Java
- Homepage:
- Size: 135 KB
- Stars: 35
- Watchers: 10
- Forks: 6
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Solidbase [](https://github.com/gitbucket/solidbase/actions?query=workflow%3Abuild+branch%3Amaster) [](https://maven-badges.herokuapp.com/maven-central/io.github.gitbucket/solidbase) [](https://github.com/gitbucket/solidbase/blob/master/LICENSE)
Generic migration tool for RDBMS and other resources based on [Liquibase](http://www.liquibase.org/).
- Multi-database (based on Liquibase)
- Multi-resource (not only RDBMS)
- Multi-module (modules can have their own versions)## Usage
### Add dependency
Add following dependency into your Maven `pom.xml`:
```xml
io.github.gitbucket
solidbase
1.1.0
```
or for Gradle add to `build.gradle`:
```groovy
implementation 'io.github.gitbucket:solidbase:1.0.5'
```
### Define migrationCreate the Liquibase migration xml files under `src/main/resources`. For example:
- `src/main/resources/test_1.0.0.xml`
```xml
```Define migration that migrates RDBMS using these XML files:
```java
import io.github.gitbucket.solidbase.migration.LiquibaseMigration;
import io.github.gitbucket.solidbase.model.Module;
import io.github.gitbucket.solidbase.model.Version;Module module = new Module(
// module id
"test",
// versions (oldest first)
new Version("1.0.0", new LiquibaseMigration("test_1.0.0.xml")),
new Version("1.0.1", new LiquibaseMigration("test_1.0.1.xml")),
...
);
```You can also add a migration for resources other than RDBMS by implementing `Migration` interface.
Added migrations are executed in order.```java
import io.github.gitbucket.solidbase.migration.LiquibaseMigration;
import io.github.gitbucket.solidbase.migration.Migration;new Version("1.0.0",
// At first, migrate RDBMS
new LiquibaseMigration("test_1.0.0.xml"),
// Second, migrate other resources
new Migration(){
@Override
public void migrate(String moduleId, String version, Map context) throws Exception {
...
}
}
);
```### Run
Then, run migration as below:
```java
import io.github.gitbucket.solidbase.SolidBase;
import java.sql.DriverManager;
import liquibase.database.core.H2Database;Solidbase solidbase = new Solidbase();
solidbase.migrate(
DriverManager.getConnection("jdbc:h2:mem:test", "sa", "sa"),
Thread.currentThread().getContextClassLoader(),
new H2Database(),
module
);
```Differences between the current version and the latest version are applied.
### Background
Solidbase creates a following `VERSIONS` table to manage versions automatically:
| Column name | Data type | Not Null |
|:---------------|:-------------|:---------|
| MODULE_ID (PK) | VARCHAR(100) | Yes |
| VERSION | VARCHAR(100) | Yes |Solidbase uses this table to know the current version. When migration of the new version is successful, it updates the version with the new version.
## Migration
### XML migration
`LiquibaseMigration` migrates the database by Liquibase like XML as above.
XML schema is improved from Liquibase to be possible to declare column information as attributes instead of nested elements. And a default variable `${currentDateTime}` is available in the XML:
```xml
```
### SQL migration
`SqlMigration` migrates the database by native SQL.
### Apply RDBMS specific configuration
In the default, `LiquibaseMigration` and `SqlMigration` try to load a file from classpath as following order:1. Specified path with `_${database}` name suffix (if specified)
2. Specified path (if specified)
3. `${moduleId}_${version}_${database}.${extension}`
4. `${moduleId}_${version}.${extension}`It's possible to apply different XML/SQL for each databases by creating multiple files such as `gitbucket_1.0.0_h2.sql` (for H2 database) and `gitbucket_1.0.0_mysql.sql` (for MySQL).
## for Developers
To release arifacts, run the following command:
```
$ mvn deploy -DperformRelease=true -DskipTests
```