Files
ExperionCrawler/fastTable/step2.md

65 lines
2.4 KiB
Markdown

# STEP 2 — DbContext: DbSet + 인덱스 추가 (`ExperionDbContext.cs`)
## 사전 확인 (작업 전 반드시 수행)
1. `src/Infrastructure/Database/ExperionDbContext.cs` 파일을 열어 전체 내용을 읽는다.
2. 아래 항목을 확인하고 기록한다:
- [x] STEP 1이 완료되어 `FastSession`, `FastRecord` 클래스가 존재하는가? → 미완료면 STEP 1 먼저 수행
- [x] `FastSessions` DbSet이 이미 선언되어 있는가? → 있으면 작업 1 건너뜀
- [x] `FastRecords` DbSet이 이미 선언되어 있는가? → 있으면 작업 1 건너뜀
- [x] `OnModelCreating``FastSession` 인덱스 설정이 이미 있는가? → 있으면 작업 2 건너뜀
- [x] 기존 DbSet 선언 위치(줄 번호)를 확인한다
- [x] `OnModelCreating` 메서드의 끝 위치(줄 번호)를 확인한다
---
## 작업 1 — DbSet 추가
**위치**: 기존 DbSet 선언 블록 마지막 줄 바로 아래
```csharp
public DbSet<FastSession> FastSessions => Set<FastSession>();
public DbSet<FastRecord> FastRecords => Set<FastRecord>();
```
---
## 작업 2 — OnModelCreating 인덱스 추가
**위치**: `OnModelCreating` 메서드 내부, 기존 마지막 설정 블록 아래
```csharp
modelBuilder.Entity<FastSession>(e =>
{
e.HasKey(x => x.Id);
e.HasIndex(x => x.Status);
e.HasIndex(x => x.StartedAt);
});
modelBuilder.Entity<FastRecord>(e =>
{
e.HasKey(x => x.Id);
e.HasIndex(x => x.SessionId);
e.HasIndex(x => new { x.SessionId, x.TagName, x.RecordedAt });
});
```
---
## 사후 확인 (작업 후 반드시 수행)
1. `ExperionDbContext.cs` 파일을 다시 열어 변경 내용을 읽는다.
2. 아래 항목을 하나씩 확인한다:
- [x] `public DbSet<FastSession> FastSessions` 선언이 존재하는가?
- [x] `public DbSet<FastRecord> FastRecords` 선언이 존재하는가?
- [x] `modelBuilder.Entity<FastSession>` 블록이 `OnModelCreating` 안에 있는가?
- [x] `modelBuilder.Entity<FastRecord>` 블록이 `OnModelCreating` 안에 있는가?
- [x] `HasIndex(x => new { x.SessionId, x.TagName, x.RecordedAt })` 복합 인덱스가 있는가?
3. `dotnet build src/Infrastructure` 실행 → 에러/경고 0개 확인
4. 문제가 있으면 수정 후 다시 빌드 확인
---
## 완료 조건
- `dotnet build src/Web/ExperionCrawler.csproj` 결과: 에러 0, 경고 0 (기존 경고 포함)
- DbSet 2개, 인덱스 설정 2블록 모두 존재