Ejemplo n.º 1
0
    def upgrade(self, sql):
        print('数据库开始初始化')
        with self.app.app_context():
            migrate_directory = self.app.extensions['migrate'].directory

            migrate_path, _, _ = discover_configs()
            migrate_path = os.path.join(migrate_path, migrate_directory)

            if not os.path.exists(os.path.join(migrate_path, 'alembic.ini')):
                # 判断是不是第一次初始化数据库
                is_empty = input('第一次初始化数据库,请确保你的数据库是空的。Y/N? ')
                if is_empty != 'Y':
                    return

                flask_migrate.init(migrate_path)

            flask_migrate.migrate(migrate_path, sql=sql)
            flask_migrate.upgrade(migrate_path, sql=sql)

            if is_new_databases():
                # 写入默认数据
                print('初始化模拟数据')
                init_database_default_analogdata()
                print('初始化默认业务模块')
                init_database_default_datas()

        print("数据库升级完成")
Ejemplo n.º 2
0
def init(ctx, dev, directory):
    """ Initialize new configuration directory.
    """
    from seed.runner.setting import discover_configs, generate_settings

    if directory:
        os.environ['SEED_CONF'] = directory

    directory, py, yaml = discover_configs()

    if directory and not os.path.exists(directory):
        os.makedirs(directory)

    py_contents, yaml_contents = generate_settings(dev)

    if os.path.isfile(yaml):
        click.confirm("File already exists at '%s', overwrite?" %
                      click.format_filename(yaml),
                      abort=True)

    with click.open_file(yaml, 'w') as fp:
        fp.write(yaml_contents)

    if os.path.isfile(py):
        click.confirm("File already exists at '%s', overwrite?" %
                      click.format_filename(py),
                      abort=True)

    with click.open_file(py, 'w') as fp:
        fp.write(py_contents)
Ejemplo n.º 3
0
def upgrade(ctx, sql=False):
    """ Upgrade database data and strcuct
    """
    from seed.services.app import SeedHttpServer
    from seed.runner.setting import discover_configs

    _, config_file, _ = discover_configs()
    SeedHttpServer(workers=1, config_file=config_file).upgrade(sql)
Ejemplo n.º 4
0
def web(bind, workers, debug):
    from seed.services.app import SeedHttpServer
    from seed.runner.setting import discover_configs

    _, config_file, _ = discover_configs()
    http_server = SeedHttpServer(host=bind[0],
                                 port=bind[1],
                                 workers=workers,
                                 config_file=config_file)
    http_server.run()
Ejemplo n.º 5
0
def apply_application():
    _, config_file, _ = discover_configs()
    http_server = SeedHttpServer(config_file=config_file)
    return http_server.app