All Projects → padarom → java-migrations

padarom / java-migrations

Licence: other
📃 Laravel inspired DBS-independent Database Migrations for Java 8 (work in progress)

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to java-migrations

Postgres Migrations
🐦 A Stack Overflow-inspired PostgreSQL migration library with strict ordering and immutable migrations
Stars: ✭ 161 (+666.67%)
Mutual labels:  database-migrations
migrate
A simple database migration tool.
Stars: ✭ 38 (+80.95%)
Mutual labels:  database-migrations
upscheme
Database migrations and schema updates made easy
Stars: ✭ 737 (+3409.52%)
Mutual labels:  database-migrations
Scala Forklift
Type-safe data migration tool for Slick, Git and beyond.
Stars: ✭ 180 (+757.14%)
Mutual labels:  database-migrations
database-migrations-dotnet
A code example showing 5 ways to manage database schema in .NET
Stars: ✭ 44 (+109.52%)
Mutual labels:  database-migrations
flyway-ant
Flyway Ant tasks
Stars: ✭ 14 (-33.33%)
Mutual labels:  database-migrations
Micrate
Database migration tool written in Crystal
Stars: ✭ 128 (+509.52%)
Mutual labels:  database-migrations
Sane
"Spring Boot for Classic ASP." A powerful and full-featured VBScript MVC framework that brings sanity to Classic ASP development. Use domain & view models, automap model -> view, easily enumerate and introspect, write db migrations, and more. No, seriously.
Stars: ✭ 26 (+23.81%)
Mutual labels:  database-migrations
r2dbc-migrate
R2DBC database migration tool & library
Stars: ✭ 83 (+295.24%)
Mutual labels:  database-migrations
DBTestCompare
Application to compare results of two SQL queries
Stars: ✭ 15 (-28.57%)
Mutual labels:  database-migrations
Obevo
Obevo is a database deployment tool that handles enterprise scale schemas and complexity
Stars: ✭ 192 (+814.29%)
Mutual labels:  database-migrations
Aerich
A database migrations tool for TortoiseORM, ready to production.
Stars: ✭ 240 (+1042.86%)
Mutual labels:  database-migrations
migrant
Migration management for PostgreSQL/SQLite/MySQL
Stars: ✭ 85 (+304.76%)
Mutual labels:  database-migrations
Phinx Migrations Generator
A Migration Code Generator for Phinx
Stars: ✭ 178 (+747.62%)
Mutual labels:  database-migrations
neo4j-migrations
Automated script runner aka "Migrations" for Neo4j. Inspired by Flyway.
Stars: ✭ 82 (+290.48%)
Mutual labels:  database-migrations
Yuniql
Free and open source schema versioning and database migration made natively with .NET Core.
Stars: ✭ 156 (+642.86%)
Mutual labels:  database-migrations
migrations
Migrations is a database migration tool that uses go's database/sql from the standard library
Stars: ✭ 17 (-19.05%)
Mutual labels:  database-migrations
db-migrator.go
DB migrations. CLI and Golang
Stars: ✭ 13 (-38.1%)
Mutual labels:  database-migrations
harmonica
Kotlin Database Migration Tool. This tool makes it really easy to create table, index, add columns, and so on, with Kotlin DSL.
Stars: ✭ 123 (+485.71%)
Mutual labels:  database-migrations
sqflite migration
Library to manage sqlite db migrations.
Stars: ✭ 40 (+90.48%)
Mutual labels:  database-migrations

Migrations

Java Migrations for Java 8. This package is a work in progress.

About this project

I make a living in the world of PHP and love working with the PHP web framework Laravel. One of the many great features it offers are Database Migrations. Their description of it is as follows:

Migrations are like version control for your database, allowing a team to easily modify and share the application's database schema. Migrations are typically paired with Laravel's schema builder to easily build your application's database schema.

For my Java projects I more and more need to use databases, so I thought it would make sense to have a similar tool at hand that allows me to easily create and then run migrations without too much boilerplate code. The other migration tools I've found for Java didn't quite fit my needs, so I decided to write my own, heavily inspired by Laravel's migration and schema builder syntax.

Roadmap

  • Migrations
    • Run migrations within package
    • Run single migrations
    • Rollback all migrations
    • Rollback batch of migrations
    • Rollback individual migrations
    • Create Tables
    • Drop Tables
    • Modify existing tables
    • Rename tables
  • Schema Builder
    • Custom columns
    • Foreign keys
    • Custom indices
    • Pre-defined column definitions for ease of use

Why should you use this?

  • No need to learn library specific markup for XML, YAML or JSON definitions
  • No need to manually write SQL statements
  • Create your database schema using simple, nonverbose Java

What this isn't

Keep in mind that this is not an ORM and not meant to ever become one. There are quasi standards for Java ORMs out there already, so this library focuses solely on setting up your database.

How to use

Define your migration

package path.to.your.migrations;

import io.padarom.migrations.MigrationInterface;
import io.padarom.migrations.Migration;
import io.padarom.migrations.schema.Schema;

@Migration
public class CreateUsersTable implements MigrationInterface {

    @Override
    public void up() {
        Schema.create("users", table -> {
            table.increments("id");
            table.string("name");
            table.string("password");
            table.timestamps();
        });
    }

    @Override
    public void down() {
        Schema.drop("users");
    }
}

You can define the order in which multiple migrations should run by specifying a priority (defaults to 100):

@Migration (priority = 10)
public class CreateFirstTable implements MigrationInterface {
   // ...
}

@Migration (priority = 20)
public class CreateSecondTable implements MigrationInterface {
    // ...
}

Call the Migrator

java.sql.Connection databaseConnection = somehowGetYourDatabaseConnection();

Migrator migrator = new Migrator(databaseConnection, "path.to.your.migrations");
migrator.runAllMigrations();

In this example the migrator automatically creates a DatabaseMigrationRepository, which stores a list of all previously ran migrations within the database, in the table migrations. If you don't want this, you can pass in your own MigrationRepositoryInterface to the migrator's constructor:

DatabaseMigrationRepository repository = new DatabaseMigrationRepository(databaseConnection, "custom_migrations_table");
Migrator migrator = new Migrator(repository, databaseConnection, "path.to.your.migrations");

By doing this you can store the information of which migrations have already run however you'd like.

SQL Flavors

This library works with JDBC. This library uses instances of java.sql.Connection to interact with the database. It will automatically determine the flavor of your DBMS by analyzing the driver's class name. Currently supported, and planned for future support are:

  • SQLite (org.sqlite.JDBC)
  • MySQL (com.mysql.jdbc.Driver)
  • PostgreSQL (org.postgresql.Driver)
  • SqlServer (com.microsoft.sqlserver.jdbc.SQLServerDriver)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].