-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unfortunately, we manually changed the schema JSON files manually so there was an issue with the old schemas since the identity hashes were different and Room was unable to apply migrations correctly. Now everything should be fine, it was tested via migration tests and also manually to ensure everything works now
- Loading branch information
1 parent
8f41cb0
commit 4373148
Showing
6 changed files
with
33 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 15 additions & 13 deletions
28
data/src/main/java/com/costular/atomtasks/data/database/DatabaseMigrations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
package com.costular.atomtasks.data.database | ||
|
||
import androidx.room.DeleteColumn | ||
import androidx.room.migration.AutoMigrationSpec | ||
import androidx.room.migration.Migration | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
|
||
val MIGRATION_4_5 = object : Migration(4, 5) { | ||
override fun migrate(database: SupportSQLiteDatabase) { | ||
database.execSQL( | ||
override fun migrate(db: SupportSQLiteDatabase) { | ||
db.execSQL( | ||
"CREATE TABLE IF NOT EXISTS `_new_tasks` (`id` INTEGER PRIMARY KEY" + | ||
" AUTOINCREMENT NOT NULL, `created_at` TEXT NOT NULL, `name` TEXT NOT NULL," + | ||
" `date` TEXT NOT NULL, `is_done` INTEGER NOT NULL, `position`" + | ||
" INTEGER NOT NULL DEFAULT 0)", | ||
) | ||
database.execSQL( | ||
db.execSQL( | ||
"INSERT INTO `_new_tasks` (`id`,`created_at`,`name`,`date`," + | ||
"`is_done`) SELECT `id`,`created_at`,`name`,`date`,`is_done` FROM `tasks`", | ||
) | ||
database.execSQL("DROP TABLE `tasks`") | ||
database.execSQL("ALTER TABLE `_new_tasks` RENAME TO `tasks`") | ||
database.execSQL( | ||
db.execSQL("DROP TABLE `tasks`") | ||
db.execSQL("ALTER TABLE `_new_tasks` RENAME TO `tasks`") | ||
db.execSQL( | ||
"UPDATE tasks SET position = (SELECT COUNT ( *) FROM tasks " + | ||
"AS t WHERE t.ID <= tasks.ID);", | ||
) | ||
database.execSQL( | ||
db.execSQL( | ||
"CREATE INDEX IF NOT EXISTS `index_tasks_created_at` " + | ||
"ON `tasks` (`created_at`)", | ||
) | ||
database.execSQL( | ||
db.execSQL( | ||
"CREATE UNIQUE INDEX IF NOT EXISTS `index_tasks_position_date` " + | ||
"ON `tasks` (`position`, `date`)", | ||
) | ||
} | ||
} | ||
|
||
val MIGRATION_6_7 = object : Migration(6, 7) { | ||
val MIGRATION_5_6 = object : Migration(5, 6) { | ||
override fun migrate(db: SupportSQLiteDatabase) { | ||
db.execSQL("DROP INDEX IF EXISTS `index_tasks_created_at`") | ||
db.execSQL("ALTER TABLE reminders DROP COLUMN is_enabled;") | ||
} | ||
} | ||
|
||
@DeleteColumn(tableName = "reminders", columnName = "is_enabled") | ||
internal class MigrationDeleteIsEnabledReminder : AutoMigrationSpec | ||
class Migration6To7Spec : AutoMigrationSpec { | ||
override fun onPostMigrate(db: SupportSQLiteDatabase) { | ||
db.execSQL("DROP INDEX IF EXISTS `index_tasks_created_at`;") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters