feat(14-01): add phase_dependencies table to schema
- Add phase_dependencies table mirroring task_dependencies pattern - Add phaseId and dependsOnPhaseId FK columns with cascade delete - Add phasesRelations with dependsOn and dependents many relations - Add phaseDependenciesRelations with phase and dependsOnPhase one relations - Export PhaseDependency and NewPhaseDependency types
This commit is contained in:
@@ -60,11 +60,46 @@ export const phasesRelations = relations(phases, ({ one, many }) => ({
|
|||||||
references: [initiatives.id],
|
references: [initiatives.id],
|
||||||
}),
|
}),
|
||||||
plans: many(plans),
|
plans: many(plans),
|
||||||
|
// Dependencies: phases this phase depends on
|
||||||
|
dependsOn: many(phaseDependencies, { relationName: 'dependentPhase' }),
|
||||||
|
// Dependents: phases that depend on this phase
|
||||||
|
dependents: many(phaseDependencies, { relationName: 'dependencyPhase' }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export type Phase = InferSelectModel<typeof phases>;
|
export type Phase = InferSelectModel<typeof phases>;
|
||||||
export type NewPhase = InferInsertModel<typeof phases>;
|
export type NewPhase = InferInsertModel<typeof phases>;
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// PHASE DEPENDENCIES
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
export const phaseDependencies = sqliteTable('phase_dependencies', {
|
||||||
|
id: text('id').primaryKey(),
|
||||||
|
phaseId: text('phase_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => phases.id, { onDelete: 'cascade' }),
|
||||||
|
dependsOnPhaseId: text('depends_on_phase_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => phases.id, { onDelete: 'cascade' }),
|
||||||
|
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const phaseDependenciesRelations = relations(phaseDependencies, ({ one }) => ({
|
||||||
|
phase: one(phases, {
|
||||||
|
fields: [phaseDependencies.phaseId],
|
||||||
|
references: [phases.id],
|
||||||
|
relationName: 'dependentPhase',
|
||||||
|
}),
|
||||||
|
dependsOnPhase: one(phases, {
|
||||||
|
fields: [phaseDependencies.dependsOnPhaseId],
|
||||||
|
references: [phases.id],
|
||||||
|
relationName: 'dependencyPhase',
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
export type PhaseDependency = InferSelectModel<typeof phaseDependencies>;
|
||||||
|
export type NewPhaseDependency = InferInsertModel<typeof phaseDependencies>;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// PLANS
|
// PLANS
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user