def set_up(self, drop=False):
"""Create a new DB and create the initial scheme.
If the database exists and drop=True, the existing database is dropped
and recreated. Regardless, any tables defined by the schema that do not
exist are created.
Parameters
----------
drop : bool, optional (default=False)
Drop database if it already exists.
"""
# todo extract database name from engine url and report for brevity
engine = self.__orm.engine
if database_exists(engine.url):
print("Database {} already exists.".format(engine.url))
if drop:
print("Dropping old database {}".format(engine.url))
drop_database(engine.url)
with possibly_talking_action("Re-creating database..."):
create_database(engine.url)
else:
with possibly_talking_action("Creating database..."):
create_database(engine.url)
with possibly_talking_action("Creating tables..."):
Base.metadata.create_all(engine)
print("Database {} created successfully".format(engine.url))
评论列表
文章目录