AlmaLinux / build-system

The AlmaLinux OS project Build System documentation and issue tracker.
Creative Commons Attribution Share Alike 4.0 International
27 stars 9 forks source link

The script `manage_flavours` doesn't delete repositories that are not listed in config #106

Closed anfimovdm closed 9 months ago

anfimovdm commented 1 year ago

Config for flavours. If database have more repos then that config we should delete relation to extra ones from DB. As part of the said script.

anfimovdm commented 1 year ago

@metalefty We have a flavour config here with repositories and other data. Sometimes users can remove some repositories from this config. And if we run our manage_flavours script with the -U flag repositories that were removed from that config will remain in our database. So, we need to make changes in the manage_flavours script to keep only actual flavours in our database.

metalefty commented 1 year ago

Thanks for the detail!

metalefty commented 1 year ago

We need to delete flavours not only from platform_flavours table because there's foreign key constraint. I'm going to delete relation from platform_flavour_repository.

What about repositories?

metalefty commented 1 year ago

And if we run our manage_flavours script with the -U flag repositories that were removed from that config will remain in our database.

As far as I understand this comment, need to delete repos.

anfimovdm commented 1 year ago

Yes, we need to remove all entities (such as repositories and platform_flavour_repository) related to platform_flavour

metalefty commented 1 year ago

Thanks I already implemented simple deletion. I'm working on deleting related entities now.

sqlalchemy.exc.IntegrityError: (sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class 'asyncpg.exceptions.ForeignKeyViolationError'>: update or delete on table "platform_flavours" violates foreign key constraint "platform_flavour_repository_flavour_id_fkey" on table "platform_flavour_repository"
DETAIL:  Key (id)=(1) is still referenced from table "platform_flavour_repository".
[SQL: DELETE FROM platform_flavours WHERE platform_flavours.id = %s]
metalefty commented 1 year ago

I'm still not sure how to perform this in SQLAlchemy and looking into that.

DELETE FROM repositories WHERE id IN (SELECT repository_id FROM platform_flavour_repository WHERE flavour_id=1);
DELETE FROM platform_flavour_repository WHERE flavour_id=1;

I know how to perform this:

DELETE FROM platform_flavours WHERE id=1;
db.execute(delete(models.PlatformFlavour).where(models.PlatformFlavour.id == pf_id))
metalefty commented 1 year ago

Draft PR: https://github.com/AlmaLinux/albs-web-server/pull/662