Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: add chain.evm_tokens token_name index #466

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions storage/migrations/08_evm_tokens_name_index.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Add 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;
6 changes: 6 additions & 0 deletions storage/postgres/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ func (c *Client) listNexusMaterializedViews(ctx context.Context) ([]string, erro

// Wipe removes all contents of the database.
func (c *Client) Wipe(ctx context.Context) error {
if _, err := c.pool.Exec(ctx, "DROP EXTENSION IF EXISTS pg_trgm CASCADE;"); err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works out okay when it's at the beginning, because this way dropping the extension with cascade cleans up its types and functions

return err
}

tables, err := c.listNexusTables(ctx)
if err != nil {
return err
Expand All @@ -322,6 +326,7 @@ func (c *Client) Wipe(ctx context.Context) error {

// List, then drop all custom types.
// Query from https://stackoverflow.com/questions/3660787/how-to-list-custom-types-using-postgres-information-schema
// TODO: Don't delete extensions' types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a TODO, now that we're dropping the extension?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can switch course to dropping all extensions (except for some)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, so IIUC it's a TODO in the sense that if we added another extension, and that extension defined a custom type, and we chose not to use DROP EXTENSION IF EXISTS on it, we'd have to amend this code here so that it doesn't delete the extension's types.
In that hypothetical world, the same goes for other objects I guess? I don't know enough about postgres extensions but I imagine they can introduce functions and tables and whatnot.

Maybe this line can be something a little milder? Like NOTE: If you introduce postgres extensions with their own custom types, this will try to delete those types too.

I don't see it as a realistic TODO, i.e. I don't expect us to ever need to work on it in a principled way.

types, err := c.listNexusTypes(ctx)
if err != nil {
return err
Expand All @@ -334,6 +339,7 @@ func (c *Client) Wipe(ctx context.Context) error {
}

// List, then drop all custom functions.
// TODO: Don't delete extensions' functions.
functions, err := c.listNexusFunctions(ctx)
if err != nil {
return err
Expand Down