You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: backfill/recreate-indexes/recreate-indexes.go
+66-44Lines changed: 66 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -27,69 +27,91 @@ func main() {
27
27
28
28
log.Println("Connected to database")
29
29
30
+
tx, err:=db.Begin()
31
+
iferr!=nil {
32
+
log.Fatalf("Failed to begin transaction: %v", err)
33
+
}
34
+
30
35
// SQL commands grouped by table
31
36
commands:= []struct {
32
37
descriptionstring
33
38
querystring
34
39
}{
35
-
// // CREATE INDEX commands for Balances
36
-
// {"Create unique index on Balances", `CREATE UNIQUE INDEX "balances_unique_constraint" ON "Balances" (network, "chainId", account, qualname, "tokenId");`},
37
-
// {"Create account index on Balances", `CREATE INDEX "balances_account_index" ON "Balances" (account);`},
38
-
// {"Create tokenId index on Balances", `CREATE INDEX "balances_tokenid_index" ON "Balances" ("tokenId");`},
39
-
// {"Create contractId index on Balances", `CREATE INDEX "balances_contractid_index" ON "Balances" ("contractId");`},
40
-
// {"Create search index on Balances", `CREATE INDEX "balances_search_idx" ON "Balances" (LOWER(account));`},
41
-
42
-
// // CREATE INDEX commands for Blocks
43
-
// {"Create height index on Blocks", `CREATE INDEX "blocks_height_idx" ON "Blocks" (height);`},
44
-
// {"Create chainId height index on Blocks", `CREATE INDEX "blocks_chainid_height_idx" ON "Blocks" ("chainId", height);`},
45
-
// {"Create chainId index on Blocks", `CREATE INDEX "blocks_chainid_idx" ON "Blocks" ("chainId");`},
46
-
// {"Create canonical index on Blocks", `CREATE INDEX "blocks_canonical_idx" ON "Blocks" (canonical);`},
47
-
// {"Create GIN trgm parent index on Blocks", `CREATE INDEX "blocks_trgm_parent_idx" ON "Blocks" USING gin (LOWER(parent) gin_trgm_ops);`},
48
-
49
-
// // CREATE INDEX commands for Contracts
50
-
// {"Create unique index on Contracts", `CREATE UNIQUE INDEX "contract_unique_constraint" ON "Contracts" (network, "chainId", module, "tokenId");`},
51
-
// {"Create search index on Contracts", `CREATE INDEX "contracts_search_idx" ON "Contracts" (LOWER(module));`},
52
-
53
-
// // CREATE INDEX commands for Events
54
-
// {"Create transactionId index on Events", `CREATE INDEX "events_transactionid_idx" ON "Events" ("transactionId");`},
55
-
56
-
// CREATE INDEX commands for Signers
57
-
{"Create publicKey transactionId index on Signers", `CREATE INDEX "signers_pubkey_transactionid_idx" ON "Signers" (pubkey, "transactionId");`},
58
-
59
-
// CREATE INDEX commands for Transactions
60
-
{"Create requestkey index on Transactions", `CREATE INDEX "transactions_requestkey_idx" ON "Transactions" (requestkey);`},
61
-
{"Create sender index on Transactions", `CREATE INDEX "transactions_sender_idx" ON "Transactions" (sender);`},
62
-
{"Create chainId blockId index on Transactions", `CREATE INDEX "transactions_chainid_blockid_idx" ON "Transactions" ("chainId", "blockId");`},
63
-
{"Create hash index on Transactions", `CREATE INDEX "transactions_hash_idx" ON "Transactions" (hash);`},
64
-
{"Create canonical index on Transactions", `CREATE INDEX "transactions_canonical_idx" ON "Transactions" (canonical);`},
65
-
{"Create GIN trgm requestkey index on Transactions", `CREATE INDEX "transactions_trgm_requestkey_idx" ON "Transactions" USING gin (LOWER(requestkey) gin_trgm_ops);`},
66
-
{"Create GIN trgm hash index on Transactions", `CREATE INDEX "transactions_trgm_hash_idx" ON "Transactions" USING gin (LOWER(hash) gin_trgm_ops);`},
67
-
{"Create GIN trgm txid index on Transactions", `CREATE INDEX "transactions_trgm_txid_idx" ON "Transactions" USING gin (LOWER(txid) gin_trgm_ops);`},
68
-
{"Create GIN trgm pactid index on Transactions", `CREATE INDEX "transactions_trgm_pactid_idx" ON "Transactions" USING gin (LOWER(pactid) gin_trgm_ops);`},
69
-
{"Create GIN trgm sender index on Transactions", `CREATE INDEX "transactions_trgm_sender_idx" ON "Transactions" USING gin (LOWER(sender) gin_trgm_ops);`},
70
-
71
-
// CREATE INDEX commands for Transfers
72
-
{"Create contractId index on Transfers", `CREATE INDEX "transfers_contractid_idx" ON "Transfers" ("contractId");`},
73
-
{"Create type index on Transfers", `CREATE INDEX "transfers_type_idx" ON "Transfers" (type);`},
74
-
{"Create transactionId index on Transfers", `CREATE INDEX "transfers_transactionid_idx" ON "Transfers" ("transactionId");`},
75
-
{"Create modulename index on Transfers", `CREATE INDEX "transfers_modulename_idx" ON "Transfers" (modulename);`},
76
-
{"Create from_acct modulename index on Transfers", `CREATE INDEX "transfers_from_acct_modulename_idx" ON "Transfers" (from_acct, modulename);`},
40
+
{"Create unique index on Balances", `CREATE UNIQUE INDEX "Balances_pkey" ON public."Balances" USING btree (id);`},
41
+
{"Create index on account column of Balances", `CREATE INDEX balances_account_index ON public."Balances" USING btree (account);`},
42
+
{"Create index on contractId column of Balances", `CREATE INDEX balances_contractid_index ON public."Balances" USING btree ("contractId");`},
43
+
{"Create index on lower(account) column of Balances", `CREATE INDEX balances_search_idx ON public."Balances" USING btree (lower((account)::text));`},
44
+
{"Create index on tokenId column of Balances", `CREATE INDEX balances_tokenid_index ON public."Balances" USING btree ("tokenId");`},
45
+
{"Create unique constraint on Balances", `CREATE UNIQUE INDEX balances_unique_constraint ON public."Balances" USING btree ("chainId", account, module, "tokenId");`},
46
+
{"Create unique index on Blocks", `CREATE UNIQUE INDEX "Blocks_pkey" ON public."Blocks" USING btree (id);`},
47
+
{"Create index on canonical column of Blocks", `CREATE INDEX blocks_canonical_idx ON public."Blocks" USING btree (canonical);`},
48
+
{"Create index on chainId, height columns of Blocks", `CREATE INDEX blocks_chainid_height_idx ON public."Blocks" USING btree ("chainId", height);`},
49
+
{"Create index on chainId column of Blocks", `CREATE INDEX blocks_chainid_idx ON public."Blocks" USING btree ("chainId");`},
50
+
{"Create unique index on Blocks chainwebVersion, chainId, hash", `CREATE UNIQUE INDEX "blocks_chainwebVersion_chainid_hash_unique_idx" ON public."Blocks" USING btree ("chainwebVersion", "chainId", hash);`},
51
+
{"Create index on hash column of Blocks", `CREATE INDEX blocks_hash_idx ON public."Blocks" USING btree (hash);`},
52
+
{"Create index on height, id columns of Blocks", `CREATE INDEX blocks_height_id_idx ON public."Blocks" USING btree (height, id);`},
53
+
{"Create index on height column of Blocks", `CREATE INDEX blocks_height_idx ON public."Blocks" USING btree (height);`},
54
+
{"Create GIN index on parent column of Blocks", `CREATE INDEX blocks_trgm_parent_idx ON public."Blocks" USING gin (lower((parent)::text));`},
55
+
{"Create unique index on Contracts", `CREATE UNIQUE INDEX "Contracts_pkey" ON public."Contracts" USING btree (id);`},
56
+
{"Create unique constraint on Contracts", `CREATE UNIQUE INDEX contract_unique_constraint ON public."Contracts" USING btree ("chainId", module, "tokenId");`},
57
+
{"Create index on Contracts module", `CREATE INDEX contracts_search_idx ON public."Contracts" USING btree (lower((module)::text));`},
58
+
{"Create unique index on Events", `CREATE UNIQUE INDEX "Events_pkey" ON public."Events" USING btree (id);`},
59
+
{"Create index on Events module, name", `CREATE INDEX events_module_name_idx ON public."Events" USING btree (module, name);`},
60
+
{"Create index on transactionId column of Events", `CREATE INDEX events_transactionid_idx ON public."Events" USING btree ("transactionId");`},
61
+
{"Create unique index on Guards", `CREATE UNIQUE INDEX "Guards_pkey" ON public."Guards" USING btree (id);`},
62
+
{"Create unique index on Guards publicKey, predicate, balanceId", `CREATE UNIQUE INDEX guards_publickey_predicate_balanceid_idx ON public."Guards" USING btree ("publicKey", predicate, "balanceId");`},
63
+
{"Create unique index on Signers", `CREATE UNIQUE INDEX "Signers_pkey" ON public."Signers" USING btree (id);`},
64
+
{"Create index on pubkey column of Signers", `CREATE INDEX signers_pubkey_idx ON public."Signers" USING btree (pubkey);`},
65
+
{"Create index on pubkey, transactionId columns of Signers", `CREATE INDEX signers_pubkey_transactionid_idx ON public."Signers" USING btree (pubkey, "transactionId");`},
66
+
{"Create index on transactionId column of Signers", `CREATE INDEX signers_transaction_id_idx ON public."Signers" USING btree ("transactionId");`},
67
+
{"Create unique index on Transactions", `CREATE UNIQUE INDEX "Transactions_pkey" ON public."Transactions" USING btree (id);`},
68
+
{"Create index on blockId column of Transactions", `CREATE INDEX "transactions_blockId_idx" ON public."Transactions" USING btree ("blockId");`},
69
+
{"Create index on canonical column of Transactions", `CREATE INDEX transactions_canonical_idx ON public."Transactions" USING btree (canonical);`},
70
+
{"Create index on chainId column of Transactions", `CREATE INDEX "transactions_chainId_idx" ON public."Transactions" USING btree ("chainId");`},
71
+
{"Create index on chainId, blockId columns of Transactions", `CREATE INDEX transactions_chainid_blockid_idx ON public."Transactions" USING btree ("chainId", "blockId");`},
72
+
{"Create index on hash column of Transactions", `CREATE INDEX transactions_hash_idx ON public."Transactions" USING btree (hash);`},
73
+
{"Create index on requestkey column of Transactions", `CREATE INDEX transactions_requestkey_idx ON public."Transactions" USING btree (requestkey);`},
74
+
{"Create index on sender, id columns of Transactions", `CREATE INDEX transactions_sender_id_idx ON public."Transactions" USING btree (sender, id);`},
75
+
{"Create index on sender column of Transactions", `CREATE INDEX transactions_sender_idx ON public."Transactions" USING btree (sender);`},
76
+
{"Create GIN index on hash column of Transactions", `CREATE INDEX transactions_trgm_hash_idx ON public."Transactions" USING gin (lower((hash)::text));`},
77
+
{"Create GIN index on pactid column of Transactions", `CREATE INDEX transactions_trgm_pactid_idx ON public."Transactions" USING gin (lower((pactid)::text));`},
78
+
{"Create GIN index on requestkey column of Transactions", `CREATE INDEX transactions_trgm_requestkey_idx ON public."Transactions" USING gin (lower((requestkey)::text));`},
79
+
{"Create GIN index on sender column of Transactions", `CREATE INDEX transactions_trgm_sender_idx ON public."Transactions" USING gin (lower((sender)::text));`},
80
+
{"Create GIN index on txid column of Transactions", `CREATE INDEX transactions_trgm_txid_idx ON public."Transactions" USING gin (lower((txid)::text));`},
81
+
{"Create unique index on Transfers", `CREATE UNIQUE INDEX "Transfers_pkey" ON public."Transfers" USING btree (id);`},
82
+
{"Create index on from_acct column of Transfers", `CREATE INDEX from_acct_idx ON public."Transfers" USING btree (from_acct);`},
83
+
{"Create index on to_acct column of Transfers", `CREATE INDEX to_acct_idx ON public."Transfers" USING btree (to_acct);`},
84
+
{"Create index on chainId, from_acct, modulename columns of Transfers", `CREATE INDEX transfers_chainid_from_acct_modulename_idx ON public."Transfers" USING btree ("chainId", from_acct, modulename);`},
85
+
{"Create index on chainId, to_acct, modulename columns of Transfers", `CREATE INDEX transfers_chainid_to_acct_modulename_idx ON public."Transfers" USING btree ("chainId", to_acct, modulename);`},
86
+
{"Create index on contractId column of Transfers", `CREATE INDEX transfers_contractid_idx ON public."Transfers" USING btree ("contractId");`},
87
+
{"Create index on from_acct, modulename columns of Transfers", `CREATE INDEX transfers_from_acct_modulename_idx ON public."Transfers" USING btree (from_acct, modulename);`},
88
+
{"Create index on hasTokenId column of Transfers", `CREATE INDEX "transfers_hasTokenId_idx" ON public."Transfers" USING btree ("hasTokenId");`},
89
+
{"Create index on modulename column of Transfers", `CREATE INDEX transfers_modulename_idx ON public."Transfers" USING btree (modulename);`},
90
+
{"Create index on transactionId column of Transfers", `CREATE INDEX transfers_transactionid_idx ON public."Transfers" USING btree ("transactionId");`},
91
+
{"Create index on type column of Transfers", `CREATE INDEX transfers_type_idx ON public."Transfers" USING btree (type);`},
0 commit comments