All Projects → MatrixDev → Roomigrant

MatrixDev / Roomigrant

Licence: mit
Automated Android Room ORM migrations generator with compile-time code generation

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Roomigrant

Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+2109.74%)
Mutual labels:  migration, database
Dbmigrations
A library for the creation, management, and installation of schema updates for relational databases.
Stars: ✭ 67 (-80.8%)
Mutual labels:  migration, database
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+140.11%)
Mutual labels:  migration, database
Migrations
ProcessWire Migrations module
Stars: ✭ 37 (-89.4%)
Mutual labels:  migration, database
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+563.32%)
Mutual labels:  migration, database
Node Sqlite
SQLite client for Node.js applications with SQL-based migrations API written in Typescript
Stars: ✭ 642 (+83.95%)
Mutual labels:  migration, database
East
node.js database migration tool
Stars: ✭ 53 (-84.81%)
Mutual labels:  migration, database
Evolve
Database migration tool for .NET and .NET Core projects. Inspired by Flyway.
Stars: ✭ 477 (+36.68%)
Mutual labels:  migration, database
Goose
A database migration tool. Supports SQL migrations and Go functions.
Stars: ✭ 2,112 (+505.16%)
Mutual labels:  migration, database
Darwin
Database schema evolution library for Go
Stars: ✭ 112 (-67.91%)
Mutual labels:  migration, database
Laravel Sync Migration
Developer tool helps to sync migrations without refreshing the database
Stars: ✭ 89 (-74.5%)
Mutual labels:  migration, database
Yii2 Migration
Yii 2 Migration Creator And Updater
Stars: ✭ 262 (-24.93%)
Mutual labels:  migration, database
Fluentmigrator
Fluent migrations framework for .NET
Stars: ✭ 2,636 (+655.3%)
Mutual labels:  migration, database
Pgloader
Migrate to PostgreSQL in a single command!
Stars: ✭ 3,754 (+975.64%)
Mutual labels:  migration, database
Atsd Use Cases
Axibase Time Series Database: Usage Examples and Research Articles
Stars: ✭ 335 (-4.01%)
Mutual labels:  database
Lungo
A MongoDB compatible embeddable database and toolkit for Go.
Stars: ✭ 343 (-1.72%)
Mutual labels:  database
Redis Ui
📡 P3X Redis UI is a very functional handy database GUI and works in your pocket on the responsive web or as a desktop app
Stars: ✭ 334 (-4.3%)
Mutual labels:  database
Pgdiff
Compares the PostgreSQL schema between two databases and generates SQL statements that can be run manually against the second database to make their schemas match.
Stars: ✭ 333 (-4.58%)
Mutual labels:  database
R2dbc Client
Reactive Relational Database Connectivity
Stars: ✭ 347 (-0.57%)
Mutual labels:  database
Koa Vue Notes Api
🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and async/await.
Stars: ✭ 342 (-2.01%)
Mutual labels:  database

Roomigrant

Release CI-Build

Roomigrant is a helper library to automatically generate Android Room library migrations using compile-time code generation.

Add to your project

To add this library into your project:

Step 1. Add a JitPack repository to your root build.gradle:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add Roomigrant library and compiler dependencies:

dependencies {
    // Room
    implementation 'androidx.room:room-runtime:2.2.5'
    kapt 'androidx.room:room-compiler:2.2.5'

    // Roomigrant
    implementation 'com.github.MatrixDev.Roomigrant:RoomigrantLib:0.3.4'
    kapt 'com.github.MatrixDev.Roomigrant:RoomigrantCompiler:0.3.4'
}

More info can be found at https://jitpack.io/#MatrixDev/Roomigrant

How does it work?

Roomigrant uses scheme files created by the Room library and generates migrations base on the difference between them. This means that the Room schema generation must be enabled in the build.gradle file:

android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
    }
}

After that database class should be annotated to enable migrations generation:

@Database(version = 5, entities = [Object1Dbo::class, Object2Dbo::class])
@GenerateRoomMigrations
abstract class Database : RoomDatabase() {
    // ...
}

And finally migrations can be added to the Room database builder:

Room.databaseBuilder(appContext, Database::class.java, "database.sqlite")
		.addMigrations(*Database_Migrations.build())
		.build()

Default rules

Roominator will try its best to migrate everything by itself. Its default rules are:

  • columns that have new affinity/type will use SQLite's CAST method
  • cells with nullability removed will have default value for theirs affinity/type
  • new columns will be initialized to default values -- 0 for INTEGER -- 0.0 for REAL -- "" for TEXT or BLOB

Because of the SQLite limitations when any change other than adding new column is done:

  • new merge table will be created
  • data copied from original table to merge table
  • original table will be removed
  • merge table will be renamed back to original

Custom rules

Sometimes it will be required to write custom migration rules. It can be done by adding rules classes to GenerateRoomMigrations annotation:

@Database(version = 5, entities = [Object1Dbo::class, Object2Dbo::class])
@GenerateRoomMigrations(Rules::class)
abstract class Database : RoomDatabase() {
    // ...
}

Rules classes should contain methods annotated with FieldMigrationRule

// version 3 had Object1Dbo.intVal column
// version 4 has Object1Dbo.intValRenamed column
@FieldMigrationRule(version1 = 3, version2 = 4, table = "Object1Dbo", field = "intValRenamed")
fun migrate_3_4_Object1Dbo_intVal(): String {
	return "`Object1Dbo`.`intVal`"
}

The returned value will be injected as-is to the final SQL statement when copying/updating corresponding field.

Custom code can also be invoked before and after each migration:

@OnMigrationStartRule(version1 = 1, version2 = 2)
fun migrate_1_2_before(db: SupportSQLiteDatabase, version1: Int, version2: Int) {
	val cursor = db.query("pragma table_info(Object1Dbo)")
	assert(cursor.count == 1)
}

@OnMigrationEndRule(version1 = 1, version2 = 2)
fun migrate_1_2_after(db: SupportSQLiteDatabase, version1: Int, version2: Int) {
	val cursor = db.query("pragma table_info(Object1Dbo)")
	assert(cursor.count == 3)
}

Todos

  • Add views support
  • Add table and column names escaping
  • Add foreign key support (currently they are completely ignored)
  • Some internal optimizations

License

MIT License

Copyright (c) 2018 Rostyslav Lesovyi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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].