Skip to content

Commit

Permalink
Move DB migrate to config
Browse files Browse the repository at this point in the history
  • Loading branch information
mbillow committed May 22, 2018
1 parent 3ac8322 commit f40005d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
23 changes: 23 additions & 0 deletions gunicorn_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import subprocess

from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, upgrade
from flask import Flask

app = Flask(__name__)

if os.path.exists(os.path.join(os.getcwd(), "config.py")):
app.config.from_pyfile(os.path.join(os.getcwd(), "config.py"))
else:
app.config.from_pyfile(os.path.join(os.getcwd(), "config.env.py"))

# Create the database session and import models.
db = SQLAlchemy(app)
from selfservice.models import *
migrate = Migrate(app, db)

def on_starting(server):
if not os.path.exists(os.path.join(os.getcwd(), "data.db")):
with app.app_context():
upgrade()
6 changes: 1 addition & 5 deletions selfservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_recaptcha import ReCaptcha
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, upgrade
from flask_migrate import Migrate
from alembic import command

from selfservice.utilities.general import is_expired, email_recovery, phone_recovery
Expand All @@ -24,10 +24,6 @@
from selfservice.models import *
migrate = Migrate(app, db)

if not os.path.exists(os.path.join(os.getcwd(), "data.db")):
with app.app_context():
upgrade()

# Create recaptcha object
recaptcha = ReCaptcha()
recaptcha.init_app(app)
Expand Down

0 comments on commit f40005d

Please sign in to comment.