From 78e65b1d10f75a016a01ba620d7e45758ecb3c6d Mon Sep 17 00:00:00 2001 From: Warren He Date: Fri, 23 Jun 2023 17:05:20 -0700 Subject: [PATCH] storage: add chain.evm_tokens token_name index --- .../08_evm_tokens_name_index.up.sql | 10 ++++++++ storage/postgres/client.go | 25 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 storage/migrations/08_evm_tokens_name_index.up.sql diff --git a/storage/migrations/08_evm_tokens_name_index.up.sql b/storage/migrations/08_evm_tokens_name_index.up.sql new file mode 100644 index 000000000..2c6ab4eb0 --- /dev/null +++ b/storage/migrations/08_evm_tokens_name_index.up.sql @@ -0,0 +1,10 @@ +-- Add a indexes for evm_tokens token names and symbols for search. + +BEGIN; + +CREATE EXTENSION pg_trgm; + +CREATE INDEX ix_evm_tokens_name ON chain.evm_tokens USING GIST (token_name gist_trgm_ops); +CREATE INDEX ix_evm_tokens_symbol ON chain.evm_tokens USING GIST (symbol gist_trgm_ops); + +COMMIT; diff --git a/storage/postgres/client.go b/storage/postgres/client.go index 24aaab846..a7c1f186c 100644 --- a/storage/postgres/client.go +++ b/storage/postgres/client.go @@ -250,9 +250,32 @@ func (c *Client) Wipe(ctx context.Context) error { } } + // list, then drop some extensions. + rows, err := c.Query(ctx, ` + SELECT extname + FROM pg_extension + `) + if err != nil { + return fmt.Errorf("failed to list extensions: %w", err) + } + defer rows.Close() + for rows.Next() { + var extension string + if err = rows.Scan(&extension); err != nil { + return err + } + // This one was here when I got here. + if extension == "plpgsql" { + continue + } + if _, err = c.pool.Exec(ctx, fmt.Sprintf("DROP EXTENSION %s CASCADE", extension)); err != nil { + return err + } + } + // List, then drop all custom types. // Query from https://stackoverflow.com/questions/3660787/how-to-list-custom-types-using-postgres-information-schema - rows, err := c.Query(ctx, ` + rows, err = c.Query(ctx, ` SELECT n.nspname as schema, t.typname as type FROM pg_type t LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace