feat(14-01): add dependency methods to PhaseRepository

- Add createDependency(phaseId, dependsOnPhaseId) to interface and adapter
- Add getDependencies(phaseId) returning IDs of phases this phase depends on
- Add getDependents(phaseId) returning IDs of phases that depend on this phase
- Import phaseDependencies table in DrizzlePhaseRepository
- Follow exact pattern from DrizzleTaskRepository.createDependency
This commit is contained in:
Lukas May
2026-02-02 13:33:16 +01:00
parent cd02439ca9
commit 8e68a6e89e
2 changed files with 50 additions and 1 deletions

View File

@@ -7,7 +7,7 @@
import { eq, asc, and, max } from 'drizzle-orm';
import { nanoid } from 'nanoid';
import type { DrizzleDatabase } from '../../index.js';
import { phases, type Phase } from '../../schema.js';
import { phases, phaseDependencies, type Phase } from '../../schema.js';
import type {
PhaseRepository,
CreatePhaseData,
@@ -102,4 +102,34 @@ export class DrizzlePhaseRepository implements PhaseRepository {
await this.db.delete(phases).where(eq(phases.id, id));
}
async createDependency(phaseId: string, dependsOnPhaseId: string): Promise<void> {
const id = nanoid();
const now = new Date();
await this.db.insert(phaseDependencies).values({
id,
phaseId,
dependsOnPhaseId,
createdAt: now,
});
}
async getDependencies(phaseId: string): Promise<string[]> {
const result = await this.db
.select({ dependsOnPhaseId: phaseDependencies.dependsOnPhaseId })
.from(phaseDependencies)
.where(eq(phaseDependencies.phaseId, phaseId));
return result.map((row) => row.dependsOnPhaseId);
}
async getDependents(phaseId: string): Promise<string[]> {
const result = await this.db
.select({ phaseId: phaseDependencies.phaseId })
.from(phaseDependencies)
.where(eq(phaseDependencies.dependsOnPhaseId, phaseId));
return result.map((row) => row.phaseId);
}
}

View File

@@ -71,4 +71,23 @@ export interface PhaseRepository {
* Cascades to child plans and tasks via FK constraints.
*/
delete(id: string): Promise<void>;
/**
* Create a dependency between two phases.
* The phase identified by phaseId will depend on dependsOnPhaseId.
* Both phases must exist.
*/
createDependency(phaseId: string, dependsOnPhaseId: string): Promise<void>;
/**
* Get IDs of phases that this phase depends on.
* Returns empty array if no dependencies.
*/
getDependencies(phaseId: string): Promise<string[]>;
/**
* Get IDs of phases that depend on this phase.
* Returns empty array if no dependents.
*/
getDependents(phaseId: string): Promise<string[]>;
}