add sql cli and explain it in the readme

This commit is contained in:
2020-05-14 20:05:02 -05:00
parent 8de802aff5
commit 0dc58ed6a8
6 changed files with 119 additions and 12 deletions

View File

@ -42,7 +42,7 @@ nano capsulflask/__init__.py
Run the app
```
FLASK_APP=capsulflask flask run
flask run
```
Run the app in gunicorn
@ -50,8 +50,49 @@ Run the app in gunicorn
.venv/bin/gunicorn --bind 127.0.0.1:5000 capsulflask:app
```
-----
# postgres database schema management
## cli
You can manually mess around with the database like this:
```
flask cli sql -f test.sql
```
```
flask cli sql -c 'SELECT * FROM vms'
```
This one selects the vms table with the column name header:
```
flask cli sql -c "SELECT string_agg(column_name::text, ', ') from information_schema.columns WHERE table_name='vms'; SELECT * from vms"
```
How to modify a payment manually, like if you get a chargeback or to fix customer payment issues:
```
$ flask cli sql -c "SELECT id, created, email, dollars, invalidated from payments"
1, 2020-05-05T00:00:00, forest.n.johnson@gmail.com, 20.00, FALSE
$ flask cli sql -c "UPDATE payments SET invalidated = True WHERE id = 1"
1 rows affected.
$ flask cli sql -c "SELECT id, created, email, dollars, invalidated from payments"
1, 2020-05-05T00:00:00, forest.n.johnson@gmail.com, 20.00, TRUE
```
How you would kick off the scheduled task:
```
flask cli cron-task
```
-----
## postgres database schema management
capsulflask has a concept of a schema version. When the application starts, it will query the database for a table named
`schemaversion` that has one row and one column (`version`). If the `version` it finds is not equal to the `desiredSchemaVersion` variable set in `db.py`, it will run migration scripts from the `schema_migrations` folder one by one until the `schemaversion` table shows the correct version.
@ -62,9 +103,9 @@ For example, the script named `02_up_xyz.sql` should contain code that migrates
In general, for safety, schema version upgrades should not delete data. Schema version downgrades will simply throw an error and exit for now.
-----
# how to setup btcpay server
## how to setup btcpay server
Generate a private key and the accompanying bitpay SIN for the bitpay API client.