This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added command line interface to
initdb.py
(and additional dev dep…
…endency "Typer", which is a wrapper around "click") - Moved botfather commands out of README into a separate file - Added docker/docker-compose.yml for easy setup of development database - Updated README
- Loading branch information
Joscha Götzer
committed
May 29, 2020
1 parent
3cf9f6d
commit f428cbf
Showing
7 changed files
with
117 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Botfather Commands | ||
|
||
start - Start the bot | ||
stop - Stop the bot | ||
delete_me - Remove me from the bot. Forever | ||
settings - Open the user settings menu | ||
create - Create a new poll | ||
list - List all active polls and manage them | ||
list_closed - List all closed polls and manage them | ||
notify - Activate notifications in external chats | ||
help - Show the help text | ||
donations - Get me a coffee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '3' | ||
services: | ||
database: | ||
image: postgres:latest # use latest official postgres version | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_DB: pollbot | ||
POSTGRES_USER: pollbot | ||
POSTGRES_PASSWORD: null | ||
volumes: | ||
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down | ||
volumes: | ||
database-data: # named volumes can be managed easier using docker-compose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,53 @@ | ||
#!/bin/env python | ||
"""Drop and create a new database with schema.""" | ||
"""Create a new database with schema.""" | ||
from contextlib import contextmanager | ||
|
||
import typer | ||
from sqlalchemy_utils.functions import database_exists, create_database, drop_database | ||
|
||
from sqlalchemy_utils.functions import database_exists, create_database | ||
from pollbot.db import engine, base | ||
from pollbot.models import * # noqa | ||
|
||
db_url = engine.url | ||
if not database_exists(db_url): | ||
create_database(db_url) | ||
|
||
def initialize_database(exist_ok: bool = False, drop_existing: bool = False): | ||
db_url = engine.url | ||
typer.echo(f"Using database at {db_url}") | ||
|
||
if database_exists(db_url): | ||
if drop_existing: | ||
with wrap_echo("Dropping database"): | ||
drop_database(db_url) | ||
elif not exist_ok: | ||
typer.echo( | ||
f"Database already exists, aborting.\n" | ||
f"Use --exist-ok if you are sure the database is uninitialized and contains no data.\n" | ||
f"Use --drop-existing if you want to recreate it.", | ||
err=True, | ||
) | ||
return | ||
|
||
with wrap_echo("Creating database"): | ||
create_database(db_url) | ||
pass | ||
|
||
with engine.connect() as con: | ||
con.execute("CREATE EXTENSION IF NOT EXISTS pgcrypto;") | ||
with wrap_echo("Installing pgcrypto extension"): | ||
con.execute("CREATE EXTENSION IF NOT EXISTS pgcrypto;") | ||
pass | ||
|
||
with wrap_echo("Creating metadata"): | ||
base.metadata.create_all() | ||
pass | ||
|
||
typer.echo("Database initialization complete.") | ||
|
||
|
||
@contextmanager | ||
def wrap_echo(msg: str): | ||
typer.echo(f"{msg}... ", nl=False) | ||
yield | ||
typer.echo("done.") | ||
|
||
|
||
base.metadata.create_all() | ||
if __name__ == "__main__": | ||
typer.run(initialize_database) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters