Skip to content

Commit

Permalink
change index of new tables to unique index
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukaMa committed Sep 7, 2024
1 parent e62be83 commit f7eb766
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion db/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def migrate(self):
migrations: list[tuple[int, Callable[[psycopg.AsyncConnection[DictRow], Redis[str]], Awaitable[None]]]] = [
(1, self.migrate_1_add_block_validator_index),
(2, self.migrate_2_add_address_tag_and_validator_table),
(3, self.migrate_3_change_tag_validator_index_to_unique),
]
async with self.pool.connection() as conn:
async with conn.cursor() as cur:
Expand Down Expand Up @@ -63,4 +64,14 @@ async def migrate_2_add_address_tag_and_validator_table(conn: psycopg.AsyncConne
website text,
logo text
)""")
await conn.execute("create index validator_info_address_index on validator_info (address)")
await conn.execute("create index validator_info_address_index on validator_info (address)")

@staticmethod
async def migrate_3_change_tag_validator_index_to_unique(conn: psycopg.AsyncConnection[DictRow], redis: Redis[str]):
await conn.execute("drop index address_tag_address_index")
await conn.execute("drop index address_tag_tag_index")
await conn.execute("create unique index address_tag_address_index on address_tag (address)")
await conn.execute("create unique index address_tag_tag_index on address_tag (tag)")

await conn.execute("drop index validator_info_address_index")
await conn.execute("create unique index validator_info_address_index on validator_info (address)")

0 comments on commit f7eb766

Please sign in to comment.