# Path: boardinghouse/schema.py
# def _table_exists(table_name, schema=None):
#     cursor = connection.cursor()
#     cursor.execute("""SELECT *
#                         FROM information_schema.tables
#                        WHERE table_name = %s
#                          AND table_schema = %s""", [table_name, schema or settings.PUBLIC_SCHEMA])
#     return bool(cursor.fetchone())
# 
# Path: boardinghouse/signals.py



from django.conf import settings
from django.db import migrations
from boardinghouse.schema import _table_exists
from boardinghouse.signals import schema_aware_operation

    for model in private_auth_models(apps):
        schema_editor.execute(view_from_model(model))


def drop_views(apps, schema_editor):
    for model in private_auth_models(apps):
        schema_editor.execute('DROP VIEW "{public}"."{table_name}" CASCADE'.format(
            public=settings.PUBLIC_SCHEMA, table_name=model._meta.db_table
        ))


def move_existing_to_schemata(apps, schema_editor):
    """
    This is not really working that well at the moment. Perhaps we should look at
    using the migration operations that actually add/remove these tables?

    Or maybe just give instructions about what to do if this case is detected?
    """
    def move_table(table_name):
        schema_editor.execute('CREATE TABLE "{table}" (LIKE "{public}"."{table}" INCLUDING ALL)'.format(
            public=settings.PUBLIC_SCHEMA,
            table=table_name
        ))

    for model in private_auth_models(apps):
        # Look for model in public schema.
        table_name = model._meta.db_table
        if (
            _table_exists(schema=settings.PUBLIC_SCHEMA, table_name=table_name) and

# Path: boardinghouse/schema.py
# def _table_exists(table_name, schema=None):
#     cursor = connection.cursor()
#     cursor.execute("""SELECT *
#                         FROM information_schema.tables
#                        WHERE table_name = %s
#                          AND table_schema = %s""", [table_name, schema or settings.PUBLIC_SCHEMA])
#     return bool(cursor.fetchone())
# 
# Path: boardinghouse/signals.py



# Path: boardinghouse/migrations/0005_group_views.py
from django.conf import settings
from django.db import migrations
from boardinghouse.schema import _table_exists
from boardinghouse.signals import schema_aware_operation


    for model in private_auth_models(apps):
        schema_editor.execute(view_from_model(model))


def drop_views(apps, schema_editor):
    for model in private_auth_models(apps):
        schema_editor.execute('DROP VIEW "{public}"."{table_name}" CASCADE'.format(
            public=settings.PUBLIC_SCHEMA, table_name=model._meta.db_table
        ))


def move_existing_to_schemata(apps, schema_editor):
    """
    This is not really working that well at the moment. Perhaps we should look at
    using the migration operations that actually add/remove these tables?

    Or maybe just give instructions about what to do if this case is detected?
    """
    def move_table(table_name):
        schema_editor.execute('CREATE TABLE "{table}" (LIKE "{public}"."{table}" INCLUDING ALL)'.format(
            public=settings.PUBLIC_SCHEMA,
            table=table_name
        ))

    for model in private_auth_models(apps):
        # Look for model in public schema.
        table_name = model._meta.db_table
        if (
            _table_exists(schema=settings.PUBLIC_SCHEMA, table_name=table_name) and

            not _table_exists(schema=settings.TEMPLATE_SCHEMA, table_name=table_name)