# Path: sesql/config.py
# CONFIG_PATH_FALLBACK = 'sesql_config'
#     CONFIG_PATH = getattr(settings, 'SESQL_CONFIG_PATH', CONFIG_PATH_FALLBACK)
#     CONFIG_PATH = CONFIG_PATH_FALLBACK
# 
# Path: sesql/typemap.py
# class TypeMap(object):
#     def __init__(self):
#     def all_subclasses(klass, done = None):
#     def all_tables(self):
#     def all_classes(self):
#     def all_class_names(self):
#     def get_class_names_for(self, table):
#     def get_classes_for(self, table):
#     def get_table_for(self, klass):
#     def get_class_by_name(self, klass):


from sesql import config
from sesql.typemap import typemap
@sql_function
def create_schedule_table():
    """
    Create the table to insert the reindex schedule
    """
    return [
        "DROP SEQUENCE IF EXISTS sesql_reindex_id_seq",
        "CREATE SEQUENCE sesql_reindex_id_seq",

        "DROP TABLE IF EXISTS sesql_reindex_schedule",
        """CREATE TABLE sesql_reindex_schedule (
        rowid integer NOT NULL,
        classname character varying(250) NOT NULL,
        objid integer NOT NULL,
        scheduled_at timestamp NOT NULL DEFAULT NOW(),
        PRIMARY KEY (rowid)
        )""",
        "CREATE INDEX sesql_reindex_schedule_date_index ON sesql_reindex_schedule (scheduled_at)",
        "CREATE INDEX sesql_reindex_schedule_content_index ON sesql_reindex_schedule (classname, rowid)"
    ]


@config.orm.transactional
def sync_db(cursor, verbosity = 0):
    if not config.orm.table_exists(cursor, config.MASTER_TABLE_NAME):
        create_dictionnary(cursor, execute = True, verbosity = verbosity, include_drop = True)
        create_master_table(cursor, execute = True, verbosity = verbosity, include_drop = True)
    elif verbosity:
        print "SeSQL : Table %s already existed, skipped." % config.MASTER_TABLE_NAME


# Path: sesql/config.py
# CONFIG_PATH_FALLBACK = 'sesql_config'
#     CONFIG_PATH = getattr(settings, 'SESQL_CONFIG_PATH', CONFIG_PATH_FALLBACK)
#     CONFIG_PATH = CONFIG_PATH_FALLBACK
# 
# Path: sesql/typemap.py
# class TypeMap(object):
#     def __init__(self):
#     def all_subclasses(klass, done = None):
#     def all_tables(self):
#     def all_classes(self):
#     def all_class_names(self):
#     def get_class_names_for(self, table):
#     def get_classes_for(self, table):
#     def get_table_for(self, klass):
#     def get_class_by_name(self, klass):


# Path: sesql/datamodel.py
from sesql import config
from sesql.typemap import typemap

@sql_function
def create_schedule_table():
    """
    Create the table to insert the reindex schedule
    """
    return [
        "DROP SEQUENCE IF EXISTS sesql_reindex_id_seq",
        "CREATE SEQUENCE sesql_reindex_id_seq",

        "DROP TABLE IF EXISTS sesql_reindex_schedule",
        """CREATE TABLE sesql_reindex_schedule (
        rowid integer NOT NULL,
        classname character varying(250) NOT NULL,
        objid integer NOT NULL,
        scheduled_at timestamp NOT NULL DEFAULT NOW(),
        PRIMARY KEY (rowid)
        )""",
        "CREATE INDEX sesql_reindex_schedule_date_index ON sesql_reindex_schedule (scheduled_at)",
        "CREATE INDEX sesql_reindex_schedule_content_index ON sesql_reindex_schedule (classname, rowid)"
    ]


@config.orm.transactional
def sync_db(cursor, verbosity = 0):
    if not config.orm.table_exists(cursor, config.MASTER_TABLE_NAME):
        create_dictionnary(cursor, execute = True, verbosity = verbosity, include_drop = True)
        create_master_table(cursor, execute = True, verbosity = verbosity, include_drop = True)
    elif verbosity:
        print "SeSQL : Table %s already existed, skipped." % config.MASTER_TABLE_NAME


    for table in typemap.all_tables():