Skip to content

Commit

Permalink
Prehook changes (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Sep 4, 2024
1 parent d42b1d9 commit 5bfc8fa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pay-api/migrations/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Migrating Pay-db

Run `python manage.py db migrate`
Run `poetry run flask db migrate`

If you are updating a large table (i.e. invoices, invoice_references, etc.) add `op.execute(op.text("set statement_timeout=20000;")` to the top of your new migration scripts for upgrade/downgrade. This will prevent the deployment from causing errors in prod when it takes too long to complete (> 20 seconds).)

Expand Down
4 changes: 4 additions & 0 deletions pay-api/pre-hook-update-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/sh
cd /opt/app-root
echo 'starting upgrade'
poetry run flask db upgrade
14 changes: 8 additions & 6 deletions pay-api/src/pay_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ def create_app(run_mode=os.getenv('DEPLOYMENT_ENV', 'production')):
db.init_app(app)
queue.init_app(app)
if run_mode != 'testing':
Migrate(app, db)
app.logger.info('Running migration upgrade.')
with app.app_context():
execute_migrations(app)

if app.config.get('CLOUD_PLATFORM') != 'OCP':
Migrate(app, db)
app.logger.info('Running migration upgrade.')
with app.app_context():
execute_migrations(app)
app.logger.info('Finished migration upgrade.')
else:
app.logger.info('Migrations were executed on prehook.')
# Alembic has it's own logging config, we'll need to restore our logging here.
setup_logging(os.path.join(_Config.PROJECT_ROOT, 'logging.conf'))
app.logger.info('Finished migration upgrade.')
ma.init_app(app)
endpoints.init_app(app)

Expand Down
1 change: 1 addition & 0 deletions pay-api/src/pay_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _Config: # pylint: disable=too-few-public-methods
"""Base class configuration that should set reasonable defaults for all the other configurations."""

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
CLOUD_PLATFORM = os.getenv('CLOUD_PLATFORM', 'OCP')

SECRET_KEY = 'a secret'

Expand Down

0 comments on commit 5bfc8fa

Please sign in to comment.