fix: update repo information with aurblup script

Currently, the "Repo" column in "OfficialProviders" is not updated
when a package is moved from one repository to another.

Note that we only save a package/provides combination once,
hence if a package is available in core and testing at the same time,
it would only put just one record into the OfficialProviders table.

We iterate through the repos one by one and the last value
is kept for mapping a (package/provides) combination to a repo.
Due to that, the repos listed in the "sync-db" config setting
should be ordered such that the "testing" repos are listed first.

Signed-off-by: moson-mo <mo-son@mailbox.org>
This commit is contained in:
moson-mo 2023-05-17 18:22:53 +02:00
parent 3253a6ad29
commit d0b0e4d88b
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296
2 changed files with 31 additions and 0 deletions

View file

@ -49,6 +49,7 @@ def _main(force: bool = False):
.all()
)
# delete providers not existing in any of our alpm repos
for name, provides in old_providers.difference(providers):
db.delete_all(
db.query(OfficialProvider).filter(
@ -59,10 +60,20 @@ def _main(force: bool = False):
)
)
# add new providers that do not yet exist in our DB
for name, provides in providers.difference(old_providers):
repo = repomap.get((name, provides))
db.create(OfficialProvider, Name=name, Repo=repo, Provides=provides)
# update providers where a pkg was moved from one repo to another
all_providers = db.query(OfficialProvider)
for op in all_providers:
new_repo = repomap.get((op.Name, op.Provides))
if op.Repo != new_repo:
op.Repo = new_repo
def main(force: bool = False):
db.get_engine()

View file

@ -87,3 +87,23 @@ def test_aurblup_cleanup(alpm_db: AlpmDatabase):
db.query(OfficialProvider).filter(OfficialProvider.Name == "fake package").all()
)
assert len(providers) == 0
def test_aurblup_repo_change(alpm_db: AlpmDatabase):
# Add a package and sync up the database.
alpm_db.add("pkg", "1.0", "x86_64", provides=["pkg2", "pkg3"])
aurblup.main()
# We should find an entry with repo "test"
op = db.query(OfficialProvider).filter(OfficialProvider.Name == "pkg").first()
assert op.Repo == "test"
# Modify the repo to something that does not exist.
op.Repo = "nonsense"
# Run our script.
aurblup.main()
# Repo should be set back to "test"
db.refresh(op)
assert op.Repo == "test"