-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
core/database/schemas/com.chipichipi.dobedobe.core.database.db.DobeDobeDatabase/1.json
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,64 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "12a643d55ca1f7cd0240a2b873dfe241", | ||
"entities": [ | ||
{ | ||
"tableName": "Goal", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT NOT NULL, `isPinned` INTEGER NOT NULL, `state` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `completedAt` INTEGER)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "isPinned", | ||
"columnName": "isPinned", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "state", | ||
"columnName": "state", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "createdAt", | ||
"columnName": "createdAt", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "completedAt", | ||
"columnName": "completedAt", | ||
"affinity": "INTEGER", | ||
"notNull": false | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": true, | ||
"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, '12a643d55ca1f7cd0240a2b873dfe241')" | ||
] | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../src/androidTest/kotlin/com/chipichipi/dobedobe/core/database/db/DobeDobeMigrationTest.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,44 @@ | ||
package com.chipichipi.dobedobe.core.database.db | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import androidx.room.testing.MigrationTestHelper | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.jupiter.api.DisplayName | ||
import java.io.IOException | ||
|
||
class DobeDobeMigrationTest { | ||
@get:Rule | ||
val helper = | ||
MigrationTestHelper( | ||
InstrumentationRegistry.getInstrumentation(), | ||
DobeDobeDatabase::class.java, | ||
) | ||
|
||
@Test | ||
@DisplayName("모든 database 버전 마이그레이션 테스트") | ||
@Throws(IOException::class) | ||
fun test_migrateAll() { | ||
// given | ||
val dbName = "TEST_DB" | ||
val oldestDbVersion = 1 | ||
val testContext = ApplicationProvider.getApplicationContext<Context>() | ||
|
||
// when : 가장 오래된 버전의 DB를 생성하고 닫음 | ||
helper.createDatabase(dbName, oldestDbVersion) | ||
.close() | ||
|
||
// then : 최신 버전 DB로 마이그레이션 후 검증 | ||
Room.databaseBuilder( | ||
testContext, | ||
DobeDobeDatabase::class.java, | ||
dbName, | ||
).addMigrations(*DobeDobeDatabase.MIGRATIONS) | ||
.build().apply { | ||
openHelper.writableDatabase.close() | ||
} | ||
} | ||
} |