Example #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--recreate',
                        help='Drop and re-create all tables.',
                        action='store_true')
    parser.add_argument('--dog-csv',
                        help='The csv file containing the Dog_info table.')
    parser.add_argument('--user-csv',
                        help='The csv file containing the auth table.')
    parser.add_argument('--app-csv',
                        help='The csv file containing the Apps table.')
    args = parser.parse_args()

    if args.recreate:
        print "Dropping all tables."
        db.drop_all()
        print "Creating all tables."
        db.create_all()
        print "Stamping alembic @ HEAD."
        with app.app_context():
            Migrate(app, db, directory=pkg_resources.resource_filename('crrr', 'migrations'))
            command.stamp(_get_config(None), 'head')
    if args.dog_csv:
        import_dogs(args.dog_csv)
    if args.user_csv:
        import_users(args.user_csv)
    if args.app_csv:
        import_apps(args.app_csv)
Example #2
0
 def heads():
     config = _get_config(None)
     script = ScriptDirectory.from_config(config)
     with EnvironmentContext(config, script) as ctx:
         print(ctx.get_head_revisions())
         print(script.get_current_head())
         rev = script.get_current_head()
         mig = script.get_revision(rev)
         print(mig)
         with open(mig.path, 'r') as fp:
             return fp.read()
Example #3
0
def reset():
    """ Reset the current DB
    """

    drop = prompt_bool('Drop all tables? All data will be lost...')
    if drop:
        db.drop_all()
        db.session.commit()

        config = _get_config(None)
        alembic.command.stamp(config, 'base')
        alembic.command.upgrade(config, 'head')
Example #4
0
 def heads():
     config = _get_config(None)
     script = ScriptDirectory.from_config(config)
     with EnvironmentContext(
             config,
             script
         ) as ctx:
         print(ctx.get_head_revisions())
         print(script.get_current_head())
         rev = script.get_current_head()
         mig = script.get_revision(rev)
         print(mig)
         with open(mig.path, 'r') as fp:
             return fp.read()
Example #5
0
def create(force=False):
    """Create tables if the database has not been configured yet."""
    # Fail if there's an alembic version set
    engine = db.get_engine(flask.current_app)
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_rev = context.get_current_revision()
    alembic_config = _get_config(directory=migrate_path)
    script = ScriptDirectory.from_config(alembic_config)
    latest_rev = script.get_current_head()
    if current_rev == latest_rev and not force:
        print(u"You need to run 'evesrp -c config.py db migrate' to "
              u"migrate to the latest database schema.")
    else:
        db.create_all()
        if current_rev is None:
            stamp()
Example #6
0
def create(force=False):
    """Create tables if the database has not been configured yet."""
    # Fail if there's an alembic version set
    engine = db.get_engine(flask.current_app)
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_rev = context.get_current_revision()
    alembic_config = _get_config(directory=migrate_path)
    script = ScriptDirectory.from_config(alembic_config)
    latest_rev = script.get_current_head()
    if current_rev == latest_rev and not force:
        print(u"You need to run 'evesrp -c config.py db migrate' to "
              u"migrate to the latest database schema.")
    else:
        db.create_all()
        if current_rev is None:
            stamp()
Example #7
0
def runserver(ssl=False, host='0.0.0.0', port=5000, migrate=False):
    """ Customised run server function so we can run the development server
    with custom arguments.
    """

    # Run migrations before server start
    if migrate:
        config = _get_config(None)
        alembic.command.upgrade(config, 'head')

    # Host / Port Config
    kwagrs = {
        'host': host,
        'port': int(port)
    }

    # Run with SSL?
    if ssl:
        kwagrs['ssl_context'] = 'adhoc'

    app.run(**kwagrs)