-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DB indexes for Accounts and Targeted Messaging
- Loading branch information
1 parent
75db7c2
commit 4cd4b93
Showing
2 changed files
with
107 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,17 @@ | ||
CREATE INDEX idx_accounts_group_id | ||
ON accounts (group_id); | ||
|
||
CREATE INDEX idx_account_data_settings_account_id_account_data_type_id | ||
ON account_data_settings (account_id, account_data_type_id); | ||
|
||
CREATE INDEX idx_counterfactual_safes_account_id | ||
ON counterfactual_safes(account_id); | ||
|
||
CREATE INDEX idx_counterfactual_safes_account_id_chain_id_predicted_address | ||
ON counterfactual_safes(account_id, chain_id, predicted_address); | ||
|
||
CREATE INDEX idx_targeted_safes_outreach_id_address | ||
ON targeted_safes (outreach_id, address); | ||
|
||
CREATE INDEX idx_submissions_targeted_safe_id_signer_address | ||
ON submissions (targeted_safe_id, signer_address); |
90 changes: 90 additions & 0 deletions
90
migrations/deprecated/__tests__/00010_account-indexes.spec.ts
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,90 @@ | ||
import { TestDbFactory } from '@/__tests__/db.factory'; | ||
import { PostgresDatabaseMigrator } from '@/datasources/db/v1/postgres-database.migrator'; | ||
import { faker } from '@faker-js/faker/.'; | ||
import type postgres from 'postgres'; | ||
|
||
describe('Migration 00010_account-indexes', () => { | ||
let sql: postgres.Sql; | ||
let migrator: PostgresDatabaseMigrator; | ||
const testDbFactory = new TestDbFactory(); | ||
|
||
beforeAll(async () => { | ||
sql = await testDbFactory.createTestDatabase(faker.string.uuid()); | ||
migrator = new PostgresDatabaseMigrator(sql); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testDbFactory.destroyTestDatabase(sql); | ||
}); | ||
|
||
it('runs successfully', async () => { | ||
const result = await migrator.test({ | ||
migration: '00010_account-indexes', | ||
after: async (sql: postgres.Sql) => { | ||
return { | ||
accounts: { | ||
indexes: | ||
await sql`SELECT indexname FROM pg_indexes WHERE tablename = 'accounts'`, | ||
}, | ||
account_data_settings: { | ||
indexes: | ||
await sql`SELECT indexname FROM pg_indexes WHERE tablename = 'account_data_settings'`, | ||
}, | ||
counterfactual_safes: { | ||
indexes: | ||
await sql`SELECT indexname FROM pg_indexes WHERE tablename = 'counterfactual_safes'`, | ||
}, | ||
targeted_safes: { | ||
indexes: | ||
await sql`SELECT indexname FROM pg_indexes WHERE tablename = 'targeted_safes'`, | ||
}, | ||
submissions: { | ||
indexes: | ||
await sql`SELECT indexname FROM pg_indexes WHERE tablename = 'submissions'`, | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
expect(result.after).toMatchObject({ | ||
accounts: { | ||
indexes: expect.arrayContaining([ | ||
{ indexname: 'idx_accounts_group_id' }, | ||
]), | ||
}, | ||
account_data_settings: { | ||
indexes: expect.arrayContaining([ | ||
{ | ||
indexname: | ||
'idx_account_data_settings_account_id_account_data_type_id', | ||
}, | ||
]), | ||
}, | ||
counterfactual_safes: { | ||
indexes: expect.arrayContaining([ | ||
{ | ||
indexname: 'idx_counterfactual_safes_account_id', | ||
}, | ||
{ | ||
indexname: | ||
'idx_counterfactual_safes_account_id_chain_id_predicted_address', | ||
}, | ||
]), | ||
}, | ||
targeted_safes: { | ||
indexes: expect.arrayContaining([ | ||
{ | ||
indexname: 'idx_targeted_safes_outreach_id_address', | ||
}, | ||
]), | ||
}, | ||
submissions: { | ||
indexes: expect.arrayContaining([ | ||
{ | ||
indexname: 'idx_submissions_targeted_safe_id_signer_address', | ||
}, | ||
]), | ||
}, | ||
}); | ||
}); | ||
}); |