-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
53 lines (41 loc) · 1.15 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import click
import pytest
from commandlib import Command
from flask.cli import FlaskGroup
from antipodal import create_app
from dotenv import load_dotenv
cli = FlaskGroup(create_app=create_app)
psql = Command("psql")
load_dotenv()
@cli.command()
def test() -> None:
"""use to test things"""
pytest.main(args=["tests/", "--pdb"])
@cli.command()
@click.argument("what")
def setup(what) -> None:
"""
use to set things up
:param what: db
"""
if what == "db":
psql("--command=CREATE DATABASE antipodal").run()
psql("--command=CREATE USER antipodal WITH PASSWORD 'password'").run()
psql("--command=ALTER ROLE antipodal SUPERUSER").run()
psql("--command=GRANT ALL PRIVILEGES ON DATABASE antipodal TO antipodal").run()
else:
click.echo("No such thing to setup")
@cli.command()
@click.argument("what")
def drop(what) -> None:
"""
use to drop things
:param what: db
"""
if what == "db":
psql("--command=DROP DATABASE antipodal").run()
psql("--command=DROP USER antipodal").run()
else:
click.echo("No such thing to drop")
if __name__ == "__main__":
cli()