{"id":13494469,"url":"https://github.com/MatrixDev/Roomigrant","last_synced_at":"2025-03-28T14:31:15.877Z","repository":{"id":41501440,"uuid":"141049575","full_name":"MatrixDev/Roomigrant","owner":"MatrixDev","description":"Automated Android Room ORM migrations generator with compile-time code generation","archived":false,"fork":false,"pushed_at":"2021-04-21T09:09:49.000Z","size":208,"stargazers_count":373,"open_issues_count":4,"forks_count":23,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-31T09:36:52.246Z","etag":null,"topics":["android","database","migration","room-library"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatrixDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-15T18:35:14.000Z","updated_at":"2024-10-02T20:03:14.000Z","dependencies_parsed_at":"2022-09-09T10:20:42.330Z","dependency_job_id":null,"html_url":"https://github.com/MatrixDev/Roomigrant","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixDev%2FRoomigrant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixDev%2FRoomigrant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixDev%2FRoomigrant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixDev%2FRoomigrant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatrixDev","download_url":"https://codeload.github.com/MatrixDev/Roomigrant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246045919,"owners_count":20714872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","database","migration","room-library"],"created_at":"2024-07-31T19:01:25.342Z","updated_at":"2025-03-28T14:31:14.845Z","avatar_url":"https://github.com/MatrixDev.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Roomigrant\n\n[![Release](https://jitpack.io/v/MatrixDev/Roomigrant.svg)](https://jitpack.io/#MatrixDev/Roomigrant)\n![CI-Build](https://github.com/MatrixDev/Roomigrant/workflows/ci-build/badge.svg)\n\nRoomigrant is a helper library to automatically generate Android Room library migrations using compile-time code generation.\n\n# Add to your project\n\nTo add this library into your project:\n\nStep 1. Add a JitPack repository to your root build.gradle:\n\n```groovy\nallprojects {\n    repositories {\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\nStep 2. Add Roomigrant library and compiler dependencies:\n\n```groovy\ndependencies {\n    // Room\n    implementation 'androidx.room:room-runtime:2.2.5'\n    kapt 'androidx.room:room-compiler:2.2.5'\n\n    // Roomigrant\n    implementation 'com.github.MatrixDev.Roomigrant:RoomigrantLib:0.3.4'\n    kapt 'com.github.MatrixDev.Roomigrant:RoomigrantCompiler:0.3.4'\n}\n```\n\nMore info can be found at https://jitpack.io/#MatrixDev/Roomigrant\n\n# How does it work?\n\nRoomigrant uses scheme files created by the Room library and generates migrations base on the difference between them.\nThis means that the Room schema generation must be enabled in the build.gradle file:\n\n```groovy\nandroid {\n    defaultConfig {\n        javaCompileOptions {\n            annotationProcessorOptions {\n                arguments = [\"room.schemaLocation\": \"$projectDir/schemas\".toString()]\n            }\n        }\n    }\n}\n```\n\nAfter that database class should be annotated to enable migrations generation:\n\n```kotlin\n@Database(version = 5, entities = [Object1Dbo::class, Object2Dbo::class])\n@GenerateRoomMigrations\nabstract class Database : RoomDatabase() {\n    // ...\n}\n```\n\nAnd finally migrations can be added to the Room database builder:\n\n```kotlin\nRoom.databaseBuilder(appContext, Database::class.java, \"database.sqlite\")\n\t\t.addMigrations(*Database_Migrations.build())\n\t\t.build()\n```\n\n# Default rules\n\nRoominator will try its best to migrate everything by itself. Its default rules are:\n\n - columns that have new affinity/type will use SQLite's CAST method\n - cells with nullability removed will have default value for theirs affinity/type\n - new columns will be initialized to default values\n -- 0 for INTEGER\n -- 0.0 for REAL\n -- \"\" for TEXT or BLOB\n\nBecause of the SQLite limitations when any change other than adding new column is done:\n - new merge table will be created\n - data copied from original table to merge table\n - original table will be removed\n - merge table will be renamed back to original\n\n# Custom rules\n\nSometimes it will be required to write custom migration rules.\nIt can be done by adding rules classes to GenerateRoomMigrations annotation:\n\n```kotlin\n@Database(version = 5, entities = [Object1Dbo::class, Object2Dbo::class])\n@GenerateRoomMigrations(Rules::class)\nabstract class Database : RoomDatabase() {\n    // ...\n}\n```\n\nRules classes should contain methods annotated with FieldMigrationRule\n\n```kotlin\n// version 3 had Object1Dbo.intVal column\n// version 4 has Object1Dbo.intValRenamed column\n@FieldMigrationRule(version1 = 3, version2 = 4, table = \"Object1Dbo\", field = \"intValRenamed\")\nfun migrate_3_4_Object1Dbo_intVal(): String {\n\treturn \"`Object1Dbo`.`intVal`\"\n}\n```\n\nThe returned value will be injected as-is to the final SQL statement when copying/updating corresponding field.\n\nCustom code can also be invoked before and after each migration:\n\n```kotlin\n@OnMigrationStartRule(version1 = 1, version2 = 2)\nfun migrate_1_2_before(db: SupportSQLiteDatabase, version1: Int, version2: Int) {\n\tval cursor = db.query(\"pragma table_info(Object1Dbo)\")\n\tassert(cursor.count == 1)\n}\n\n@OnMigrationEndRule(version1 = 1, version2 = 2)\nfun migrate_1_2_after(db: SupportSQLiteDatabase, version1: Int, version2: Int) {\n\tval cursor = db.query(\"pragma table_info(Object1Dbo)\")\n\tassert(cursor.count == 3)\n}\n```\n\n# Warning\n\nPlease be careful when changing existing tables - be sure to increment database version before doing so. Otherwise wrong schema will be updated by the Room library and, in result, generated migrations will not be valid.\n\n# Todos\n\n - Add views support\n - Add table and column names escaping\n - Add foreign key support (currently they are completely ignored)\n - Some internal optimizations\n\n# License\n\n```\nMIT License\n\nCopyright (c) 2018 Rostyslav Lesovyi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMatrixDev%2FRoomigrant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMatrixDev%2FRoomigrant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMatrixDev%2FRoomigrant/lists"}