Add missing database migrations
This commit is contained in:
parent
62986ca79d
commit
13390b2e1b
|
@ -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) {
|
val MIGRATION_2_3: Migration = object : Migration(2, 3) {
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
database.execSQL(
|
database.execSQL(
|
||||||
|
@ -42,3 +81,97 @@ 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(
|
||||||
|
"ALTER TABLE ServerSetting ADD COLUMN color INTEGER"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,7 +7,11 @@ import org.koin.core.qualifier.named
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.moire.ultrasonic.data.AppDatabase
|
import org.moire.ultrasonic.data.AppDatabase
|
||||||
import org.moire.ultrasonic.data.MIGRATION_1_2
|
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_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.fragment.ServerSettingsModel
|
import org.moire.ultrasonic.fragment.ServerSettingsModel
|
||||||
import org.moire.ultrasonic.util.Settings
|
import org.moire.ultrasonic.util.Settings
|
||||||
|
|
||||||
|
@ -27,7 +31,11 @@ val appPermanentStorage = module {
|
||||||
DB_FILENAME
|
DB_FILENAME
|
||||||
)
|
)
|
||||||
.addMigrations(MIGRATION_1_2)
|
.addMigrations(MIGRATION_1_2)
|
||||||
|
.addMigrations(MIGRATION_2_1)
|
||||||
.addMigrations(MIGRATION_2_3)
|
.addMigrations(MIGRATION_2_3)
|
||||||
|
.addMigrations(MIGRATION_3_2)
|
||||||
|
.addMigrations(MIGRATION_3_4)
|
||||||
|
.addMigrations(MIGRATION_4_3)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue