@@ -144,7 +144,7 @@ def __init__(
144144
145145 self ._seed_columns_to_types = {
146146 "name" : exp .DataType .build ("text" ),
147- "version " : exp .DataType .build ("text" ),
147+ "identifier " : exp .DataType .build ("text" ),
148148 "content" : exp .DataType .build ("text" ),
149149 }
150150
@@ -220,7 +220,7 @@ def _push_snapshots(self, snapshots: t.Iterable[Snapshot], overwrite: bool = Fal
220220 seed_contents .append (
221221 {
222222 "name" : snapshot .name ,
223- "version " : snapshot .version ,
223+ "identifier " : snapshot .identifier ,
224224 "content" : seed_model .seed .content ,
225225 }
226226 )
@@ -341,10 +341,6 @@ def _is_snapshot_used(snapshot: Snapshot) -> bool:
341341 )
342342 )
343343
344- seed_deletion_candidates = [t .snapshot for t in cleanup_targets if not t .dev_table_only ]
345- if seed_deletion_candidates :
346- self ._delete_seeds (seed_deletion_candidates )
347-
348344 return cleanup_targets
349345
350346 def delete_expired_environments (self ) -> t .List [Environment ]:
@@ -372,6 +368,7 @@ def delete_expired_environments(self) -> t.List[Environment]:
372368 def delete_snapshots (self , snapshot_ids : t .Iterable [SnapshotIdLike ]) -> None :
373369 for where in self ._snapshot_id_filter (snapshot_ids ):
374370 self .engine_adapter .delete_from (self .snapshots_table , where = where )
371+ self .engine_adapter .delete_from (self .seeds_table , where = where )
375372
376373 def snapshots_exist (self , snapshot_ids : t .Iterable [SnapshotIdLike ]) -> t .Set [SnapshotId ]:
377374 return self ._snapshot_ids_exist (snapshot_ids , self .snapshots_table )
@@ -489,8 +486,8 @@ def _get_snapshots(
489486 exp .to_table (self .seeds_table ).as_ ("seeds" ),
490487 on = exp .and_ (
491488 exp .column ("name" , table = "snapshots" ).eq (exp .column ("name" , table = "seeds" )),
492- exp .column ("version " , table = "snapshots" ).eq (
493- exp .column ("version " , table = "seeds" )
489+ exp .column ("identifier " , table = "snapshots" ).eq (
490+ exp .column ("identifier " , table = "seeds" )
494491 ),
495492 ),
496493 join_type = "left" ,
@@ -1001,6 +998,7 @@ def _migrate_rows(self, promoted_snapshots_only: bool) -> None:
1001998 if not snapshot_mapping :
1002999 logger .info ("No changes to snapshots detected" )
10031000 return
1001+ self ._migrate_seed_rows (snapshot_mapping )
10041002 self ._migrate_environment_rows (environments , snapshot_mapping )
10051003
10061004 def _migrate_snapshot_rows (
@@ -1149,6 +1147,51 @@ def _visit(
11491147
11501148 return all_snapshot_mapping
11511149
1150+ def _migrate_seed_rows (self , snapshot_mapping : t .Dict [SnapshotId , SnapshotTableInfo ]) -> None :
1151+ # FIXME: This migration won't be necessary if the primary key of the seeds table is changed to
1152+ # (name, version) instead of (name, identifier).
1153+ seed_snapshot_ids = [
1154+ s_id for s_id , table_info in snapshot_mapping .items () if table_info .is_seed
1155+ ]
1156+ if not seed_snapshot_ids :
1157+ logger .info ("No seed rows to migrate" )
1158+ return
1159+
1160+ logger .info ("Migrating seed rows..." )
1161+
1162+ for where in self ._snapshot_id_filter (
1163+ seed_snapshot_ids , batch_size = self .SNAPSHOT_SEED_MIGRATION_BATCH_SIZE
1164+ ):
1165+ seeds = {
1166+ SnapshotId (name = name , identifier = identifier ): content
1167+ for name , identifier , content in self ._fetchall (
1168+ exp .select ("name" , "identifier" , "content" ).from_ (self .seeds_table ).where (where )
1169+ )
1170+ }
1171+ if not seeds :
1172+ continue
1173+
1174+ new_seeds = {}
1175+ for snapshot_id , content in seeds .items ():
1176+ new_snapshot_id = snapshot_mapping [snapshot_id ].snapshot_id
1177+ new_seeds [new_snapshot_id ] = {
1178+ "name" : new_snapshot_id .name ,
1179+ "identifier" : new_snapshot_id .identifier ,
1180+ "content" : content ,
1181+ }
1182+
1183+ existing_snapshot_ids = self ._snapshot_ids_exist (new_seeds , self .seeds_table )
1184+ seeds_to_push = [
1185+ s for s_id , s in new_seeds .items () if s_id not in existing_snapshot_ids
1186+ ]
1187+
1188+ if seeds_to_push :
1189+ self .engine_adapter .insert_append (
1190+ self .seeds_table ,
1191+ pd .DataFrame (seeds_to_push ),
1192+ columns_to_types = self ._seed_columns_to_types ,
1193+ )
1194+
11521195 def _migrate_environment_rows (
11531196 self ,
11541197 environments : t .List [Environment ],
@@ -1183,10 +1226,6 @@ def _migrate_environment_rows(
11831226 except Exception :
11841227 logger .warning ("Failed to unpause migrated snapshots" , exc_info = True )
11851228
1186- def _delete_seeds (self , snapshots : t .Iterable [SnapshotNameVersionLike ]) -> None :
1187- for where in self ._snapshot_name_version_filter (snapshots , alias = None ):
1188- self .engine_adapter .delete_from (self .seeds_table , where = where )
1189-
11901229 def _snapshot_ids_exist (
11911230 self , snapshot_ids : t .Iterable [SnapshotIdLike ], table_name : exp .Table
11921231 ) -> t .Set [SnapshotId ]:
0 commit comments