{"id":16040350,"url":"https://github.com/mathroule/room-delete-entity-sample","last_synced_at":"2025-04-05T06:24:50.589Z","repository":{"id":98988567,"uuid":"275557783","full_name":"mathroule/room-delete-entity-sample","owner":"mathroule","description":null,"archived":false,"fork":false,"pushed_at":"2020-06-28T12:06:09.000Z","size":869,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T14:13:13.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mathroule.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-28T10:08:42.000Z","updated_at":"2020-06-28T12:06:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"4e33157a-8c99-4898-b2df-6049d530e34f","html_url":"https://github.com/mathroule/room-delete-entity-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathroule%2Froom-delete-entity-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathroule%2Froom-delete-entity-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathroule%2Froom-delete-entity-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathroule%2Froom-delete-entity-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathroule","download_url":"https://codeload.github.com/mathroule/room-delete-entity-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247296588,"owners_count":20915659,"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":[],"created_at":"2024-10-08T23:10:37.936Z","updated_at":"2025-04-05T06:24:50.570Z","avatar_url":"https://github.com/mathroule.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Room delete entity sample\n\nSample project to showcase Room not deleting table when an entity is deleted during destructive migration.\n\nTo test the project, run master branch on a device. Then checkout one of the following branch and run it on the same device.\n\n## Delete an entity\nBranch [delete-book-entity](../../tree/delete-book-entity): `Book` entity has been removed from code. The `User` entity columns has been removed.\nRoom will not drop the table during the database destructive migration, it will lead to invalid foreign key constraint, since referenced column has been removed.\n\n### Database schema version 1\n![Database schema version 1](./database-schema-version-1.png)\n\n### Database schema version 2\n![Database schema version 2](./database-schema-version-2.png)\n\n## Convert an entity to a database view\nBranch [convert-book-entity-to-view](../../tree/convert-book-entity-to-view): `Book` entity has been transformed to a database view.\nRoom will not drop the table during the database destructive migration, but will try to delete the view. This lead to crash:\n```\njava.lang.RuntimeException: Unable to start activity ComponentInfo{com.mathroule.sample.room/com.mathroule.sample.room.MainActivity}: android.database.sqlite.SQLiteException: use DROP TABLE to delete table book (code 1 SQLITE_ERROR): , while compiling: DROP VIEW IF EXISTS `book`\n    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)\n    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)\n    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)\n    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)\n    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)\n    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)\n    at android.os.Handler.dispatchMessage(Handler.java:106)\n    at android.os.Looper.loop(Looper.java:193)\n    at android.app.ActivityThread.main(ActivityThread.java:6669)\n    at java.lang.reflect.Method.invoke(Native Method)\n    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)\n    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)\n Caused by: android.database.sqlite.SQLiteException: use DROP TABLE to delete table book (code 1 SQLITE_ERROR): , while compiling: DROP VIEW IF EXISTS `book`\n    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)\n    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)\n    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514)\n    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)\n    at android.database.sqlite.SQLiteProgram.\u003cinit\u003e(SQLiteProgram.java:58)\n    at android.database.sqlite.SQLiteStatement.\u003cinit\u003e(SQLiteStatement.java:31)\n    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1769)\n    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1698)\n    at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:242)\n    at com.mathroule.sample.room.database.SampleDatabase_Impl$1.dropAllTables(SampleDatabase_Impl.java:44)\n    at androidx.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:114)\n    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:124)\n    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:398)\n    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)\n    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)\n    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)\n    at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)\n    at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)\n    at com.mathroule.sample.room.database.SampleDao_Impl.insert(SampleDao_Impl.java:39)\n    at com.mathroule.sample.room.MainActivity.onCreate(MainActivity.kt:19)\n    at android.app.Activity.performCreate(Activity.java:7136)\n    at android.app.Activity.performCreate(Activity.java:7127)\n    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)\n    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)\n    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) \n    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) \n    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) \n    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) \n    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) \n    at android.os.Handler.dispatchMessage(Handler.java:106) \n    at android.os.Looper.loop(Looper.java:193) \n    at android.app.ActivityThread.main(ActivityThread.java:6669) \n    at java.lang.reflect.Method.invoke(Native Method) \n    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) \n    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)\n```\n\n## Generated sample database implementation\n\n| Version 1 | Removed Book entity | Converted Book entity to view |\n|-----------|---------------------|-------------------------------|\n| ![SampleDatabase_Impl](./drop-all-table-version-1.png) | ![SampleDatabase_Impl](./drop-all-table-version-2-removed.png) | ![SampleDatabase_Impl](./drop-all-table-version-2-view.png) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathroule%2Froom-delete-entity-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathroule%2Froom-delete-entity-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathroule%2Froom-delete-entity-sample/lists"}