diff --git a/core/database/schemas/com.chipichipi.dobedobe.core.database.db.DobeDobeDatabase/1.json b/core/database/schemas/com.chipichipi.dobedobe.core.database.db.DobeDobeDatabase/1.json new file mode 100644 index 00000000..ff133afe --- /dev/null +++ b/core/database/schemas/com.chipichipi.dobedobe.core.database.db.DobeDobeDatabase/1.json @@ -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')" + ] + } +} \ No newline at end of file diff --git a/core/database/src/androidTest/kotlin/com/chipichipi/dobedobe/core/database/db/DobeDobeMigrationTest.kt b/core/database/src/androidTest/kotlin/com/chipichipi/dobedobe/core/database/db/DobeDobeMigrationTest.kt new file mode 100644 index 00000000..7f513128 --- /dev/null +++ b/core/database/src/androidTest/kotlin/com/chipichipi/dobedobe/core/database/db/DobeDobeMigrationTest.kt @@ -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() + + // when : 가장 오래된 버전의 DB를 생성하고 닫음 + helper.createDatabase(dbName, oldestDbVersion) + .close() + + // then : 최신 버전 DB로 마이그레이션 후 검증 + Room.databaseBuilder( + testContext, + DobeDobeDatabase::class.java, + dbName, + ).addMigrations(*DobeDobeDatabase.MIGRATIONS) + .build().apply { + openHelper.writableDatabase.close() + } + } +} \ No newline at end of file