fixup! fix(projections): added check to make sure there cannot be 2 projections for the same table

This commit is contained in:
Iraq Jaber
2025-08-08 17:05:46 +01:00
parent 57ae374793
commit ba697e7bdf
2 changed files with 7 additions and 3 deletions

View File

@@ -209,17 +209,18 @@ func Init(ctx context.Context) error {
return nil return nil
} }
func Start(ctx context.Context) { func Start(ctx context.Context) error {
projectionTableMap := make(map[string]bool, len(projections)) projectionTableMap := make(map[string]bool, len(projections))
for _, projection := range projections { for _, projection := range projections {
table := projection.String() table := projection.String()
if projectionTableMap[table] { if projectionTableMap[table] {
panic("projeciton for " + projection.String() + " already added") return fmt.Errorf("projeciton for %s already added", table)
} }
projectionTableMap[table] = true projectionTableMap[table] = true
projection.Start(ctx) projection.Start(ctx)
} }
return nil
} }
func ProjectInstance(ctx context.Context) error { func ProjectInstance(ctx context.Context) error {

View File

@@ -90,7 +90,10 @@ func StartQueries(
return nil, err return nil, err
} }
if startProjections { if startProjections {
projection.Start(ctx) err = projection.Start(ctx)
if err != nil {
return nil, err
}
} }
repo.caches, err = startCaches( repo.caches, err = startCaches(