Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from lendingblock/master
Browse files Browse the repository at this point in the history
added create db command
  • Loading branch information
lsbardel authored Jun 19, 2018
2 parents ba0d300 + 1202260 commit ea11311
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Minimal OpenAPI asynchronous server application
"""
__version__ = '0.1.1'
__version__ = '0.1.2'
25 changes: 25 additions & 0 deletions openapi/db/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from copy import copy

import click

from sqlalchemy_utils import database_exists, drop_database, create_database

from .migrations import Migration


Expand Down Expand Up @@ -71,3 +75,24 @@ def show(ctx, revision):
"""Show revision ID and creation date
"""
return migration(ctx).show(revision)


@db.command()
@click.argument('dbname', nargs=1)
@click.option('--force', default=False, is_flag=True,
help='Force removal of an existing database')
@click.pass_context
def create(ctx, dbname, force):
"""Creates a new database
"""
store = ctx.parent.parent.app['store']
url = copy(store.url)
url.database = dbname
store = str(url)
if database_exists(store):
if force:
drop_database(store)
else:
return click.echo(f'database {dbname} already available')
create_database(store)
click.echo(f'database {dbname} created')
9 changes: 9 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ def test_db(cli):
assert result.output.startswith('Usage: root db [OPTIONS]')


def test_createdb(cli):
runner = CliRunner()
result = runner.invoke(cli.app['cli'], ['db', 'create', 'testing-aio-db'])
assert result.exit_code == 0
result = runner.invoke(
cli.app['cli'], ['db', 'create', 'testing-aio-db', '--force'])
assert result.exit_code == 0


async def tests_get_list(cli):
response = await cli.get('/tasks')
data = await jsonBody(response)
Expand Down

0 comments on commit ea11311

Please sign in to comment.