Beispiel #1
0
    def action_db_migrate(action=('a', 'start'), debug=False):
        """Migrate database.
        This command is responsible for data base migrations.
        Actions:
        init - initiates migration module use only once.
        migrate - creates schema migration.
        upgrade - upgrades database using schema migrations.

        Options:
        - '--debug' use debug configuration
        """
        from flask.ext.migrate import upgrade, init, migrate, stamp, downgrade
        if debug:
            app = make_debug(with_debug_layer=False)
        else:
            app = make_app()

        with app.app_context():
            if action == 'init':
                init()
            elif action == 'migrate':
                migrate()
            elif action == 'upgrade':
                upgrade()
            elif action == 'stamp':
                stamp()
            elif action == 'downgrade':
                downgrade()
            else:
                print('Unknown action')
Beispiel #2
0
    def run(self, addroles=True, revision='head', default=False):
        # migrate database to latest revision
        logger.info('Upgrading DB')
        upgrade(revision=revision)

        if addroles:
            logger.info('Inserting Roles into DB')
            Role.insert_roles()

        admin_role = Role.query.filter_by(name='Administrator').one()

        if default:
            admin_email = current_app.config.get('ADMIN_EMAIL', '*****@*****.**')
        else:
            admin_email = prompt('Admin email', default='*****@*****.**')

        existing = User.query.filter(User.email==admin_email).scalar()
        while existing:
            print('Email already registered. Please provide a different email address')
            admin_email = prompt('Admin email', default='*****@*****.**')
            existing = User.query.filter(User.email==admin_email).scalar()

        admin = User(email=admin_email)

        if default:
            admin.password = '******'
        else:
            admin.password = prompt_pass('Admin password')

        db.session.add(admin)
        db.session.commit()
Beispiel #3
0
def deploy():
    '''Run deployment tasks.'''
    from flask.ext.migrate import upgrade

    # migrate database to latest revision
    upgrade()
    app.run()
Beispiel #4
0
def deploy():
    from flask.ext.migrate import upgrade
    from stepbystep.models import RoleModel

    upgrade()

    RoleModel.insert_roles()
Beispiel #5
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import User

    # migrate database to latest revision
    upgrade()
Beispiel #6
0
def deploy():
    """运行部署任务"""
    from flask.ext.migrate import upgrade
    upgrade()
    Role.insert_roles()
    City.insert_cities()
    Topic.insert_topics()
Beispiel #7
0
def runserver():
    """This command is meant for development. If no configuration is found,
    we start the app listening from all hosts, from port 9999."""

    # Testig Alembic
    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_ver = context.get_current_revision()
    if not current_ver:
        print("Automatic DB Upgrade")
        print("Press Ctrl+C when finished")
        upgrade()
        print("Upgrade completed. Press Ctrl+C and runserver again.")

    try:
        from application import config
        PORT = config.Config.PORT
        DEBUG = config.Config.DEBUG
        HOST = config.Config.HOST
    except ImportError:
        DEBUG = False
        PORT = 9999
        HOST = '0.0.0.0'
    app.run(port=PORT, debug=DEBUG, host=HOST, threaded=True)
Beispiel #8
0
    def run(self, addroles=True, revision='head', default=False):
        # migrate database to latest revision
        logger.info('Upgrading DB')
        upgrade(revision=revision)

        if addroles:
            logger.info('Inserting Roles into DB')
            Role.insert_roles()

        admin_role = Role.query.filter_by(name='Administrator').one()

        if default:
            admin_email = current_app.config.get('ADMIN_EMAIL',
                                                 '*****@*****.**')
        else:
            admin_email = prompt('Admin email', default='*****@*****.**')

        existing = User.query.filter(User.email == admin_email).scalar()
        while existing:
            print(
                'Email already registered. Please provide a different email address'
            )
            admin_email = prompt('Admin email', default='*****@*****.**')
            existing = User.query.filter(User.email == admin_email).scalar()

        admin = User(email=admin_email)

        if default:
            admin.password = '******'
        else:
            admin.password = prompt_pass('Admin password')

        db.session.add(admin)
        db.session.commit()
Beispiel #9
0
def deploy():
	"""Run deployment tasks"""
	from flask.ext.migrate import upgrade
	from app.models import Role, User

	upgrade()
	Role.insert_roles()
Beispiel #10
0
def deploy():
	from flask.ext.migrate import upgrade
	from app.models import Role,User
	
	upgrade()
	
	Role.insert_roles()
Beispiel #11
0
def deploy():
    from flask.ext.migrate import upgrade
    from app.models import Role

    upgrade()

    Role.insert_roles()
Beispiel #12
0
def deploy():
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    upgrade()
    Role.insert_role()
    User.add_self_follows()
def deploy():
	"""迁移数据库并创建用户角色"""
	from flask.ext.migrate import upgrade
	from app.models import Role, User
	
	upgrade()
	Role.insert_roles()
Beispiel #14
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade

    print 'Running deployment tasks...'

    # Migrate database to latest revision
    print 'Migrating database to latest revison...',
    upgrade()
    print 'done'

    print 'Checking for user roles...',
    Role.insert_roles()
    print 'done'

    print 'Checking for Publisher images...'
    Publisher.set_images()
    print 'done'

    if app.config.get('APP_ENV') in ('prod', 'stag'):
        print 'Uploading Static assets to S3...'
        import flask_s3
        flask_s3.create_all(app)
        print 'done'
    else:
        print 'NOT uploading assets to S3, on dev...'
Beispiel #15
0
def deploy(deploy_type):
    import os
    from flask.ext.migrate import upgrade
    from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
        ArticleType, Plugin, BlogView, Comment

    # ADMIN SETTING
    ADMIN_EMAIL = os.environ.get('ADMIN_EMAIL') or "*****@*****.**"
    ADMIN_NAME = os.environ.get('ADMIN_NAME') or "admin"
    ADMIN_PASSWD = os.environ.get('ADMIN_PASSWD') or "admin"

    # upgrade database to the latest version
    upgrade()

    if deploy_type == 'product':
        # step_1:insert basic blog info
        BlogInfo.insert_blog_info()
        # step_2:insert admin account
        User.insert_admin(email=ADMIN_EMAIL,
                          username=ADMIN_NAME,
                          password=ADMIN_PASSWD)
        # step_3:insert system default setting
        ArticleTypeSetting.insert_system_setting()
        # step_4:insert default article sources
        Source.insert_sources()
        # step_5:insert default articleType
        Menu.insert_menus()
        ArticleType.insert_system_articleType()
        ArticleType.insert_articleTypes()
        # step_6:insert system plugin
        Plugin.insert_system_plugin()
        # step_7:insert blog view
        BlogView.insert_view()
Beispiel #16
0
def deploy():
    """Run deployment tasks"""
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    upgrade()
    Role.insert_roles()
Beispiel #17
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    # migrate database to latest revision
    upgrade()
Beispiel #18
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade

    print 'Running deployment tasks...'

    # Migrate database to latest revision
    print 'Migrating database to latest revison...',
    upgrade()
    print 'done'

    print 'Checking for user roles...',
    Role.insert_roles()
    print 'done'

    print 'Checking for Publisher images...'
    Publisher.set_images()
    print 'done'

    if app.config.get('APP_ENV') in ('prod', 'stag'):
        print 'Uploading Static assets to S3...'
        import flask_s3
        flask_s3.create_all(app)
        print 'done'
    else:
        print 'NOT uploading assets to S3, on dev...'
Beispiel #19
0
    def action_db_migrate(action=('a', 'start'), debug=False):
        """Migrate database.
        This command is responsible for data base migrations.
        Actions:
        init - initiates migration module use only once.
        migrate - creates schema migration.
        upgrade - upgrades database using schema migrations.

        Options:
        - '--debug' use debug configuration
        """
        from flask.ext.migrate import upgrade, init, migrate, stamp, downgrade
        if debug:
            app = make_debug(with_debug_layer=False)
        else:
            app = make_app()

        with app.app_context():
            if action == 'init':
                init()
            elif action == 'migrate':
                migrate()
            elif action == 'upgrade':
                upgrade()
            elif action == 'stamp':
                stamp()
            elif action == 'downgrade':
                downgrade()
            else:
                print('Unknown action')
Beispiel #20
0
def runserver():
    """This command is meant for development. If no configuration is found,
    we start the app listening from all hosts, from port 9999."""

    # Testig Alembic
    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_ver = context.get_current_revision()
    if not current_ver:
        print("Automatic DB Upgrade")
        print("Press Ctrl+C when finished")
        upgrade()
        print("Upgrade completed. Press Ctrl+C and runserver again.")

    try:
        from application import config
        PORT = config.Config.PORT
        DEBUG = config.Config.DEBUG
        HOST = config.Config.HOST
    except ImportError:
        DEBUG = False
        PORT = 9999
        HOST = '0.0.0.0'
    app.run(
        port=PORT,
        debug=DEBUG,
        host=HOST,
        threaded=True)
Beispiel #21
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Player, StatsSnapshots

    # migrate database to latest revision
    upgrade()
Beispiel #22
0
def setup_db():
    """Create database and required tables."""
    if not app.config['DATABASE_URI'].startswith('sqlite'):
        try:
            with create_engine(
                app.config['DATABASE_URI'],
            ).connect() as connection:
                connection.execute('CREATE DATABASE {0}'.format(
                    app.config['DATABASE_NAME']))
            print("Database created")
        except sqlalchemy.exc.OperationalError:
            pass
        except sqlalchemy.exc.ProgrammingError:
            # If database already exists
            pass

    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_ver = context.get_current_revision()
    if not current_ver:
        print("Automatic DB Upgrade")
        print("Press Ctrl+C when finished")
        upgrade()
        print("Upgrade completed. Press Ctrl+C and runserver again.")
Beispiel #23
0
def deploy():
    """Run development tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role, User
    upgrade()
    Role.insert_roles()
    User.add_self_follows()
Beispiel #24
0
def deploy():
    from flask.ext.migrate import upgrade
    from app.models import Role, User
    # 数据库迁移至最新版本
    upgrade()
    Role.insert_roles()
    # 让所有用户都关注此用户
    User.add_self_follow()
Beispiel #25
0
def deploy():
    '''Run deployment tasks.'''
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    upgrade()
    Role.inser_roles()
    User.add_self_follows()
def check_db():
    try:
        # Do migration, if there is migration version that is not applied, apply it
        upgrade()
        return True
    except OperationalError, e:
        app.logger.error("Somethings is happen wrong : " + e.message)
        pass
Beispiel #27
0
def deploy():
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    upgrade()

    Role.insert_roles()
    User.add_self_follows()
def deploy():
    from flask.ext.migrate import upgrade
    # upgrade database
    upgrade()
    # init role
    Role.init_roles()
    # user follow self
    User.add_self_follows()
Beispiel #29
0
def upgrade(ctx, tag, sql, revision):
    """Upgrade database"""
    if not len(revision):
        revision = ('head',)

    app = factory(ctx.obj['CONFIG'])
    with app.app_context():
        migrate_extension.upgrade(revision=revision, sql=sql, tag=tag)
def check_db():
    try:
        # Do migration, if there is migration version that is not applied, apply it
        upgrade()
        return True
    except OperationalError, e:
        app.logger.error("Somethings is happen wrong : " + e.message)
        pass
Beispiel #31
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Author, Book, User
    upgrade()
    Author.add_authors()
    Book.add_books()
    User.add_admin()
Beispiel #32
0
def deploy():
    from flask.ext.migrate import upgrade
    from app.models import Role, User
    # 数据库迁移至最新版本
    upgrade()
    Role.insert_roles()
    # 让所有用户都关注此用户
    User.add_self_follow()
Beispiel #33
0
def resetdb():
    """Upgrade database"""
    from elibrarian_app.models import AuthRole

    print("Starting database upgrade:...")
    upgrade()

    print("Creating basic roles:...")
    AuthRole.insert_roles()
Beispiel #34
0
def deploy():
    """Run deployment tasks"""
    from flask.ext.migrate import upgrade
    from app.models import Role, User
    # migrate data base to newest edtion
    upgrade()
    # create user roles
    Role.insert_roles()
    User.add_self_follows()
Beispiel #35
0
def deploy():
    '''Run deploymnet tsks.'''
    from flask.ext.migrate import upgrade, migrate
    from flasky import Role, User
    migrate()
    upgrade()

    Role.insert_roles()
    User.add_self_follows()
Beispiel #36
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import User, Tag
    # migrate database to most recent revision
    upgrade()

    # add tag names
    Tag.insert_tags()
Beispiel #37
0
def deploy():
    """run deployment tasks"""
    from flask.ext.migrate import upgrade
    from app.models.user import Role

    print(config_name)

    upgrade()
    Role.insert_roles()
Beispiel #38
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import User, Tag
    # migrate database to most recent revision
    upgrade()

    # add tag names
    Tag.insert_tags()
Beispiel #39
0
def upgrade():
    log.info("Beginning database migration...")
    migrate.upgrade()
    log.info("Ensuring database fixtures exist...")
    make_fixtures()
    log.info("Reconfiguring the search index...")
    init_search()
    log.info("Re-indexing any existing database objects...")
    reindex()
Beispiel #40
0
def deploy():
    """run deployment tasks"""
    from flask.ext.migrate import upgrade
    from app.models.user import Role

    print(config_name)

    upgrade()
    Role.insert_roles()
Beispiel #41
0
def deploy():
    from flask.ext.migrate import upgrade
    from app.models import Role, User
    #把数据库迁移到最新修订版本
    upgrade()
    #创建用户角色
    Role.insert_roles()
    #让所有用户都关注此用户
    User.add_self_follows()
Beispiel #42
0
def upgrade():
    log.info("Beginning database migration...")
    migrate.upgrade()
    log.info("Ensuring database fixtures exist...")
    make_fixtures()
    log.info("Reconfiguring the search index...")
    init_search()
    log.info("Re-indexing any existing database objects...")
    reindex()
Beispiel #43
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    # migrate database to latest revision
    upgrade()
    # create user roles
    Role.insert_roles()
    # create self-follows for all users
    User.add_self_follows()    
Beispiel #44
0
def create_test_environment():
    app = create_app('test')
    Manager(app)
    db = get_registry()['DB']
    Migrate(app, db)
    with app.app_context():
        upgrade()
    set_app(app)
    return app
Beispiel #45
0
def setup_db():
    """Create database and required tables."""
    if not app.config['DATABASE_URI'].startswith('sqlite'):
        try:
            with create_engine(
                    app.config['DATABASE_URI'], ).connect() as connection:
                connection.execute('CREATE DATABASE {0}'.format(
                    app.config['DATABASE_NAME']))
            print("Database created")
        except sqlalchemy.exc.OperationalError:
            pass
        except sqlalchemy.exc.ProgrammingError:
            # If database already exists
            pass

    engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_ver = context.get_current_revision()
    if not current_ver:
        print("Automatic DB Upgrade")
        print("Press Ctrl+C when finished")
        upgrade()
        print("Upgrade completed. Press Ctrl+C and runserver again.")

    # TODO: search for the task_compilers and ask for required commands accordigly
    # Render Config
    render_config = JobType.query.filter_by(
        name='simple_blender_render').first()
    if not render_config:
        configuration = {
            'commands': {
                'default': {
                    'Linux': '',
                    'Darwin': '',
                    'Windows': ''
                }
            }
        }
        print(
            "Please enter the shared blender path for the simple_blender_render command"
        )
        configuration['commands']['default']['Linux'] = raw_input(
            'Linux path: ')
        configuration['commands']['default']['Darwin'] = raw_input(
            'OSX path: ')
        configuration['commands']['default']['Windows'] = raw_input(
            'Windows path: ')

        render_config = JobType(name='simple_blender_render',
                                properties=json.dumps(configuration))
        db.session.add(render_config)
        render_config = JobType(name='blender_simple_render',
                                properties=json.dumps(configuration))
        db.session.add(render_config)
        db.session.commit()
Beispiel #46
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import  User

    # migrate database to latest revision
    upgrade()

    # create self-follows for all users
    User.add_self_follows()
Beispiel #47
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role, User
    # migrate database
    upgrade()
    # create user
    Role.insert_roles()
    # have all users focus a itself
    User.add_self_follows()
Beispiel #48
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role, User
    # migrate database
    upgrade()
    # create user
    Role.insert_roles()
    # have all users focus a itself
    User.add_self_follows()
Beispiel #49
0
def deploy():
    """ Run deployment tasks """
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    # migrate the DB to newest version
    upgrade()

    # Create User roles
    Role.insert_roles()
Beispiel #50
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade

    # migrate database to latest revision
    upgrade()

    Users.insert_default_user()

    print('>>> Deployment Successful')
Beispiel #51
0
def deploy():
    from flask.ext.migrate import upgrade

    # migrate database to latest revision
    upgrade()

    # create teaaher1
    Teacher.add_teacher1()
    # create stu1
    Student.add_stu1()
Beispiel #52
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from app.models import Role

    # migrate database to latest revision
    upgrade()

    # create user roles
    Role.insert_roles()
Beispiel #53
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from wtxlog.models import Role, User

    upgrade()
    #db.create_all()

    # create user roles
    Role.insert_roles()
Beispiel #54
0
def deploy():
    """Run deployment tasks."""
    from flask.ext.migrate import upgrade
    from wtxlog.models import Role

    upgrade()
    # db.create_all()

    # create user roles
    Role.insert_roles()
Beispiel #55
0
    def migrate():
        now_str = datetime.datetime.now().strftime('%d-%m-%y-%H:%M')
        try:
            init_migrations()
        except CommandError as e:
            # Already initiated .., all good!
            pass

        migrate(message='silverflask_%s' % now_str)
        upgrade()
        return 'We\'ve upgraded the ship'
Beispiel #56
0
def deploy():
    """ Run deployment tasks. """
    from flask.ext.migrate import upgrade

    # migrate database to latest revision
    upgrade()

    init_models = list()
    init_models.append((Vendor, ["Unknown", "Cisco", "Avaya", "HP"]))
    system_categories = (SystemCategory, [
        "Unknown", "Load Balancer", "Router", "Switch", "Firewall", "Server"
    ])
    init_models.append(system_categories)
    init_models.append((L2Domain, ["Unknown", "None", "L2D"]))
    init_models.append(
        (HardwareType, ["Chassis", "Line Card", "Power Supply", "SFP"]))

    for model, init_items in init_models:
        for init_item in init_items:
            m = model()
            m.name = init_item
            db.session.add(m)
            db.session.commit()
            m.add_index()

    software = Software()
    software.name = "IOS"
    software.vendor = Vendor.query.filter_by(name="Cisco").first()
    db.session.add(software)
    db.session.commit()
    software.add_index()
    software = Software()
    software.name = "NXOS"
    software.vendor = Vendor.query.filter_by(name="Cisco").first()
    db.session.add(software)
    db.session.commit()
    software.add_index()

    with open("iso-3166-2.txt", "r") as f:
        country_codes = f.readlines()

    country_codes.insert(0, "?? Unknown")

    for line in country_codes:
        line = line.split()
        code = line[0]
        country = " ".join(line[1::])
        c = Country()
        c.name = country
        c.code = code
        db.session.add(c)
        db.session.commit()
        c.add_index()
Beispiel #57
0
def deploy():
    """Run deployment tasks"""
    from flask.ext.migrate import upgrade
    from app.models import Role, User

    # migrate data base to newest edtion
    upgrade()

    # create user roles
    Role.insert_roles()

    User.add_self_follows()