<commit_before><commit_msg>Cascade removed rules to their filters.<commit_after>"""Cascade removed rules to filters

Revision ID: 3de9ad66862f
Revises: <PASSWORD>
Create Date: 2015-01-12 15:47:02.778152

"""

# revision identifiers, used by Alembic.
revision = '3de9ad66862f'
down_revision = '2136a1f22f1f'

from alembic import op
import sqlalchemy as sa

import fmn.lib


def upgrade():
    engine = op.get_bind().engine
    session = sa.orm.scoped_session(sa.orm.sessionmaker(bind=engine))

    # In alembic revision '2136a1f22f1f' these filters has the rules attached
    # that were removed.  The filters need to be removed too.
    goners = [
        'Users removed from packages I own',
        'New branches for packages I own',
        'Retirement of packages I own',
    ]

    for name in goners:
        filters = session.query(fmn.lib.models.Filter)\
            .filter_by(name=name).all()
        for fltr in filters:
            while fltr.rules:
                rule = fltr.rules.pop()
                print "* Deleting rule %r." % rule
                session.delete(rule)
            print "Deleting filter %r." % fltr
            session.delete(fltr)


def downgrade():
    pass
{'fraction_non_alphanumeric': 0.09440267335004177, 'fraction_numerical': 0.04177109440267335, 'mean_word_length': 2.5654761904761907, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4939717', 'n_tokens_mistral': 410, 'n_tokens_neox': 370, 'n_words': 112}