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

DDO-3242: Remove "v2_" from table names #335

Merged
merged 12 commits into from
Oct 31, 2023

Conversation

katiewelch
Copy link
Contributor

@katiewelch katiewelch commented Oct 18, 2023

When we migration from sherlock v1 to v2, we renamed many database tables, indexes, foreign keys, keys, and sequences to include "v2_" in the name. Now, we are migrating to sherlock v3 and these resources no longer accurately reflect the current environment. During the first migration to v2, we were creating new resources. In this migration to v3, we will still be using the same resources, and will continue to use these resources for the foreseeable future. We will not add "v3_" to the resource names, so that if we do further migrations in the future, these resources will continue to reflect the current state.

This change included two parts.

  1. Find and replace all references to "v2_" in the Sherlock database.
  2. Database migrations. The migration was a simple rename command in both the up and down migrations. Unfortunately, rename commands cannot be stacked, so each rename had to be written as it's own command. The migrations are organized by table and then split into keys, foreign keys, and indexes. All sequence commands are at the bottom.

Testing

I tested this locally by

  1. starting up my local Sherlock. Doing this will run all the migrations and fail if there are any errors.
    Screenshot 2023-10-24 at 12 09 31 PM
  2. using the golang-migrate/migrate tool to test run my up and down migrations. I used
    migrate -path sherlock/db/migrations -database 'postgres://sherlock:password@localhost:5432/sherlock?sslmode=disable' goto 59
    and
    migrate -path sherlock/db/migrations -database 'postgres://sherlock:password@localhost:5432/sherlock?sslmode=disable' goto 60
    to test down and up, respectively.
    Screenshot 2023-10-24 at 12 12 39 PM

Risk

This change will affect many resources in the database and will require downtime, but is easy to revert using ArgoCD. We will push to dev first and make sure it spins up.

@katiewelch katiewelch requested a review from a team as a code owner October 18, 2023 19:41
@github-actions
Copy link

No API changes detected

@github-actions
Copy link

github-actions bot commented Oct 18, 2023

Published image from e27d297 (merge a6d5871):

us-central1-docker.pkg.dev/dsp-artifact-registry/sherlock/sherlock:v0.2.21-a6d5871

@codecov
Copy link

codecov bot commented Oct 24, 2023

Codecov Report

Merging #335 (e27d297) into main (9d17c79) will not change coverage.
Report is 3 commits behind head on main.
The diff coverage is 22.96%.

@@           Coverage Diff           @@
##             main     #335   +/-   ##
=======================================
  Coverage   63.23%   63.23%           
=======================================
  Files         147      147           
  Lines        8671     8671           
=======================================
  Hits         5483     5483           
  Misses       2813     2813           
  Partials      375      375           
Files Coverage Δ
sherlock/internal/models/app_version.go 93.75% <100.00%> (ø)
sherlock/internal/models/chart.go 100.00% <100.00%> (ø)
sherlock/internal/models/chart_release.go 25.00% <100.00%> (ø)
sherlock/internal/models/chart_version.go 93.75% <100.00%> (ø)
sherlock/internal/models/ci_identifier.go 100.00% <100.00%> (ø)
sherlock/internal/models/ci_run.go 100.00% <100.00%> (ø)
sherlock/internal/models/cluster.go 56.00% <100.00%> (ø)
...lock/internal/models/deploy_hook_trigger_config.go 72.72% <100.00%> (ø)
sherlock/internal/models/environment.go 25.00% <100.00%> (ø)
...lock/internal/models/github_actions_deploy_hook.go 100.00% <100.00%> (ø)
... and 17 more

Copy link
Contributor

@jack-r-warren jack-r-warren left a comment

Choose a reason for hiding this comment

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

Looks great! My one comment is that I don't think we should change metrics/metrics.go in this PR because that'll impact Prometheus, not the DB, and we'll want to roll that out differently than the database changes

sherlock/internal/metrics/metrics.go Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@katiewelch katiewelch merged commit 8bb8918 into main Oct 31, 2023
15 checks passed
@katiewelch katiewelch deleted the DDO-3242-remove-v2-from-tables branch October 31, 2023 01:14
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