Merge pull request #660 from ultrasonic/develop_migrations
Fix database migrations
This commit is contained in:
commit
fd239e8e72
|
@ -26,6 +26,45 @@ val MIGRATION_1_2: Migration = object : Migration(1, 2) {
|
|||
}
|
||||
}
|
||||
|
||||
val MIGRATION_2_1: Migration = object : Migration(2, 1) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS ServerSettingMigration (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
[index] INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
userName TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
jukeboxByDefault INTEGER NOT NULL,
|
||||
allowSelfSignedCertificate INTEGER NOT NULL,
|
||||
ldapSupport INTEGER NOT NULL,
|
||||
musicFolderId TEXT
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
database.execSQL(
|
||||
"""
|
||||
INSERT INTO ServerSettingMigration (
|
||||
id, [index], name, url, userName, password, jukeboxByDefault,
|
||||
allowSelfSignedCertificate, ldapSupport, musicFolderId
|
||||
)
|
||||
SELECT
|
||||
id, [index], name, url, userName, password, jukeboxByDefault,
|
||||
allowSelfSignedCertificate, ldapSupport, musicFolderId
|
||||
FROM ServerSetting
|
||||
""".trimIndent()
|
||||
)
|
||||
database.execSQL(
|
||||
"DROP TABLE ServerSetting"
|
||||
)
|
||||
database.execSQL(
|
||||
"ALTER TABLE ServerSettingMigration RENAME TO ServerSetting"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATION_2_3: Migration = object : Migration(2, 3) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
|
@ -43,6 +82,46 @@ val MIGRATION_2_3: Migration = object : Migration(2, 3) {
|
|||
}
|
||||
}
|
||||
|
||||
val MIGRATION_3_2: Migration = object : Migration(3, 2) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS ServerSettingMigration (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
[index] INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
userName TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
jukeboxByDefault INTEGER NOT NULL,
|
||||
allowSelfSignedCertificate INTEGER NOT NULL,
|
||||
ldapSupport INTEGER NOT NULL,
|
||||
musicFolderId TEXT,
|
||||
minimumApiVersion TEXT
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
database.execSQL(
|
||||
"""
|
||||
INSERT INTO ServerSettingMigration (
|
||||
id, [index], name, url, userName, password, jukeboxByDefault,
|
||||
allowSelfSignedCertificate, ldapSupport, musicFolderId, minimumApiVersion
|
||||
)
|
||||
SELECT
|
||||
id, [index], name, url, userName, password, jukeboxByDefault,
|
||||
allowSelfSignedCertificate, ldapSupport, musicFolderId, minimumApiVersion
|
||||
FROM ServerSetting
|
||||
""".trimIndent()
|
||||
)
|
||||
database.execSQL(
|
||||
"DROP TABLE ServerSetting"
|
||||
)
|
||||
database.execSQL(
|
||||
"ALTER TABLE ServerSettingMigration RENAME TO ServerSetting"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATION_3_4: Migration = object : Migration(3, 4) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
|
@ -50,3 +129,49 @@ val MIGRATION_3_4: Migration = object : Migration(3, 4) {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
val MIGRATION_4_3: Migration = object : Migration(4, 3) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS ServerSettingMigration (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
[index] INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
userName TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
jukeboxByDefault INTEGER NOT NULL,
|
||||
allowSelfSignedCertificate INTEGER NOT NULL,
|
||||
ldapSupport INTEGER NOT NULL,
|
||||
musicFolderId TEXT,
|
||||
minimumApiVersion TEXT,
|
||||
chatSupport INTEGER,
|
||||
bookmarkSupport INTEGER,
|
||||
shareSupport INTEGER,
|
||||
podcastSupport INTEGER
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
database.execSQL(
|
||||
"""
|
||||
INSERT INTO ServerSettingMigration (
|
||||
id, [index], name, url, userName, password, jukeboxByDefault,
|
||||
allowSelfSignedCertificate, ldapSupport, musicFolderId, minimumApiVersion,
|
||||
chatSupport, bookmarkSupport, shareSupport, podcastSupport
|
||||
)
|
||||
SELECT
|
||||
id, [index], name, url, userName, password, jukeboxByDefault,
|
||||
allowSelfSignedCertificate, ldapSupport, musicFolderId, minimumApiVersion,
|
||||
chatSupport, bookmarkSupport, shareSupport, podcastSupport
|
||||
FROM ServerSetting
|
||||
""".trimIndent()
|
||||
)
|
||||
database.execSQL(
|
||||
"DROP TABLE ServerSetting"
|
||||
)
|
||||
database.execSQL(
|
||||
"ALTER TABLE ServerSettingMigration RENAME TO ServerSetting"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,11 @@ import org.koin.core.qualifier.named
|
|||
import org.koin.dsl.module
|
||||
import org.moire.ultrasonic.data.AppDatabase
|
||||
import org.moire.ultrasonic.data.MIGRATION_1_2
|
||||
import org.moire.ultrasonic.data.MIGRATION_2_1
|
||||
import org.moire.ultrasonic.data.MIGRATION_2_3
|
||||
import org.moire.ultrasonic.data.MIGRATION_3_2
|
||||
import org.moire.ultrasonic.data.MIGRATION_3_4
|
||||
import org.moire.ultrasonic.data.MIGRATION_4_3
|
||||
import org.moire.ultrasonic.model.ServerSettingsModel
|
||||
import org.moire.ultrasonic.util.Settings
|
||||
|
||||
|
@ -28,9 +31,11 @@ val appPermanentStorage = module {
|
|||
DB_FILENAME
|
||||
)
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_2_1)
|
||||
.addMigrations(MIGRATION_2_3)
|
||||
.addMigrations(MIGRATION_3_2)
|
||||
.addMigrations(MIGRATION_3_4)
|
||||
.fallbackToDestructiveMigration()
|
||||
.addMigrations(MIGRATION_4_3)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue