Skip to content

Commit

Permalink
Merge pull request #2322 from opengovern/fix-tasks
Browse files Browse the repository at this point in the history
fix: add default values for named queries
  • Loading branch information
artaasadi authored Dec 28, 2024
2 parents 096c945 + 96a81de commit 4a9812a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions jobs/post-install-job/job/migrations/inventory/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ func (m Migration) Run(ctx context.Context, conf config.MigratorConfig, logger *
}
dbm := db.Database{ORM: orm}

ormMetadata, err := postgres.NewClient(&postgres.Config{
Host: conf.PostgreSQL.Host,
Port: conf.PostgreSQL.Port,
User: conf.PostgreSQL.Username,
Passwd: conf.PostgreSQL.Password,
DB: "metadata",
SSLMode: conf.PostgreSQL.SSLMode,
}, logger)
if err != nil {
return fmt.Errorf("new postgres client: %w", err)
}
dbMetadata := db.Database{ORM: ormMetadata}

awsResourceTypesContent, err := os.ReadFile(path.Join(m.AttachmentFolderPath(), "aws-resource-types.json"))
if err != nil {
return err
Expand Down Expand Up @@ -171,6 +184,22 @@ func (m Migration) Run(ctx context.Context, conf config.MigratorConfig, logger *
return err
}

err = dbMetadata.ORM.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
for _, obj := range QueryParameters {
err := tx.Clauses(clause.OnConflict{
DoNothing: true,
}).Create(&obj).Error
if err != nil {
return err
}
}
return nil
})
if err != nil {
logger.Error("failed to insert query params", zap.Error(err))
return err
}

return nil
}

Expand Down

0 comments on commit 4a9812a

Please sign in to comment.