diff --git a/migration/migration.go b/migration/migration.go index e8df29a16f..95ba77c1a5 100644 --- a/migration/migration.go +++ b/migration/migration.go @@ -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 diff --git a/migration/migration_blackbox_test.go b/migration/migration_blackbox_test.go index f98e5c14c5..ec3309f43f 100644 --- a/migration/migration_blackbox_test.go +++ b/migration/migration_blackbox_test.go @@ -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) @@ -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 diff --git a/migration/sql-files/110-update-number-for-existing-iterations.sql b/migration/sql-files/110-update-number-for-existing-iterations.sql deleted file mode 100644 index 11ba425438..0000000000 --- a/migration/sql-files/110-update-number-for-existing-iterations.sql +++ /dev/null @@ -1,19 +0,0 @@ ---- Assign a number to every existing iteration partitioned by their space and in ---- ascending creation order. -WITH iteration_numbers AS ( - SELECT *, ROW_NUMBER() OVER(PARTITION BY space_id ORDER BY created_at ASC) AS num - FROM iterations -) -UPDATE iterations SET number = (SELECT num FROM iteration_numbers WHERE iteration_numbers.id = iterations.id); - --- Make "number" a required column and add an index for faster querying over --- "space_id" and "number". -ALTER TABLE iterations ALTER COLUMN number SET NOT NULL; -ALTER TABLE iterations ADD CONSTRAINT iterations_space_id_number_idx UNIQUE (space_id, number); - --- Update the "number_sequences" table with the maximum for iterations. -INSERT INTO number_sequences (space_id, table_name, current_val) - SELECT space_id, 'iterations' "table_name", MAX(number) - FROM iterations - WHERE number IS NOT NULL - GROUP BY 1,2; diff --git a/migration/sql-test-files/110-update-number-for-existing-iterations.sql b/migration/sql-test-files/110-update-number-for-existing-iterations.sql deleted file mode 100644 index 25919a3237..0000000000 --- a/migration/sql-test-files/110-update-number-for-existing-iterations.sql +++ /dev/null @@ -1,25 +0,0 @@ -SET sp_template.id = '{{index . 0}}'; -SET sp1.id = '{{index . 1}}'; -SET sp2.id = '{{index . 2}}'; - -SET iter1.id = '{{index . 3}}'; -SET iter2.id = '{{index . 4}}'; -SET iter3.id = '{{index . 5}}'; -SET iter4.id = '{{index . 6}}'; - --- create space template -INSERT INTO space_templates (id,name,description) - VALUES(current_setting('sp_template.id')::uuid, current_setting('sp_template.id'), 'test template'); - --- create two spaces -INSERT INTO spaces (id,name,space_template_id) - VALUES - (current_setting('sp1.id')::uuid, current_setting('sp1.id'), current_setting('sp_template.id')::uuid), - (current_setting('sp2.id')::uuid, current_setting('sp2.id'), current_setting('sp_template.id')::uuid); - -INSERT INTO iterations (id, name, path, space_id, created_at) -VALUES - (current_setting('iter1.id')::uuid, 'iteration 1', replace(current_setting('iter1.id'), '-', '_')::ltree, current_setting('sp1.id')::uuid, '2018-09-17 16:01'), - (current_setting('iter2.id')::uuid, 'iteration 2', replace(current_setting('iter2.id'), '-', '_')::ltree, current_setting('sp1.id')::uuid, '2018-09-17 15:01'), - (current_setting('iter3.id')::uuid, 'iteration 3', replace(current_setting('iter3.id'), '-', '_')::ltree, current_setting('sp2.id')::uuid, '2018-09-17 16:01'), - (current_setting('iter4.id')::uuid, 'iteration 4', replace(current_setting('iter4.id'), '-', '_')::ltree, current_setting('sp2.id')::uuid, '2018-09-17 15:01');