File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -426,11 +426,12 @@ def _emit_repository_data(repositories, engine):
426426 metadata_size = pretty_size (repo .get_size ())
427427 actual_size = pretty_size (repo .get_local_size ())
428428 if head :
429+ lq_server_name = head .lq_server_name ()
429430 head = head .image_hash [:10 ]
430431 if (
431432 engine .run_sql (
432433 "SELECT 1 FROM pg_foreign_server WHERE srvname = %s" ,
433- (repo . lq_server_name ()[: 63 ] ,),
434+ (lq_server_name ,),
434435 return_shape = ResultShape .ONE_ONE ,
435436 )
436437 is not None
Original file line number Diff line number Diff line change @@ -801,7 +801,7 @@ def record_overlay_table_as_patch(
801801 # Finally, point the LQ FDW to the latest image to pick up the new changes after truncating the upper table
802802 self .object_engine .run_sql (
803803 SQL ("ALTER SERVER {} OPTIONS (SET image_hash %s)" ).format (
804- Identifier (old_table .repository .lq_server_name ()),
804+ Identifier (old_table .repository .images . by_hash ( image_hash ). lq_server_name ()),
805805 ),
806806 (image_hash ,),
807807 )
Original file line number Diff line number Diff line change @@ -69,6 +69,11 @@ def __eq__(self, other: object) -> bool:
6969 return NotImplemented
7070 return self .image_hash == other .image_hash and self .repository == other .repository
7171
72+ def lq_server_name (self , target_schema : Optional [str ] = None ) -> str :
73+ """The name of the foreign server used in the layered querying checkout mode"""
74+ target_schema = target_schema or self .repository .to_schema ()
75+ return f"{ target_schema } :{ self .image_hash [:8 ]} _lq_srv" [:63 ]
76+
7277 def get_parent_children (self ) -> Tuple [Optional [str ], List [str ]]:
7378 """Gets the parent and a list of children of a given image."""
7479 parent = self .parent_id
@@ -191,7 +196,7 @@ def lq_checkout(
191196 from splitgraph .hooks .data_source .fdw import init_fdw
192197
193198 target_schema = target_schema or self .repository .to_schema ()
194- server_id = self .repository . lq_server_name ()
199+ server_id = self .lq_server_name ()
195200 engine = self .repository .engine
196201 object_engine = self .repository .object_engine
197202
@@ -207,7 +212,6 @@ def lq_checkout(
207212 "repository" : self .repository .repository ,
208213 "image_hash" : self .image_hash ,
209214 },
210- overwrite = False ,
211215 )
212216
213217 # It's easier to create the foreign tables from our side than to implement IMPORT FOREIGN SCHEMA by the FDW
Original file line number Diff line number Diff line change @@ -151,10 +151,6 @@ def to_schema(self) -> str:
151151 """Returns the engine schema that this repository gets checked out into."""
152152 return self .namespace + "/" + self .repository if self .namespace else self .repository
153153
154- def lq_server_name (self ) -> str :
155- """The name of the foreign server used in the layered querying checkout mode"""
156- return f"{ self .to_schema ()} _lq_checkout_server"
157-
158154 def __repr__ (self ) -> str :
159155 repr = "Repository %s on %s" % (self .to_schema (), self .engine .name )
160156 if self .engine != self .object_engine :
Original file line number Diff line number Diff line change 77
88
99def unmount_schema (engine : "PsycopgEngine" , schema : str ) -> None :
10- engine .run_sql (
11- SQL ("DROP SERVER IF EXISTS {} CASCADE" ).format (Identifier ("%s_lq_checkout_server" % schema ))
12- )
10+ engine .run_sql (SQL ("DROP SERVER IF EXISTS {} CASCADE" ).format (Identifier ("%s_lq_srv" % schema )))
1311 engine .run_sql (SQL ("DROP SERVER IF EXISTS {} CASCADE" ).format (Identifier (schema + "_server" )))
1412 engine .run_sql (SQL ("DROP SCHEMA IF EXISTS {} CASCADE" ).format (Identifier (schema )))
You can’t perform that action at this time.
0 commit comments