Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set unique chart ID column #1429

Merged
merged 2 commits into from
Jan 13, 2020
Merged

Set unique chart ID column #1429

merged 2 commits into from
Jan 13, 2020

Conversation

andresmgot
Copy link
Contributor

Description of the change

Not setting a unique varchar column with PostgreSQL was causing the application to show duplicates instead of updating the existing chart. Now the chart ID (e.g. bitnami/apache) is used as that unique column.

Possible drawbacks

It requires deleting the existing table (or restarting postgres pods) but the feature has not been released yet.

@@ -112,38 +110,22 @@ func (m *postgresAssetManager) UpdateLastCheck(repoName, checksum string, now ti
}

func (m *postgresAssetManager) importCharts(charts []models.Chart) error {
txn, err := m.DB.Begin()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you also removing the transaction for importing the charts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to explain that. The only supported method when doing a transaction is COPY FROM (https://godoc.org/github.com/lib/pq#hdr-Bulk_imports). That was the reason for a chart to be added several times to the database. Once I set the unique column, that method started to fail because "there was already an entry with that unique ID".

I tried to use a custom query (instead of COPYing) but arguments were not supported. The only way I found to safely do this was to execute one query per chart (and it didn't have a noticeable impact in the performance).

@andresmgot andresmgot merged commit 672a7b2 into master Jan 13, 2020
@andresmgot andresmgot deleted the charts_unique_id branch January 16, 2020 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants