forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB index (0xPolygonHermez#2562) (0xPolygonHermez#2570)
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |