Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Postpone iteration number update #2325

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,6 @@ func GetMigrations() Migrations {
// Version 109
m = append(m, steps{ExecuteSQLFile("109-number-column-for-iteration.sql")})

// Version 110
m = append(m, steps{ExecuteSQLFile("110-update-number-for-existing-iterations.sql")})

// Version N
//
// In order to add an upgrade, simply append an array of MigrationFunc to the
Expand Down
78 changes: 0 additions & 78 deletions migration/migration_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func TestMigrations(t *testing.T) {
t.Run("TestMirgraion107", testMigration107NumberSequencesTable)
t.Run("TestMirgraion108", testMigration108NumberColumnForArea)
t.Run("TestMirgraion109", testMigration109NumberColumnForIteration)
t.Run("TestMirgraion110", testMigration110UpdateNumberForExistingIterations)

// Perform the migration
err = migration.Migrate(sqlDB, databaseName)
Expand Down Expand Up @@ -1384,83 +1383,6 @@ func testMigration109NumberColumnForIteration(t *testing.T) {
require.True(t, dialect.HasColumn("iterations", "number"))
}

func testMigration110UpdateNumberForExistingIterations(t *testing.T) {
t.Run("migrate to previous version", func(t *testing.T) {
migrateToVersion(t, sqlDB, migrations[:110], 110)
})

spaceTemplateID := uuid.NewV4()
space1ID := uuid.NewV4()
space2ID := uuid.NewV4()
// two iterations in space 1
iter1ID := uuid.NewV4()
iter2ID := uuid.NewV4()
// two iterations in space 2
iter3ID := uuid.NewV4()
iter4ID := uuid.NewV4()

t.Run("setup test data to migrate", func(t *testing.T) {
require.Nil(t, runSQLscript(sqlDB, "110-update-number-for-existing-iterations.sql",
spaceTemplateID.String(),
space1ID.String(),
space2ID.String(),
iter1ID.String(),
iter2ID.String(),
iter3ID.String(),
iter4ID.String(),
))
})

// Helper functions

getNumberOf := func(t *testing.T, table string, id uuid.UUID) int {
q := fmt.Sprintf("SELECT number FROM %s WHERE id = $1", table)
row := sqlDB.QueryRow(q, id)
require.NotNil(t, row)
var p int32
err := row.Scan(&p)
require.NoError(t, err, "%+v", err)
return int(p)
}
getNumberOfIteration := func(t *testing.T, iterID uuid.UUID) int { return getNumberOf(t, "iterations", iterID) }

t.Run("migrate to current version", func(t *testing.T) {
migrateToVersion(t, sqlDB, migrations[:111], 111)
})

t.Run("checks after migration", func(t *testing.T) {
// check that the newest iteration/area has the smaller number and that
// the numbering is partitioned by space_id
assert.Equal(t, 2, getNumberOfIteration(t, iter1ID))
assert.Equal(t, 1, getNumberOfIteration(t, iter2ID))
assert.Equal(t, 2, getNumberOfIteration(t, iter3ID))
assert.Equal(t, 1, getNumberOfIteration(t, iter4ID))

// check that the sequences table has the expected values
type numberSequence struct {
spaceID uuid.UUID
tableName string
currentVal int
}
rows, err := sqlDB.Query("SELECT space_id, table_name, current_val FROM number_sequences WHERE space_id IN ($1, $2)", space1ID, space2ID)
require.NoError(t, err)
defer rows.Close()
toBeFound := map[numberSequence]struct{}{
{space1ID, "iterations", 2}: {},
{space2ID, "iterations", 2}: {},
}
for rows.Next() {
seq := numberSequence{}
err := rows.Scan(&seq.spaceID, &seq.tableName, &seq.currentVal)
require.NoError(t, err)
delete(toBeFound, seq)
}
require.Empty(t, toBeFound, "failed to find these number sequences: %+v", spew.Sdump(toBeFound))

require.True(t, dialect.HasIndex("iterations", "iterations_space_id_number_idx"))
})
}

// runSQLscript loads the given filename from the packaged SQL test files and
// executes it on the given database. Golang text/template module is used
// to handle all the optional arguments passed to the sql test files
Expand Down

This file was deleted.

This file was deleted.