Skip to content

Commit

Permalink
Merge pull request #1680 from Bee-lee/cluster-toggle-cluster-disable-…
Browse files Browse the repository at this point in the history
…user-id

delete everything in Migration 31
  • Loading branch information
Bee-lee authored Nov 9, 2022
2 parents 6dbe805 + 7268e10 commit bd349f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion migration/actual_migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,10 +1223,26 @@ func TestMigration31(t *testing.T) {
err = migration.SetDBVersion(db, dbDriver, 31)
helpers.FailOnError(t, err)

_, err = db.Exec(`
INSERT INTO advisor_ratings
(org_id, rule_fqdn, error_key, rated_at, last_updated_at, rating, rule_id)
VALUES
($1, $2, $3, $4, $5, $6, $7)
`,
testdata.OrgID,
testdata.Rule1ID,
testdata.ErrorKey1,
time.Now(),
time.Now(),
1,
testdata.Rule1CompositeID,
)
helpers.FailOnError(t, err)

err = db.QueryRow(`SELECT user_id FROM advisor_ratings`).Err()
assert.Error(t, err, "user_id column should not exist")

err = migration.SetDBVersion(db, dbDriver, 29)
err = migration.SetDBVersion(db, dbDriver, 30)
helpers.FailOnError(t, err)

var userID types.UserID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ var migrationStep = alterConstraintStep{
var mig0031AlterConstraintDropUserAdvisorRatings = Migration{
StepUp: func(tx *sql.Tx, driver types.DBDriver) error {
if driver == types.DBDriverPostgres {
deleteInvalidRowsQuery := "DELETE FROM advisor_ratings WHERE user_id = '0'"
// there are 27 rows in the prod table, all made by our QE org. it's not worth coming
// up with a query to flatten the table just because these testing rows.
deleteInvalidRowsQuery := "DELETE FROM advisor_ratings"
_, err := tx.Exec(deleteInvalidRowsQuery)
if err != nil {
return err
Expand Down

0 comments on commit bd349f0

Please sign in to comment.