Skip to content

Commit

Permalink
Merge pull request #286 from Progress1/news_item
Browse files Browse the repository at this point in the history
Add cascade delete to NEWS_ITEM releated tables
  • Loading branch information
Progress1 authored May 15, 2024
2 parents 8a0d9e5 + 3bcab5e commit ee98f55
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""add cascade delete to NEWS_ITEM releated tables
Revision ID: 57d784d699d9
Revises: f0a4860000ff
Create Date: 2024-05-07 10:06:33.066000
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '57d784d699d9'
down_revision = 'f0a4860000ff'
branch_labels = None
depends_on = None


def upgrade():
delete_previous()
# news_item_attribute
op.create_foreign_key('news_item_data_news_item_attribute_news_item_attribute_id_fkey', 'news_item_data_news_item_attribute', 'news_item_attribute', ['news_item_attribute_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key('news_item_aggregate_news_item_attri_news_item_attribute_id_fkey', 'news_item_aggregate_news_item_attribute', 'news_item_attribute', ['news_item_attribute_id'], ['id'], ondelete='CASCADE')
# news_item_data - manual delete in Taranis keeps DATA tree records (to not crawl again?)
op.create_foreign_key('news_item_data_news_item_attribute_news_item_data_id_fkey', 'news_item_data_news_item_attribute', 'news_item_data', ['news_item_data_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key('news_item_news_item_data_id_fkey', 'news_item', 'news_item_data', ['news_item_data_id'], ['id'], ondelete='CASCADE')
# news_item_aggregate
op.create_foreign_key('news_item_aggregate_news_item_attri_news_item_aggregate_id_fkey', 'news_item_aggregate_news_item_attribute', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key('report_item_news_item_aggregate_news_item_aggregate_id_fkey', 'report_item_news_item_aggregate', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key('news_item_aggregate_search_index_news_item_aggregate_id_fkey', 'news_item_aggregate_search_index', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'], ondelete='CASCADE')
op.create_foreign_key('news_item_news_item_aggregate_id_fkey', 'news_item', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'], ondelete='CASCADE')
# news_item
op.create_foreign_key('news_item_vote_news_item_id_fkey', 'news_item_vote', 'news_item', ['news_item_id'], ['id'], ondelete='CASCADE')

def downgrade():
delete_previous()
# news_item_attribute
op.create_foreign_key('news_item_data_news_item_attribute_news_item_attribute_id_fkey', 'news_item_data_news_item_attribute', 'news_item_attribute', ['news_item_attribute_id'], ['id'])
op.create_foreign_key('news_item_aggregate_news_item_attri_news_item_attribute_id_fkey', 'news_item_aggregate_news_item_attribute', 'news_item_attribute', ['news_item_attribute_id'], ['id'])
# news_item_data
op.create_foreign_key('news_item_data_news_item_attribute_news_item_data_id_fkey', 'news_item_data_news_item_attribute', 'news_item_data', ['news_item_data_id'], ['id'])
op.create_foreign_key('news_item_news_item_data_id_fkey', 'news_item', 'news_item_data', ['news_item_data_id'], ['id'])
# news_item_aggregate
op.create_foreign_key('news_item_aggregate_news_item_attri_news_item_aggregate_id_fkey', 'news_item_aggregate_news_item_attribute', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'])
op.create_foreign_key('report_item_news_item_aggregate_news_item_aggregate_id_fkey', 'report_item_news_item_aggregate', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'])
op.create_foreign_key('news_item_aggregate_search_index_news_item_aggregate_id_fkey', 'news_item_aggregate_search_index', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'])
op.create_foreign_key('news_item_news_item_aggregate_id_fkey', 'news_item', 'news_item_aggregate', ['news_item_aggregate_id'], ['id'])
# news_item
op.create_foreign_key('news_item_vote_news_item_id_fkey', 'news_item_vote', 'news_item', ['news_item_id'], ['id'], ondelete='CASCADE')

def delete_previous():
print("deleting previous objects...", flush=True)
# news_item_attribute
op.drop_constraint('news_item_data_news_item_attribute_news_item_attribute_id_fkey', 'news_item_data_news_item_attribute', type_='foreignkey')
op.drop_constraint('news_item_aggregate_news_item_attri_news_item_attribute_id_fkey', 'news_item_aggregate_news_item_attribute', type_='foreignkey')
# news_item_data
op.drop_constraint('news_item_data_news_item_attribute_news_item_data_id_fkey', 'news_item_data_news_item_attribute', type_='foreignkey')
op.drop_constraint('news_item_news_item_data_id_fkey', 'news_item', type_='foreignkey')
# news_item_aggregate
op.drop_constraint('news_item_aggregate_news_item_attri_news_item_aggregate_id_fkey', 'news_item_aggregate_news_item_attribute', type_='foreignkey')
op.drop_constraint('report_item_news_item_aggregate_news_item_aggregate_id_fkey', 'report_item_news_item_aggregate', type_='foreignkey')
op.drop_constraint('news_item_aggregate_search_index_news_item_aggregate_id_fkey', 'news_item_aggregate_search_index', type_='foreignkey')
op.drop_constraint('news_item_news_item_aggregate_id_fkey', 'news_item', type_='foreignkey')
# news_item
op.drop_constraint('news_item_vote_news_item_id_fkey', 'news_item_vote', type_='foreignkey')

0 comments on commit ee98f55

Please sign in to comment.