# Path: checkmate/management/helpers.py
# def get_project_config(path):
#     with open(os.path.join(path,".checkmate/config.json"),"r") as config_file:
#         return json.loads(config_file.read())
# 
# def get_backend(project_path,project_config,settings,echo = False,initialize_db = True):
#     backend_config = project_config['backend']
#     engine = create_engine('sqlite:///%s' % os.path.join(project_path,'.checkmate/db.sqlite'),echo=echo)
#     backend = SqlBackend(engine)
# 
#     if initialize_db:
#         backend.create_schema()
#         return backend
# 
#         #we run the Alembic migration script.
#         print("Running migrations...")
#         from checkmate.management.commands.alembic import Command as AlembicCommand
#         alembic_command = AlembicCommand(None,backend,args = ['upgrade','head'])
#         alembic_command.run()
#         print("Done running migrations...")
# 
#     return backend
# 
# def get_project_path(path = None):
#     if not path:
#         path = os.getcwd()
#     while path != "/":
#         config_path = os.path.join(path,'.checkmate')
#         if os.path.exists(config_path) and os.path.isdir(config_path):
#             return path
#         path = os.path.dirname(path)
#     return None


from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from blitzdb.backends.sql import Backend as SqlBackend
from checkmate.management.helpers import get_project_config,get_backend,get_project_path
from __future__ import with_statement


config = context.config
fileConfig(config.config_file_name)

def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """


# Path: checkmate/management/helpers.py
# def get_project_config(path):
#     with open(os.path.join(path,".checkmate/config.json"),"r") as config_file:
#         return json.loads(config_file.read())
# 
# def get_backend(project_path,project_config,settings,echo = False,initialize_db = True):
#     backend_config = project_config['backend']
#     engine = create_engine('sqlite:///%s' % os.path.join(project_path,'.checkmate/db.sqlite'),echo=echo)
#     backend = SqlBackend(engine)
# 
#     if initialize_db:
#         backend.create_schema()
#         return backend
# 
#         #we run the Alembic migration script.
#         print("Running migrations...")
#         from checkmate.management.commands.alembic import Command as AlembicCommand
#         alembic_command = AlembicCommand(None,backend,args = ['upgrade','head'])
#         alembic_command.run()
#         print("Done running migrations...")
# 
#     return backend
# 
# def get_project_path(path = None):
#     if not path:
#         path = os.getcwd()
#     while path != "/":
#         config_path = os.path.join(path,'.checkmate')
#         if os.path.exists(config_path) and os.path.isdir(config_path):
#             return path
#         path = os.path.dirname(path)
#     return None


# Path: checkmate/migrations/env.py
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from blitzdb.backends.sql import Backend as SqlBackend
from checkmate.management.helpers import get_project_config,get_backend,get_project_path

from __future__ import with_statement


config = context.config
fileConfig(config.config_file_name)

def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """


    project_path = get_project_path()