alitheg commented on code in PR #1376:
URL:
https://github.com/apache/tooling-trusted-releases/pull/1376#discussion_r3557724698
##########
atr/storage/writers/catalogue.py:
##########
@@ -227,6 +222,111 @@ async def delete_project(self, project_key:
safe.ProjectKey) -> None:
raise
self.__write_as.append_to_audit_log(asf_uid=self.__asf_uid,
deleted_project=key)
+ async def import_catalogue_csvs(
+ self, rows_by_table: dict[str, list[dict[str, str]]], committee_key:
str
+ ) -> catalogue_diff.CatalogueDiff:
+ # Recompute the diff against a snapshot taken inside this transaction,
under the write lock
+ await self.__data.begin_immediate()
+ self.__data.expire_all()
+ try:
+ snapshot = await catalogue_import.build_snapshot(self.__data,
committee_key)
+ diff = catalogue_diff.classify_catalogue(rows_by_table, snapshot,
committee_key)
+ await self._apply_diff(diff)
+ await self.__data.commit()
+ except Exception:
+ await self.__data.rollback()
+ raise
+ self._audit_import(diff)
+ return diff
+
+ async def _apply_diff(self, diff: catalogue_diff.CatalogueDiff) -> None:
+ await self.__data.execute(sqlalchemy.text("PRAGMA
defer_foreign_keys=ON"))
+ # Adds in FK order: projects, then releases, then artifacts
+ for add in diff.adds:
+ if isinstance(add, catalogue_rows.ProjectRow):
+ self.__data.add(add.to_sql())
+ await self.__data.flush()
+ for add in diff.adds:
+ if isinstance(add, catalogue_rows.ReleaseRow):
+ self.__data.add(add.to_sql())
+ await self.__data.flush()
+ for add in diff.adds:
+ if isinstance(add, catalogue_rows.ArtifactRow):
+ self.__data.add(add.to_sql())
+ for move in diff.release_moves:
+ await self._move_one_release(move)
+ for rehome in diff.artifact_rehomes:
+ await self._rehome_one_artifact(rehome)
+ await self._assert_fk_integrity()
+
+ def _audit_import(self, diff: catalogue_diff.CatalogueDiff) -> None:
+ counts = diff.counts
+ self.__write_as.append_to_audit_log(
+ asf_uid=self.__asf_uid,
+ added=counts["add"],
+ moved=counts["release_move"],
+ rehomed=counts["artifact_rehome"],
+ conflicts=counts["conflict"],
+ )
+
+ async def _move_one_release(self, move: catalogue_diff.ReleaseMove) ->
None:
+ via = sql.validate_instrumented_attribute
+ old_key = move.key
+ version = str(move.row.version)
+ new_key = f"{move.to_project}-{version}"
Review Comment:
Quite right, and that hits something that bugged me when I did this - I've
changed to start deriving the release keys instead of exposing them. For the
scope of this page, it doesn't really matter that you can't _change_ a key, you
create a new one and reassign the artifacts to it - you can always remove the
empty release as a separate operation by merging it with another.
There was another bug here - if you change version and nothing else your
edit was silently dropped.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]