From f7eb7666bd8f5cf66a3c99021500d2c7e2f62334 Mon Sep 17 00:00:00 2001 From: Haruka Date: Sat, 7 Sep 2024 22:13:17 +0900 Subject: [PATCH] change index of new tables to unique index --- db/migrate.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/db/migrate.py b/db/migrate.py index d79dbaea..fa476fb5 100644 --- a/db/migrate.py +++ b/db/migrate.py @@ -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: @@ -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)") \ No newline at end of file + 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)") \ No newline at end of file