本文整理汇总了Python中sqlalchemy_utils.functions.database_exists函数的典型用法代码示例。如果您正苦于以下问题:Python database_exists函数的具体用法?Python database_exists怎么用?Python database_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了database_exists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: db_exists
def db_exists(cls, db_name=None):
if not db_name:
raise RegistryException('db_name is required')
urls = []
url = Configuration.get('db_url')
if url:
urls.append(url)
wo_url = Configuration.get('db_wo_url')
if wo_url:
urls.append(wo_url)
for ro_url in Configuration.get('db_ro_urls', []) or []:
urls.append(ro_url)
gurl = Configuration.get('get_url', get_url)
for url in urls:
url = gurl(db_name=db_name, url=url)
if not database_exists(url):
return False
else:
return database_exists(gurl(db_name=db_name))
return True
开发者ID:anybox,项目名称:AnyBlok_Multi_Engines,代码行数:25,代码来源:registry.py
示例2: app
def app(request):
"""Flask application fixture."""
instance_path = tempfile.mkdtemp()
app = Flask('testapp', instance_path=instance_path)
app.config.update(
TESTING=True,
SERVER_NAME='localhost:5000',
SQLALCHEMY_DATABASE_URI=os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'
)
)
FlaskCLI(app)
InvenioDB(app)
InvenioREST(app)
InvenioRecords(app)
InvenioPIDStore(app)
InvenioRecordsREST(app)
with app.app_context():
if not database_exists(str(db.engine.url)) and \
app.config['SQLALCHEMY_DATABASE_URI'] != 'sqlite://':
create_database(db.engine.url)
db.drop_all()
db.create_all()
def finalize():
with app.app_context():
db.drop_all()
if app.config['SQLALCHEMY_DATABASE_URI'] != 'sqlite://':
drop_database(db.engine.url)
shutil.rmtree(instance_path)
request.addfinalizer(finalize)
return app
开发者ID:drjova,项目名称:invenio-records-rest,代码行数:34,代码来源:conftest.py
示例3: app
def app(request):
"""Flask application fixture."""
instance_path = tempfile.mkdtemp()
app = Flask('testapp', instance_path=instance_path)
Babel(app)
FlaskCLI(app)
InvenioDB(app)
LoginManager(app)
app.admin_app = InvenioAdmin(app)
protected_view = protected_adminview_factory(TestModelView)
app.admin_app.admin.add_view(protected_view(TestModel, db.session))
app.config.update(
TESTING=True,
SECRET_KEY="SECRET_KEY",
)
with app.app_context():
if not database_exists(str(db.engine.url)):
create_database(str(db.engine.url))
db.drop_all()
db.create_all()
def teardown():
with app.app_context():
drop_database(str(db.engine.url))
shutil.rmtree(instance_path)
request.addfinalizer(teardown)
return app
开发者ID:jirikuncar,项目名称:invenio-admin,代码行数:30,代码来源:conftest.py
示例4: 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
示例5: app
def app(request):
"""Flask application fixture."""
app = create_app(
CELERY_ALWAYS_EAGER=True,
CELERY_CACHE_BACKEND="memory",
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
CELERY_RESULT_BACKEND="cache",
DEBUG_TB_ENABLED=False,
SECRET_KEY="CHANGE_ME",
SECURITY_PASSWORD_SALT="CHANGE_ME",
MAIL_SUPPRESS_SEND=True,
SQLALCHEMY_DATABASE_URI=os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'),
TESTING=True,
)
with app.app_context():
if not database_exists(str(db.engine.url)):
create_database(str(db.engine.url))
db.drop_all()
db.create_all()
list(current_search.create())
def teardown():
with app.app_context():
drop_database(str(db.engine.url))
list(current_search.delete(ignore=[404]))
request.addfinalizer(teardown)
return app
开发者ID:anukat2015,项目名称:zenodo,代码行数:31,代码来源:conftest.py
示例6: app
def app(request):
"""Flask application fixture."""
instance_path = tempfile.mkdtemp()
app = Flask('testapp', instance_path=instance_path)
app.config.update(
BROKER_URL=os.environ.get('BROKER_URL', 'memory://'),
CELERY_ALWAYS_EAGER=True,
CELERY_CACHE_BACKEND="memory",
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
CELERY_RESULT_BACKEND="cache",
SQLALCHEMY_DATABASE_URI=os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'),
SQLALCHEMY_TRACK_MODIFICATIONS=False,
TESTING=True,
)
FlaskCLI(app)
FlaskCeleryExt(app)
InvenioDB(app)
InvenioRecords(app)
InvenioSearch(app)
InvenioIndexer(app)
with app.app_context():
if not database_exists(str(db.engine.url)):
create_database(str(db.engine.url))
db.create_all()
def teardown():
with app.app_context():
drop_database(str(db.engine.url))
shutil.rmtree(instance_path)
request.addfinalizer(teardown)
return app
开发者ID:lnielsen,项目名称:invenio-indexer,代码行数:34,代码来源:conftest.py
示例7: init
def init(db_url, engine_args=None, session_args=None, trans_mgr=None,
scoped=False):
alembic_d = Path(__file__).parent
alembic_cfg = alembic.config.Config(str(alembic_d / "alembic.ini"))
alembic_cfg.set_main_option("sqlalchemy.url", db_url)
log.debug(f"Checking for database '{safeDbUrl(db_url)}'")
if not database_exists(db_url):
log.info(f"Creating database '{safeDbUrl(db_url)}'")
create_database(db_url, template="template0")
log.debug(f"Connecting to database '{safeDbUrl(db_url)}'")
args = engine_args or DEFAULT_ENGINE_ARGS
engine = create_engine(db_url, **args)
connection = engine.connect()
args = session_args or DEFAULT_SESSION_ARGS
if trans_mgr:
args.update({"extension": trans_mgr})
SessionMaker = sessionmaker(bind=engine, **args)
if scoped:
SessionMaker = scoped_session(SessionMaker)
for T in TYPES:
T.metadata.bind = engine
# Upgrade to head (i.e. this) revision, or no-op if they match
with cd(str(alembic_d)):
alembic.command.upgrade(alembic_cfg, "head")
return DatabaseInfo(engine, SessionMaker, connection)
开发者ID:nicfit,项目名称:mishmash,代码行数:31,代码来源:database.py
示例8: isEnabled
def isEnabled(configs):
return database_exists(SQLALCHEMY_DATABASE_URI(
name=__class__.__bind_key__,
project_path=configs['PROJECT_PATH'],
category='Census',
flags=configs['MARRYBIRD_FLAGS'],
))
开发者ID:minhoryang,项目名称:marrybird-api,代码行数:7,代码来源:comment.py
示例9: app
def app(request):
"""Flask application fixture."""
app = Flask('testapp')
app.config.update(
TESTING=True,
SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI',
'sqlite://'),
SERVER_NAME='localhost',
)
Babel(app)
Menu(app)
Breadcrumbs(app)
InvenioDB(app)
InvenioCollections(app)
InvenioRecords(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()
def teardown():
with app.app_context():
if str(db.engine.url) != 'sqlite://':
drop_database(str(db.engine.url))
request.addfinalizer(teardown)
with app.app_context():
db.create_all()
return app
开发者ID:tiborsimko,项目名称:invenio-collections,代码行数:35,代码来源:conftest.py
示例10: app
def app(request):
"""Flask application fixture."""
# Set temporary instance path for sqlite
instance_path = tempfile.mkdtemp()
app = Flask("testapp", instance_path=instance_path)
InvenioDB(app)
InvenioPIDStore(app)
app.config.update(
SQLALCHEMY_DATABASE_URI=os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite:///test.db"), TESTING=True
)
with app.app_context():
if not database_exists(str(db.engine.url)):
create_database(str(db.engine.url))
db.drop_all()
db.create_all()
def teardown():
with app.app_context():
drop_database(str(db.engine.url))
shutil.rmtree(instance_path)
request.addfinalizer(teardown)
return app
开发者ID:hachreak,项目名称:invenio-pidstore,代码行数:26,代码来源:conftest.py
示例11: 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.drop_all()
db.create_all()
def teardown():
drop_database(str(db.engine.url))
shutil.rmtree(instance_path)
return base_app
开发者ID:tiborsimko,项目名称:invenio-userprofiles,代码行数:35,代码来源:conftest.py
示例12: records_app
def records_app(request):
"""Initialize InvenioRecords."""
app = Flask('records_testapp')
FlaskCLI(app)
app.config.update(
TESTING=True,
SQLALCHEMY_DATABASE_URI=os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'
),
)
InvenioDB(app)
from invenio_records import InvenioRecords
from invenio_db import db
InvenioRecords(app)
InvenioSearch(app)
with app.app_context():
if not database_exists(str(db.engine.url)):
create_database(str(db.engine.url))
db.create_all()
def teardown():
with app.app_context():
db.drop_all()
request.addfinalizer(teardown)
return app
开发者ID:JavierDelgadoFernandez,项目名称:invenio-search,代码行数:27,代码来源:conftest.py
示例13: script_info
def script_info(request):
"""Get ScriptInfo object for testing CLI."""
instance_path = tempfile.mkdtemp()
app = Flask('testapp', instance_path=instance_path)
app.config.update(
ACCOUNTS_USE_CELERY=False,
SECRET_KEY="CHANGE_ME",
SECURITY_PASSWORD_SALT="CHANGE_ME_ALSO",
SQLALCHEMY_DATABASE_URI=os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'),
TESTING=True,
)
FlaskCLI(app)
Babel(app)
Mail(app)
InvenioDB(app)
InvenioAccounts(app)
with app.app_context():
if not database_exists(str(db.engine.url)):
create_database(str(db.engine.url))
db.drop_all()
db.create_all()
def teardown():
with app.app_context():
drop_database(str(db.engine.url))
shutil.rmtree(instance_path)
request.addfinalizer(teardown)
return ScriptInfo(create_app=lambda info: app)
开发者ID:eamonnmag,项目名称:invenio-accounts,代码行数:31,代码来源:conftest.py
示例14: create_app
def create_app():
from colorama import init
init()
from config import add_configs
app = add_configs(Flask(__name__))
from sqlalchemy_utils.functions import database_exists, create_database
if not database_exists(app.config.get('SQLALCHEMY_DATABASE_URI')):
create_database(app.config.get('SQLALCHEMY_DATABASE_URI'), encoding='utf8')
with app.app_context():
from models import db
db.init_app(app)
app.db = db
from models.oauth2 import oauth2_provider
oauth2_provider.init_app(app)
# import models
Migrate(app, db, directory='bin/migrations/')
mgr = Manager(app)
mgr.add_command('db', MigrateCommand)
return mgr
开发者ID:st2forget,项目名称:flask-restful,代码行数:26,代码来源:migrations.py
示例15: app
def app(request):
"""Flask application fixture."""
instance_path = tempfile.mkdtemp()
app = Flask('testapp', instance_path=instance_path)
app.config.update(
LOGIN_DISABLED=False,
MAIL_SUPPRESS_SEND=True,
SECRET_KEY='changeme',
SERVER_NAME='example.com',
SQLALCHEMY_DATABASE_URI=os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite://'),
TESTING=True,
WTF_CSRF_ENABLED=False,
)
Babel(app)
Menu(app)
Breadcrumbs(app)
InvenioDB(app)
InvenioAccounts(app)
InvenioGroups(app)
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()
def teardown():
with app.app_context():
if str(db.engine.url) != 'sqlite://':
drop_database(str(db.engine.url))
shutil.rmtree(instance_path)
request.addfinalizer(teardown)
return app
开发者ID:inveniosoftware,项目名称:invenio-groups,代码行数:35,代码来源:conftest.py
示例16: test_db
def test_db(request):
"""Test database backend."""
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite://'
)
FlaskCLI(app)
InvenioDB(app)
FlaskOAuth(app)
InvenioOAuthClient(app)
def teardown():
with app.app_context():
db.drop_all()
request.addfinalizer(teardown)
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()
tables = list(filter(lambda table: table.startswith('oauthclient'),
db.metadata.tables.keys()))
assert len(tables) == 3
开发者ID:nharraud,项目名称:invenio-oauthclient,代码行数:25,代码来源:test_app.py
示例17: start
def start(self):
self.new_engine()
self.session_maker = scoped_session(sessionmaker(bind=self.engine, autoflush=False))
self.new_session()
self.base.metadata.bind = self.engine
if not database_exists(self.engine.url):
self.make_database()
self.base.metadata.create_all()
开发者ID:sjb9774,项目名称:mtg-api,代码行数:8,代码来源:my_database.py
示例18: 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
示例19: 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()
db_.drop_all()
开发者ID:drjova,项目名称:invenio-deposit,代码行数:8,代码来源:conftest.py
示例20: create_db
def create_db():
"""Creates database if it doesn't exist."""
db_uri = app.config['SQLALCHEMY_DATABASE_URI']
if not database_exists(db_uri):
print('Creating database ...')
create_database(db_uri)
db.create_all()
else:
print('Database already exists. Nothing to create.')
开发者ID:ChadevPython,项目名称:beer-tracker,代码行数:9,代码来源:manage.py
注:本文中的sqlalchemy_utils.functions.database_exists函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论