-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Resolved database migration crashes and improved App Core Manager
- Addressed issues causing crashes during database migrations. - Enhanced the App Core Manager for improved stability and performance.
- Loading branch information
Mihai-Cristian Condrea
committed
Dec 27, 2024
1 parent
0a3c101
commit 7b44b5f
Showing
15 changed files
with
292 additions
and
188 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
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
85 changes: 85 additions & 0 deletions
85
app/src/main/kotlin/com/d4rk/androidtutorials/data/database/migrations/Migrations.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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.d4rk.androidtutorials.data.database.migrations | ||
|
||
import androidx.room.migration.Migration | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
|
||
val MIGRATION_1_2 : Migration = object : Migration(1 , 2) { | ||
override fun migrate(db : SupportSQLiteDatabase) { | ||
db.execSQL( | ||
sql = """ | ||
CREATE TABLE IF NOT EXISTS `Favorite Lessons_new` ( | ||
`lessonId` TEXT PRIMARY KEY NOT NULL, | ||
`lessonTitle` TEXT NOT NULL, | ||
`lessonDescription` TEXT NOT NULL, | ||
`lessonType` TEXT NOT NULL, | ||
`lessonTags` TEXT NOT NULL, | ||
`thumbnailImageUrl` TEXT NOT NULL, | ||
`squareImageUrl` TEXT NOT NULL, | ||
`deepLinkPath` TEXT NOT NULL, | ||
`isFavorite` INTEGER NOT NULL | ||
) | ||
""".trimIndent() | ||
) | ||
|
||
db.execSQL( | ||
sql = """ | ||
INSERT INTO `Favorite Lessons_new` ( | ||
`lessonId`, `lessonTitle`, `lessonDescription`, `lessonType`, | ||
`lessonTags`, `thumbnailImageUrl`, `squareImageUrl`, `deepLinkPath`, `isFavorite` | ||
) | ||
SELECT | ||
`lessonId`, -- or whatever your original PK column was | ||
`title`, | ||
`description`, | ||
`type`, | ||
`tags`, | ||
`bannerImageUrl`, -- this becomes thumbnailImageUrl | ||
`squareImageUrl`, | ||
`deepLinkPath`, | ||
`isFavorite` | ||
FROM `Favorite Lessons` | ||
""".trimIndent() | ||
) | ||
|
||
db.execSQL(sql = "DROP TABLE `Favorite Lessons`") | ||
|
||
db.execSQL(sql = "ALTER TABLE `Favorite Lessons_new` RENAME TO `Favorite Lessons`") | ||
} | ||
} | ||
|
||
val MIGRATION_2_3 : Migration = object : Migration(2 , 3) { | ||
override fun migrate(db : SupportSQLiteDatabase) { | ||
db.execSQL( | ||
sql = """ | ||
CREATE TABLE IF NOT EXISTS `Favorite Lessons_new` ( | ||
`lessonId` TEXT PRIMARY KEY NOT NULL, | ||
`lessonTitle` TEXT NOT NULL, | ||
`lessonDescription` TEXT NOT NULL, | ||
`lessonType` TEXT NOT NULL, | ||
`lessonTags` TEXT NOT NULL, | ||
`thumbnailImageUrl` TEXT NOT NULL, | ||
`squareImageUrl` TEXT NOT NULL, | ||
`deepLinkPath` TEXT NOT NULL, | ||
`isFavorite` INTEGER NOT NULL | ||
) | ||
""".trimIndent() | ||
) | ||
|
||
db.execSQL( | ||
sql = """ | ||
INSERT INTO `Favorite Lessons_new` ( | ||
`lessonId`, `lessonTitle`, `lessonDescription`, `lessonType`, | ||
`lessonTags`, `thumbnailImageUrl`, `squareImageUrl`, `deepLinkPath`, `isFavorite` | ||
) | ||
SELECT | ||
`lessonId`, `lessonTitle`, `lessonDescription`, `lessonType`, | ||
`lessonTags`, `thumbnailImageUrl`, `squareImageUrl`, `deepLinkPath`, `isFavorite` | ||
FROM `Favorite Lessons` | ||
""".trimIndent() | ||
) | ||
|
||
db.execSQL(sql = "DROP TABLE `Favorite Lessons`") | ||
|
||
db.execSQL(sql = "ALTER TABLE `Favorite Lessons_new` RENAME TO `Favorite Lessons`") | ||
} | ||
} |
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
Oops, something went wrong.