aboutsummaryrefslogtreecommitdiffstats
path: root/gunicorn_config.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-04-15 18:47:58 +0200
committerGravatar Gareth Coles <[email protected]>2018-04-15 17:47:58 +0100
commitf5e7c358761ee49da45933e73b943fb1eb66c030 (patch)
treecde9eed9f010caba22842d39af33385aae411a45 /gunicorn_config.py
parentAdded an About category with Partners view (#1pv7h) (#50) (diff)
Initial data for tables and refactoring the dev-mode database handling to be similar to prod-mode. (#53)
* Changed the dev-mode logic to be the same as prod for creating new tables if they don't exist. Also added a new feature where a table can be initialized with data if you create a JSON file in the pysite/database/table_init/ folder and fill it with a list of dicts where each dict represents a row in your table. Included a hiphoppers json so that I can actually test if it works in production. It will only init the table if the table is empty. * Not sure if this will solve it, but I think so. * Renamed the tables and primary keys, and alphabetized the dict. Now complies with the gdudes holy wishes.
Diffstat (limited to 'gunicorn_config.py')
-rw-r--r--gunicorn_config.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/gunicorn_config.py b/gunicorn_config.py
index f863edd4..5b9f9055 100644
--- a/gunicorn_config.py
+++ b/gunicorn_config.py
@@ -12,6 +12,16 @@ def when_ready(server=None):
from pysite.database import RethinkDB
db = RethinkDB(loop_type=None)
+ db.conn = db.get_connection()
+
+ # Create any table that doesn't exist
created = db.create_tables()
+ if created:
+ tables = ", ".join([f"{table}" for table in created])
+ output(f"Created the following tables: {tables}")
- output(f"Created {created} tables.")
+ # Init the tables that require initialization
+ initialized = db.init_tables()
+ if initialized:
+ tables = ", ".join([f"{table} ({count} items)" for table, count in initialized.items()])
+ output(f"Initialized the following tables: {tables}")