当前位置: 首页>>代码示例>>Python>>正文


Python functions.drop_database函数代码示例

本文整理汇总了Python中sqlalchemy_utils.functions.drop_database函数的典型用法代码示例。如果您正苦于以下问题:Python drop_database函数的具体用法?Python drop_database怎么用?Python drop_database使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了drop_database函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: populate

def populate(bulk_data, test_data, posts, topics, force, initdb):
    """Creates the necessary tables and groups for FlaskBB."""
    if force:
        click.secho("[+] Recreating database...", fg="cyan")
        drop_database(db.engine.url)

        # do not initialize the db if -i is passed
        if not initdb:
            upgrade_database()

    if initdb:
        click.secho("[+] Initializing database...", fg="cyan")
        upgrade_database()

    if test_data:
        click.secho("[+] Adding some test data...", fg="cyan")
        create_test_data()

    if bulk_data:
        timer = time.time()
        topic_count, post_count = insert_bulk_data(int(topics), int(posts))
        elapsed = time.time() - timer
        click.secho("[+] It took {} seconds to create {} topics and {} posts"
                    .format(elapsed, topic_count, post_count), fg="cyan")

    # this just makes the most sense for the command name; use -i to
    # init the db as well
    if not test_data:
        click.secho("[+] Populating the database with some defaults...",
                    fg="cyan")
        create_default_groups()
        create_default_settings()
开发者ID:djsilcock,项目名称:flaskbb,代码行数:32,代码来源:main.py

示例2: install

def install(welcome, force, username, email, password, group):
    """Installs flaskbb. If no arguments are used, an interactive setup
    will be run.
    """
    click.secho("[+] Installing FlaskBB...", fg="cyan")
    if database_exists(db.engine.url):
        if force or click.confirm(click.style(
            "Existing database found. Do you want to delete the old one and "
            "create a new one?", fg="magenta")
        ):
            drop_database(db.engine.url)
        else:
            sys.exit(0)
    create_database(db.engine.url)
    upgrade_database()

    click.secho("[+] Creating default settings...", fg="cyan")
    create_default_groups()
    create_default_settings()

    click.secho("[+] Creating admin user...", fg="cyan")
    prompt_save_user(username, email, password, group)

    if welcome:
        click.secho("[+] Creating welcome forum...", fg="cyan")
        create_welcome_forum()

    click.secho("[+] Compiling translations...", fg="cyan")
    compile_translations()

    click.secho("[+] FlaskBB has been successfully installed!",
                fg="green", bold=True)
开发者ID:djsilcock,项目名称:flaskbb,代码行数:32,代码来源:main.py

示例3: test_alembic_and_db_create_match

def test_alembic_and_db_create_match(clean_app):
    """Check that alembic recipes and alembic models are in sync."""
    with clean_app.app_context():
        ext = clean_app.extensions['invenio-db']
        if db.engine.name == 'sqlite':
            raise pytest.skip('Upgrades are not supported on SQLite.')

        # Make sure that alembic upgrades can be run now
        ext.alembic.upgrade()
        constraints = get_all_constraints(clean_app)
        alembic_constraint_names = [x[0] for x in constraints]

        # Recreate the database with alembic only (without migrating)
        db.session.remove()
        drop_database(db.engine.url)
        db.engine.dispose()
        create_database(db.engine.url)
        db.create_all()

        # Check that the resulting state is in sync with alembic metaData
        assert not ext.alembic.compare_metadata()

        # Check that the constraints are the same. This is needed because
        # alembic.compare_metadata does not check all constraints.
        constraints = get_all_constraints(clean_app)
        db_create_constraint_names = [x[0] for x in constraints]
        assert set(alembic_constraint_names) == set(db_create_constraint_names)
开发者ID:EUDAT-B2SHARE,项目名称:b2share,代码行数:27,代码来源:test_upgrade.py

示例4: clean_app

def clean_app(request, base_app):
    """Application with database and elasticsearch cleaned."""
    with base_app.app_context():
        try:
            db.session.remove()
            drop_database(db.engine.url)
        except ProgrammingError:
            pass
        create_database(db.engine.url)
        # reset elasticsearch
        for deleted in current_search.delete(ignore=[404]):
            pass
        # reset queues
        current_queues.delete()
        current_queues.declare()

    yield base_app

    def finalize():
        with base_app.app_context():
            db.session.remove()
            drop_database(db.engine.url)
            # Dispose the engine in order to close all connections. This is
            # needed for sqlite in memory databases.
            db.engine.dispose()
            current_queues.delete()
    request.addfinalizer(finalize)

    return base_app
开发者ID:EUDAT-B2SHARE,项目名称:b2share,代码行数:29,代码来源:conftest.py

示例5: tearDownClass

 def tearDownClass(cls):
     cls.transaction.rollback()
     cls.connection.close()
     cls.engine.dispose()
     if cls.create:
         drop_database(cls.engine.url)
     super(StoreTestCase, cls).tearDownClass()
开发者ID:deliveryhero,项目名称:lymph-sqlalchemy,代码行数:7,代码来源:testing.py

示例6: base_app

def base_app():
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()
    base_app = Flask(__name__, instance_path=instance_path)

    base_app.config.update(
        ACCOUNTS_USE_CELERY=False,
        LOGIN_DISABLED=False,
        SECRET_KEY='testing_key',
        SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI',
                                          'sqlite://'),
        TEST_USER_EMAIL='[email protected]',
        TEST_USER_PASSWORD='test_password',
        TESTING=True,
        WTF_CSRF_ENABLED=False,
    )
    Babel(base_app)
    Mail(base_app)
    Menu(base_app)
    InvenioDB(base_app)
    InvenioAccounts(base_app)
    base_app.register_blueprint(accounts_blueprint)

    with base_app.app_context():
        if str(db.engine.url) != "sqlite://" and \
                not database_exists(str(db.engine.url)):
            create_database(str(db.engine.url))
        db.create_all()

    yield base_app

    with base_app.app_context():
        drop_database(str(db.engine.url))
    shutil.rmtree(instance_path)
开发者ID:inveniosoftware,项目名称:invenio-userprofiles,代码行数:34,代码来源:conftest.py

示例7: teardown

 def teardown():
     with app.app_context():
         drop_database(str(db.engine.url))
         # Delete sessions in kvsession store
         if hasattr(app, 'kvsession_store'):
             for key in app.kvsession_store.iter_keys():
                 app.kvsession_store.delete(key)
     shutil.rmtree(instance_path)
开发者ID:eamonnmag,项目名称:invenio-accounts,代码行数:8,代码来源:conftest.py

示例8: engine

def engine(dsn):
    if database_exists(dsn):
        drop_database(dsn)
    create_database(dsn)
    engine = create_engine(dsn)
    engine.execute('CREATE EXTENSION postgis')
    GeonameBase.metadata.create_all(bind=engine)
    return engine
开发者ID:jmagnusson,项目名称:sqlalchemy-geonames,代码行数:8,代码来源:test_base.py

示例9: teardown

 def teardown():
     with app.app_context():
         drop_database(str(db.engine.url))
         # Delete sessions in kvsession store
         if hasattr(app, 'kvsession_store') and \
                 isinstance(app.kvsession_store, RedisStore):
             app.kvsession_store.redis.flushall()
     shutil.rmtree(app.instance_path)
开发者ID:lnielsen,项目名称:invenio-accounts,代码行数:8,代码来源:conftest.py

示例10: db

def db(app):
    """Database fixture."""
    if not database_exists(str(db_.engine.url)):
        create_database(str(db_.engine.url))
    db_.create_all()
    yield db_
    db_.session.remove()
    drop_database(str(db_.engine.url))
开发者ID:inveniosoftware,项目名称:invenio-records-files,代码行数:8,代码来源:conftest.py

示例11: finalize

 def finalize():
     with base_app.app_context():
         db.session.remove()
         drop_database(db.engine.url)
         # Dispose the engine in order to close all connections. This is
         # needed for sqlite in memory databases.
         db.engine.dispose()
         current_queues.delete()
开发者ID:EUDAT-B2SHARE,项目名称:b2share,代码行数:8,代码来源:conftest.py

示例12: test_db

def test_db():
    """Test database backend."""
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
        'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'
    )
    FlaskCLI(app)
    InvenioDB(app)
    InvenioRecords(app)

    with app.app_context():
        create_database(db.engine.url)
        db.create_all()
        assert len(db.metadata.tables) == 3

    data = {'title': 'Test'}
    from invenio_records.models import RecordMetadata as RM

    # Create a record
    with app.app_context():
        assert RM.query.count() == 0

        record_uuid = Record.create(data).id
        db.session.commit()

        assert RM.query.count() == 1
        db.session.commit()

    # Retrieve created record
    with app.app_context():
        record = Record.get_record(record_uuid)
        assert record.dumps() == data
        with pytest.raises(NoResultFound):
            Record.get_record(uuid.uuid4())
        record['field'] = True
        record = record.patch([
            {'op': 'add', 'path': '/hello', 'value': ['world']}
        ])
        assert record['hello'] == ['world']
        record.commit()
        db.session.commit()

    with app.app_context():
        record2 = Record.get_record(record_uuid)
        assert record2.model.version_id == 2
        assert record2['field']
        assert record2['hello'] == ['world']
        db.session.commit()

    # Cannot commit record without model (i.e. Record.create_record)
    with app.app_context():
        record3 = Record({'title': 'Not possible'})
        with pytest.raises(RecordNotCommitableError):
            record3.commit()

    with app.app_context():
        db.drop_all()
        drop_database(db.engine.url)
开发者ID:JavierDelgadoFernandez,项目名称:invenio-records,代码行数:58,代码来源:test_invenio_records.py

示例13: app

def app():
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()
    app = Flask('testapp', instance_path=instance_path)
    app.config.update(
        CELERY_ALWAYS_EAGER=True,
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        CELERY_RESULT_BACKEND='cache',
        JSONSCHEMAS_HOST='inveniosoftware.org',
        TESTING=True,
        SECRET_KEY='CHANGE_ME',
        SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                               'sqlite://'),
        SQLALCHEMY_TRACK_MODIFICATIONS=True,
        SERVER_NAME='app',
        OAISERVER_RECORD_INDEX='_all',
        # Disable set signals because the celery tasks cannot be run
        # synchronously
        OAISERVER_REGISTER_SET_SIGNALS=False,
        SEARCH_ELASTIC_KEYWORD_MAPPING={None: ['_all']},
    )
    if not hasattr(app, 'cli'):
        from flask_cli import FlaskCLI
        FlaskCLI(app)
    InvenioDB(app)
    FlaskCeleryExt(app)
    InvenioJSONSchemas(app)
    InvenioRecords(app)
    InvenioPIDStore(app)
    InvenioMARC21(app)
    client = Elasticsearch(hosts=[os.environ.get('ES_HOST', 'localhost')])
    search = InvenioSearch(app, client=client)
    search.register_mappings('records', 'data')
    InvenioIndexer(app)
    InvenioOAIServer(app)

    app.register_blueprint(blueprint)

    with app.app_context():
        if str(db.engine.url) != 'sqlite://' and \
           not database_exists(str(db.engine.url)):
                create_database(str(db.engine.url))
        db.create_all()
        list(search.create(ignore=[400]))
        sleep(5)

    with app.app_context():
        yield app

    with app.app_context():
        db.session.close()
        if str(db.engine.url) != 'sqlite://':
            drop_database(str(db.engine.url))
        list(search.delete(ignore=[404]))
    shutil.rmtree(instance_path)
开发者ID:inveniosoftware,项目名称:invenio-oaiserver,代码行数:56,代码来源:conftest.py

示例14: database

def database(app):
    """Ensure that the database schema is created."""
    if not database_exists(str(db_.engine.url)):
        create_database(str(db_.engine.url))
    db_.drop_all()
    db_.create_all()

    yield db_

    drop_database(str(db_.engine.url))
开发者ID:duncanwp,项目名称:zenodo,代码行数:10,代码来源:conftest.py

示例15: test_migrations_upgrade

def test_migrations_upgrade():
    with pytest.raises(OperationalError):
        User.query.all()

    # ensure that the database is created
    create_database(db.engine.url)

    alembic.upgrade()
    assert len(User.query.all()) == 0

    drop_database(db.engine.url)
开发者ID:eirnym,项目名称:flaskbb,代码行数:11,代码来源:test_populate.py


注:本文中的sqlalchemy_utils.functions.drop_database函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。