docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거

Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
Antigravity Agent
2026-07-05 00:33:48 +09:00
parent 1cfd3bbb56
commit 9148c358d0
6455 changed files with 1 additions and 86875 deletions
@@ -0,0 +1,125 @@
---
id: android-room-patterns
title: Android Room — 안전한 SQLite ORM
category: Coding
status: draft
source_trust_level: B
verification_status: conceptual
created_at: 2026-05-09
updated_at: 2026-05-09
tags: [android, room, sqlite, persistence, vibe-coding]
tech_stack: { language: "Kotlin / Room", applicable_to: ["Android"] }
applied_in: []
aliases: [Room, DAO, Entity, Migration, Flow]
---
# Android Room
> 컴파일 타임 SQL 검증 + Flow 기반 reactive 쿼리. **Entity / DAO / Database** 3종. Migration 제대로 안 하면 사용자 데이터 손실 사고.
## 📖 핵심 개념
- Entity: @Entity 클래스 = 테이블.
- DAO: @Dao 인터페이스 = 쿼리 모음.
- Database: @Database — abstract class.
- Coroutines + Flow 자동 통합.
## 💻 코드 패턴
### Entity + DAO + DB
```kotlin
@Entity(tableName = "users", indices = [Index(value = ["email"], unique = true)])
data class UserEntity(
@PrimaryKey val id: String,
val email: String,
val name: String,
val createdAt: Long,
)
@Dao
interface UserDao {
@Query("SELECT * FROM users WHERE id = :id")
suspend fun findById(id: String): UserEntity?
@Query("SELECT * FROM users ORDER BY created_at DESC LIMIT :limit")
fun observeRecent(limit: Int): Flow<List<UserEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsert(user: UserEntity)
@Update
suspend fun update(user: UserEntity)
@Query("DELETE FROM users WHERE id = :id")
suspend fun delete(id: String)
}
@Database(entities = [UserEntity::class], version = 2, exportSchema = true)
abstract class AppDb : RoomDatabase() {
abstract fun userDao(): UserDao
}
```
### Migration
```kotlin
val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE users ADD COLUMN avatar_url TEXT")
}
}
Room.databaseBuilder(ctx, AppDb::class.java, "app.db")
.addMigrations(MIGRATION_1_2)
.build()
```
### Repository + Flow
```kotlin
class UserRepository(private val dao: UserDao, private val api: UserApi) {
fun observeUser(id: String): Flow<User> = dao.observeUser(id).map { it.toDomain() }
suspend fun refresh(id: String) {
val u = api.fetch(id)
dao.upsert(u.toEntity())
}
}
```
### Type converters
```kotlin
class Converters {
@TypeConverter fun fromInstant(t: Instant?): Long? = t?.toEpochMilli()
@TypeConverter fun toInstant(ms: Long?): Instant? = ms?.let { Instant.ofEpochMilli(it) }
}
@Database(entities = [...], version = 1)
@TypeConverters(Converters::class)
abstract class AppDb : RoomDatabase() { ... }
```
## 🤔 의사결정 기준
| 데이터 | 도구 |
|---|---|
| 구조화 데이터, 쿼리 필요 | Room |
| Key-value 설정 | DataStore |
| 큰 파일 | File API |
| 비밀 (token) | EncryptedSharedPreferences / Keystore |
| Sync (서버) | Room + WorkManager |
| 검색 | FTS5 (Room 지원) |
## ❌ 안티패턴
- **main thread 에서 DB 호출**: ANR. suspend / Flow 만.
- **migration 안 쓰고 fallbackToDestructiveMigration**: 사용자 데이터 손실.
- **DB schema 변경 후 version 안 올림**: crash on launch.
- **거대 트랜잭션 + 외부 API 호출 안에**: lock 길어짐.
- **Entity 노출 (UI 까지)**: domain 과 결합. mapper 권장.
- **인덱스 누락**: 큰 테이블 query 느림.
- **exportSchema = false**: schema 변경 검증 못 함. CI 에서 schema diff.
## 🤖 LLM 활용 힌트
- 신규 = Room. 단순 KV = DataStore.
- migration 매 version 마다.
- Flow + collectAsStateWithLifecycle 패턴.
## 🔗 관련 문서
- [[Android_DataStore_Patterns]]
- [[Android_Flow_StateFlow_SharedFlow]]