Skip to content

Commit

Permalink
[1.1.1/AN-feat] DB 마이그레이션 (Drop 방식 X) (#434)
Browse files Browse the repository at this point in the history
* fix: room entity 변경 시 db drop 후 새로 생성

* build: Room Scheme 내보내기 기능 추가

* add: pokerogueDataBase scheme 추가

* feat: PokeRogueDatabase AutoMigration

* style: ktFormat

* fix: fallbackToDestructive 삭제

* feat: Migration 버전 수정 ( 2 to 3)

* refactor: 테스트 data 및 assertion 변경
  • Loading branch information
murjune authored Oct 28, 2024
1 parent 49baae8 commit 734de30
Show file tree
Hide file tree
Showing 12 changed files with 567 additions and 4 deletions.
1 change: 1 addition & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ plugins {
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.room) apply false
alias(libs.plugins.android.junit5) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.firebase.crashlytics.plugin) apply false
Expand Down
2 changes: 2 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ androidx-test-extention-ktx = { group = "androidx.test.ext", name = "junit-ktx",
junit5-android-test-core = { module = "de.mannodermaus.junit5:android-test-core", version.ref = "android-junit5-core" }
junit5-android-test-runner = { module = "de.mannodermaus.junit5:android-test-runner", version.ref = "android-junit5-core" }
android-mockk = { module = "io.mockk:mockk-android", version.ref = "mockk" }
room-testing = { module = "androidx.room:room-testing", version.ref = "room" }

# unit test
kotlin-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
Expand Down Expand Up @@ -150,6 +151,7 @@ kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
room = { id = "androidx.room", version.ref = "room" }

# google & firebase
google-services = { id = "com.google.gms.google-services", version.ref = "google-services" }
Expand Down
9 changes: 9 additions & 0 deletions android/local/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.room)
}

android {
Expand Down Expand Up @@ -43,6 +44,13 @@ android {
excludes += "win32-x86*/**"
}
}
sourceSets {
getByName("androidTest").assets.srcDir("$projectDir/schemas")
}
}

room {
schemaDirectory("$projectDir/schemas")
}

dependencies {
Expand Down Expand Up @@ -71,4 +79,5 @@ dependencies {
androidTestImplementation(libs.kotest.runner.junit5)
androidTestImplementation(libs.junit5.android.test.core)
androidTestRuntimeOnly(libs.junit5.android.test.runner)
androidTestImplementation(libs.room.testing)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "734577a7ee599cdbfadbf26892c3d677",
"entities": [
{
"tableName": "Pokemon",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `dexNumber` INTEGER NOT NULL, `formName` TEXT NOT NULL, `name` TEXT NOT NULL, `imageUrl` TEXT NOT NULL, `types` TEXT NOT NULL, `generation` INTEGER NOT NULL, `baseStat` INTEGER NOT NULL, `hp` INTEGER NOT NULL, `attack` INTEGER NOT NULL, `defense` INTEGER NOT NULL, `specialAttack` INTEGER NOT NULL, `specialDefense` INTEGER NOT NULL, `speed` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "dexNumber",
"columnName": "dexNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "formName",
"columnName": "formName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "imageUrl",
"columnName": "imageUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "types",
"columnName": "types",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "generation",
"columnName": "generation",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "baseStat",
"columnName": "baseStat",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "hp",
"columnName": "hp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "attack",
"columnName": "attack",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "defense",
"columnName": "defense",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "specialAttack",
"columnName": "specialAttack",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "specialDefense",
"columnName": "specialDefense",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "speed",
"columnName": "speed",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '734577a7ee599cdbfadbf26892c3d677')"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "15571e87f13db1101fb5cecf0fc2527f",
"entities": [
{
"tableName": "Pokemon",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `dexNumber` INTEGER NOT NULL, `formName` TEXT NOT NULL, `name` TEXT NOT NULL, `imageUrl` TEXT NOT NULL, `backImageUrl` TEXT NOT NULL, `types` TEXT NOT NULL, `generation` INTEGER NOT NULL, `baseStat` INTEGER NOT NULL, `hp` INTEGER NOT NULL, `attack` INTEGER NOT NULL, `defense` INTEGER NOT NULL, `specialAttack` INTEGER NOT NULL, `specialDefense` INTEGER NOT NULL, `speed` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "dexNumber",
"columnName": "dexNumber",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "formName",
"columnName": "formName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "imageUrl",
"columnName": "imageUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "backImageUrl",
"columnName": "backImageUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "types",
"columnName": "types",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "generation",
"columnName": "generation",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "baseStat",
"columnName": "baseStat",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "hp",
"columnName": "hp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "attack",
"columnName": "attack",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "defense",
"columnName": "defense",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "specialAttack",
"columnName": "specialAttack",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "specialDefense",
"columnName": "specialDefense",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "speed",
"columnName": "speed",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '15571e87f13db1101fb5cecf0fc2527f')"
]
}
}
Loading

0 comments on commit 734de30

Please sign in to comment.