From 987c02cf4a76ddfdeb55ab153eb42b20af4e8e8e Mon Sep 17 00:00:00 2001 From: PranshulGG Date: Sun, 16 Aug 2026 16:53:40 +0530 Subject: [PATCH] fix db crash --- .../data/local/WeatherMasterDatabase.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/data/local/WeatherMasterDatabase.kt b/app/src/main/java/com/pranshulgg/weather_master_app/data/local/WeatherMasterDatabase.kt index c79d486a0..d8c48a4fd 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/data/local/WeatherMasterDatabase.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/data/local/WeatherMasterDatabase.kt @@ -189,10 +189,29 @@ val MIGRATION_51_52 = object : Migration(51, 52) { } } + val MIGRATION_55_56 = object : Migration(55, 56) { override fun migrate(db: SupportSQLiteDatabase) { - db.execSQL( - "ALTER TABLE weather_hourly ADD COLUMN cachedSource TEXT" - ) + val cursor = db.query("PRAGMA table_info(weather_hourly)") + var cachedSourceExists = false + + while (cursor.moveToNext()) { + val columnName = cursor.getString( + cursor.getColumnIndexOrThrow("name") + ) + + if (columnName == "cachedSource") { + cachedSourceExists = true + break + } + } + + cursor.close() + + if (!cachedSourceExists) { + db.execSQL( + "ALTER TABLE weather_hourly ADD COLUMN cachedSource TEXT" + ) + } } } \ No newline at end of file