diff --git a/app/modules/annotations/models.py b/app/modules/annotations/models.py index bf7e72d57..61344228b 100644 --- a/app/modules/annotations/models.py +++ b/app/modules/annotations/models.py @@ -21,7 +21,9 @@ class AnnotationKeywords(db.Model, HoustonModel): annotation_guid = db.Column( db.GUID, db.ForeignKey('annotation.guid'), primary_key=True ) - keyword_guid = db.Column(db.GUID, db.ForeignKey('keyword.guid'), primary_key=True) + keyword_guid = db.Column( + db.GUID, db.ForeignKey('keyword.guid', ondelete='CASCADE'), primary_key=True + ) annotation = db.relationship('Annotation', back_populates='keyword_refs') keyword = db.relationship('Keyword') diff --git a/app/modules/assets/models.py b/app/modules/assets/models.py index 7cd7fb64a..d70ad593b 100644 --- a/app/modules/assets/models.py +++ b/app/modules/assets/models.py @@ -24,7 +24,9 @@ class AssetTags(db.Model, HoustonModel): asset_guid = db.Column(db.GUID, db.ForeignKey('asset.guid'), primary_key=True) - tag_guid = db.Column(db.GUID, db.ForeignKey('keyword.guid'), primary_key=True) + tag_guid = db.Column( + db.GUID, db.ForeignKey('keyword.guid', ondelete='CASCADE'), primary_key=True + ) asset = db.relationship('Asset', back_populates='tag_refs') tag = db.relationship('Keyword') diff --git a/app/modules/users/permissions/rules.py b/app/modules/users/permissions/rules.py index e999f3d72..8480b0faa 100644 --- a/app/modules/users/permissions/rules.py +++ b/app/modules/users/permissions/rules.py @@ -178,6 +178,7 @@ 'is_admin', ], ('Keyword', AccessOperation.READ): ['is_active'], + ('Keyword', AccessOperation.DELETE): ['is_admin'], ('Sighting', AccessOperation.WRITE_INTERNAL): ['is_internal'], ('Sighting', AccessOperation.READ_PRIVILEGED): ['is_staff'], ('Sighting', AccessOperation.READ): ['is_admin'], diff --git a/migrations/versions/dc91b517a7a4_.py b/migrations/versions/dc91b517a7a4_.py new file mode 100644 index 000000000..e620eb790 --- /dev/null +++ b/migrations/versions/dc91b517a7a4_.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +"""empty message + +Revision ID: dc91b517a7a4 +Revises: 53b0fec87272 +Create Date: 2024-01-22 22:51:34.690766 + +""" + +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'dc91b517a7a4' +down_revision = '53b0fec87272' + + +def upgrade(): + """ + Upgrade Semantic Description: + ENTER DESCRIPTION HERE + """ + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('annotation_keywords', schema=None) as batch_op: + batch_op.drop_constraint( + 'fk_annotation_keywords_keyword_guid_keyword', type_='foreignkey' + ) + batch_op.create_foreign_key( + batch_op.f('fk_annotation_keywords_keyword_guid_keyword'), + 'keyword', + ['keyword_guid'], + ['guid'], + ondelete='CASCADE', + ) + + with op.batch_alter_table('asset_tags', schema=None) as batch_op: + batch_op.drop_constraint('fk_asset_tags_tag_guid_keyword', type_='foreignkey') + batch_op.create_foreign_key( + batch_op.f('fk_asset_tags_tag_guid_keyword'), + 'keyword', + ['tag_guid'], + ['guid'], + ondelete='CASCADE', + ) + + # ### end Alembic commands ### + + +def downgrade(): + """ + Downgrade Semantic Description: + ENTER DESCRIPTION HERE + """ + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('asset_tags', schema=None) as batch_op: + batch_op.drop_constraint( + batch_op.f('fk_asset_tags_tag_guid_keyword'), type_='foreignkey' + ) + batch_op.create_foreign_key( + 'fk_asset_tags_tag_guid_keyword', 'keyword', ['tag_guid'], ['guid'] + ) + + with op.batch_alter_table('annotation_keywords', schema=None) as batch_op: + batch_op.drop_constraint( + batch_op.f('fk_annotation_keywords_keyword_guid_keyword'), type_='foreignkey' + ) + batch_op.create_foreign_key( + 'fk_annotation_keywords_keyword_guid_keyword', + 'keyword', + ['keyword_guid'], + ['guid'], + ) + + # ### end Alembic commands ###