import click
from sqlalchemy import inspect
from planning_system.db import DB
from planning_system.db.schema.views import get_view_definitions, views_base


@click.command()
@click.pass_obj
def deadviews(config):
    """
    Prints a list of views which exist in the database
    but not in the planning system.

    Does not provide a delete option, as views
    should be manually inspected to determine dependencies.
    TODO automate inspection.
    """
    with DB(config.uri, config.echo) as db:

        config.verbose_print("Getting views in database")
        inspector = inspect(db.engine)
        db_views = inspector.get_view_names()

        config.verbose_print("Getting views in planning system")
        session = db.session()
        sys_views = [name for name in get_view_definitions(session).keys()]

        output = [name for name in db_views if name not in sys_views]
        output.sort()

        print("Redundant views")
        for name in output:
            print(name)

import click
from sqlalchemy import inspect
from planning_system.db import DB
from planning_system.db.schema.views import get_view_definitions, views_base


@click.command()
@click.pass_obj
def deadviews(config):
    """
    Prints a list of views which exist in the database
    but not in the planning system.

    Does not provide a delete option, as views
    should be manually inspected to determine dependencies.
    TODO automate inspection.
    """
    with DB(config.uri, config.echo) as db:

        config.verbose_print("Getting views in database")
        inspector = inspect(db.engine)
        db_views = inspector.get_view_names()

        config.verbose_print("Getting views in planning system")
        session = db.session()
        sys_views = [name for name in get_view_definitions(session).keys()]

        output = [name for name in db_views if name not in sys_views]
        output.sort()

        print("Redundant views")
        for name in output:
            print(name)

Prints a list of views which exist in the database     but not in the planning system.      Does not provide a delete option, as views     should be manually inspected to determine dependencies.     TODO automate inspection.