Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Truncate fields to fit db width (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Sep 17, 2020
1 parent 99ff9e9 commit 3279924
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/jetstream/plugins/monocular/chart_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ func (m *Monocular) translateToChart(record *store.ChartStoreRecord, chartYaml *

if chartYaml != nil {
chart.Keywords = chartYaml.Keywords
// Prefer the Chart Yaml description if we have it (db one might be truncated)
chart.Description = chartYaml.Description
chart.Maintainers = make([]ChartMaintainer, len(chartYaml.Maintainers))
for index, maintainer := range chartYaml.Maintainers {
chart.Maintainers[index] = *maintainer
Expand Down
8 changes: 6 additions & 2 deletions src/jetstream/plugins/monocular/store/chart_store_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func NewHelmChartDBStore(dcp *sql.DB) (ChartStore, error) {
return &HelmChartDBStore{db: dcp}, nil
}

func truncate(in string) string {
return fmt.Sprintf("%.255s", in)
}

// Save a Helm Chart to the database
func (p *HelmChartDBStore) Save(chart ChartStoreRecord, batchID string) error {

Expand All @@ -67,11 +71,11 @@ func (p *HelmChartDBStore) Save(chart ChartStoreRecord, batchID string) error {

if err == nil {
// The record already exists, so update it
_, err := p.db.Exec(updateChartVersion, chart.Created, chart.AppVersion, chart.Description, chart.IconURL, chart.ChartURL, sourceURL, chart.Digest, chart.IsLatest, batchID, chart.EndpointID, chart.Name, chart.Repository, chart.Version)
_, err := p.db.Exec(updateChartVersion, chart.Created, chart.AppVersion, truncate(chart.Description), truncate(chart.IconURL), truncate(chart.ChartURL), truncate(sourceURL), chart.Digest, chart.IsLatest, batchID, chart.EndpointID, chart.Name, chart.Repository, chart.Version)
return err
}

if _, err := p.db.Exec(saveChartVersion, chart.EndpointID, chart.Name, chart.Repository, chart.Version, chart.Created, chart.AppVersion, chart.Description, chart.IconURL, chart.ChartURL, sourceURL, chart.Digest, chart.IsLatest, batchID); err != nil {
if _, err := p.db.Exec(saveChartVersion, chart.EndpointID, chart.Name, chart.Repository, chart.Version, chart.Created, chart.AppVersion, truncate(chart.Description), truncate(chart.IconURL), truncate(chart.ChartURL), truncate(sourceURL), chart.Digest, chart.IsLatest, batchID); err != nil {
return fmt.Errorf("Unable to save Helm Chart Version: %v", err)
}
return nil
Expand Down

0 comments on commit 3279924

Please sign in to comment.