You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
610 B
Python
37 lines
610 B
Python
import os
|
|
from sqlalchemy import create_engine
|
|
from news.models import Base
|
|
import click
|
|
|
|
engine = create_engine(os.getenv('NEWS_DB', ''))
|
|
|
|
metadata = Base.metadata
|
|
|
|
metadata.bind = engine
|
|
|
|
|
|
@click.group()
|
|
def cli():
|
|
pass
|
|
|
|
|
|
@click.command('create_db')
|
|
def create_db():
|
|
click.echo("Creating news database")
|
|
Base.metadata.create_all()
|
|
click.echo("Database created")
|
|
|
|
|
|
@click.command('drop_db')
|
|
def drop_db():
|
|
print("Dropping news database")
|
|
Base.metadata.drop_all()
|
|
print("Database dropped")
|
|
|
|
|
|
cli.add_command(create_db)
|
|
cli.add_command(drop_db)
|
|
|
|
if __name__ == "__main__":
|
|
cli()
|