@@ -55,20 +55,34 @@ def __init__(self, config: DuckDBLiteConfig) -> None:
5555 if not config .read_only :
5656 self ._init_db ()
5757
58- def _init_db (self ):
58+ def _create_unique_index (
59+ self , index_name : str , table_name : str , columns : list
60+ ) -> None :
61+ try :
62+ self .duckdb_client .execute (
63+ f"CREATE UNIQUE INDEX { index_name } ON { table_name } ({ ', ' .join (columns )} )"
64+ )
65+ except duckdb .CatalogException as e :
66+ if "already exists" not in str (e ).lower ():
67+ raise
68+
69+ def _init_db (self ) -> None :
5970 self .duckdb_client .execute (
6071 "CREATE TABLE IF NOT EXISTS metadata_aspect_v2 "
6172 "(urn VARCHAR, aspect_name VARCHAR, version BIGINT, metadata JSON, system_metadata JSON, createdon BIGINT)"
6273 )
63- self .duckdb_client .execute (
64- "CREATE UNIQUE INDEX IF NOT EXISTS aspect_idx ON metadata_aspect_v2 (urn, aspect_name, version)"
74+
75+ self ._create_unique_index (
76+ "aspect_idx" , "metadata_aspect_v2" , ["urn" , "aspect_name" , "version" ]
6577 )
78+
6679 self .duckdb_client .execute (
6780 "CREATE TABLE IF NOT EXISTS metadata_edge_v2 "
6881 "(src_id VARCHAR, relnship VARCHAR, dst_id VARCHAR, dst_label VARCHAR)"
6982 )
70- self .duckdb_client .execute (
71- "CREATE UNIQUE INDEX IF NOT EXISTS edge_idx ON metadata_edge_v2 (src_id, relnship, dst_id)"
83+
84+ self ._create_unique_index (
85+ "edge_idx" , "metadata_edge_v2" , ["src_id" , "relnship" , "dst_id" ]
7286 )
7387
7488 def location (self ) -> str :
0 commit comments