本文整理汇总了Python中sqlalchemy_utils.drop_database函数的典型用法代码示例。如果您正苦于以下问题:Python drop_database函数的具体用法?Python drop_database怎么用?Python drop_database使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drop_database函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_engine
def gen_engine():
_engine = create_db_test()
yield _engine
drop_database(url_db)
示例2: stop_fixture
def stop_fixture(self):
"""Clean up the config fixture and storage artifacts."""
if hasattr(self, 'metricd_thread'):
self.metricd_thread.stop()
self.metricd_thread.join()
if hasattr(self, 'fixtures'):
for f in reversed(self.fixtures):
f.cleanUp()
if hasattr(self, 'index'):
self.index.disconnect()
# Swallow noise from missing tables when dropping
# database.
with warnings.catch_warnings():
warnings.filterwarnings('ignore',
module='sqlalchemy.engine.default')
sqlalchemy_utils.drop_database(self.conf.indexer.url)
if self.tmp_dir:
shutil.rmtree(self.tmp_dir)
if hasattr(self, 'coord'):
self.coord.stop()
self.conf.reset()
if not os.getenv("GNOCCHI_TEST_DEBUG"):
self.output.cleanUp()
示例3: clean_db
def clean_db(ctx: click.Context):
"""Removes Postgres database."""
db_uri = make_url(ctx.obj['db_uri'])
db_uri_str = db_uri.__to_string__()
if database_exists(db_uri):
logging.info(f'Cleaning "{db_uri_str}" database.')
drop_database(db_uri)
示例4: create_ctfd
def create_ctfd(ctf_name="CTFd", name="admin", email="[email protected]", password="password", setup=True):
app = create_app('CTFd.config.TestingConfig')
url = make_url(app.config['SQLALCHEMY_DATABASE_URI'])
if url.drivername == 'postgres':
url.drivername = 'postgresql'
if database_exists(url):
drop_database(url)
create_database(url)
with app.app_context():
app.db.create_all()
if setup:
with app.app_context():
with app.test_client() as client:
data = {}
r = client.get('/setup') # Populate session with nonce
with client.session_transaction() as sess:
data = {
"ctf_name": ctf_name,
"name": name,
"email": email,
"password": password,
"nonce": sess.get('nonce')
}
client.post('/setup', data=data)
return app
示例5: setup
def setup():
print(app.config['SQLALCHEMY_DATABASE_URI'])
engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
if database_exists(engine.url):
drop_database(engine.url)
create_database(engine.url)
engine.execute('create extension if not exists fuzzystrmatch')
示例6: dropDatabase
def dropDatabase(dbName):
"""Drop specified database."""
config = CONFIG_DB
connectString = "postgresql://{}:{}@{}:{}/{}".format(config["username"],
config["password"], config["host"], config["port"], dbName)
if sqlalchemy_utils.database_exists(connectString):
sqlalchemy_utils.drop_database(connectString)
示例7: init_data
def init_data():
from imports import (
Widget,Article,Page,
User,Setting,Type,
Template,Tag,Role,
Category,Block,Profile,
ContactMessage)
"""Fish data for project"""
if prompt_bool('Do you want to kill your db?'):
if squ.database_exists(db.engine.url):
squ.drop_database(db.engine.url)
try:
db.drop_all()
except:
pass
try:
squ.create_database(db.engine.url)
db.create_all()
except:
pass
user = User.query.filter(User.email=='[email protected]').first()
if user is None:
user = User(username='kyle', email='[email protected]', password='14wp88')
user.save()
示例8: drop_db
def drop_db(app):
from project.core.db import db
from sqlalchemy_utils import database_exists, drop_database
if database_exists(db.engine.url):
print '====> Drop database'
drop_database(db.engine.url)
else:
print '====> database not exist'
示例9: book_uri
def book_uri(request):
name = request.param
if name and database_exists(name):
drop_database(name)
yield name
if name and database_exists(name):
drop_database(name)
示例10: createdb
def createdb():
print "Connecting to %s" % settings.SQLALCHEMY_DATABASE_URI
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI)
if settings.DROP_DB_ON_RESTART and database_exists(engine.url):
print "Dropping old database... (because DROP_DB_ON_RESTART=True)"
drop_database(engine.url)
if not database_exists(engine.url):
print "Creating databases..."
create_database(engine.url)
示例11: setUp
def setUp(self):
self.app = self.create_app()
self.db = DB(engine,session,meta)
import sqlalchemy_utils as squ
if squ.database_exists(self.db.engine.url):
squ.drop_database(self.db.engine.url)
squ.create_database(self.db.engine.url)
meta.bind = self.db.engine
meta.create_all()
示例12: drop
def drop():
"""
Drop the database if it exists
:return:
"""
app.logger.debug('Dropping the database!')
if database_exists(db.engine.url):
drop_database(db.engine.url)
app.logger.error('Database does not exists!')
示例13: app
def app():
"""
Create test database and application
"""
app = create_app(testing=True)
sqlalchemy_url = app.config['SQLALCHEMY_DATABASE_URI']
if database_exists(sqlalchemy_url):
drop_database(sqlalchemy_url)
create_database(sqlalchemy_url)
yield app
示例14: create_sweography_db
def create_sweography_db():
engine = create_engine(SQLALCHEMY_DATABASE_URI)
if database_exists(engine.url):
drop_database(engine.url)
create_database(engine.url)
##creates all tables in database
Base.metadata.create_all(engine)
示例15: new_book_USD
def new_book_USD(request):
name = request.param
if name and database_exists(name):
drop_database(name)
with create_book(uri_conn=name, currency="USD", keep_foreign_keys=False) as b:
yield b
if name and database_exists(name):
drop_database(name)