Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 authored Sep 22, 2023
1 parent 81e38d6 commit 46e4b57
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db/migrations/state/0010.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +migrate Up
CREATE INDEX IF NOT EXISTS l2block_block_hash_idx ON state.l2block (block_hash);

-- +migrate Down
DROP INDEX IF EXISTS state.l2block_block_hash_idx;
45 changes: 45 additions & 0 deletions db/migrations/state/0010_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package migrations_test

import (
"database/sql"
"testing"

"github.com/stretchr/testify/assert"
)

// this migration changes length of the token name
type migrationTest0010 struct{}

func (m migrationTest0010) InsertData(db *sql.DB) error {
return nil
}

func (m migrationTest0010) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) {
indexes := []string{"l2block_block_hash_idx"}
// Check indexes adding
for _, idx := range indexes {
// getIndex
const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;`
row := db.QueryRow(getIndex, idx)
var result int
assert.NoError(t, row.Scan(&result))
assert.Equal(t, 1, result)
}
}

func (m migrationTest0010) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) {
indexes := []string{"l2block_block_hash_idx"}
// Check indexes removing
for _, idx := range indexes {
// getIndex
const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;`
row := db.QueryRow(getIndex, idx)
var result int
assert.NoError(t, row.Scan(&result))
assert.Equal(t, 0, result)
}
}

func TestMigration0010(t *testing.T) {
runMigrationTest(t, 10, migrationTest0010{})
}

0 comments on commit 46e4b57

Please sign in to comment.