Skip to content

Commit a250a11

Browse files
committed
unified initializer
1 parent c84f0ad commit a250a11

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

.gitpod.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tasks:
2-
- init: pip install -r requirements.txt
3-
command: flask init & flask run
2+
- init: pip install -r requirements.txt & flask init
3+
command: flask run
44

55
ports:
66
- port: 8080

App/controllers/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .user import *
2-
from .auth import *
2+
from .auth import *
3+
from .initialize import *

App/controllers/initialize.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from .user import create_user
2+
from App.database import db
3+
4+
5+
def initialize():
6+
db.drop_all()
7+
db.create_all()
8+
create_user('bob', 'bobpass')

App/database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from flask_sqlalchemy import SQLAlchemy
22
from flask_migrate import Migrate
33

4+
45
db = SQLAlchemy()
56

67
def get_migrate(app):

App/default_config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
SQLALCHEMY_DATABASE_URI = "sqlite:///temp-database.db"
2-
SECRET_KEY = "secret key"
1+
SQLALCHEMY_DATABASE_URI="sqlite:///temp-database.db"
2+
SECRET_KEY="secret key"
3+
DEBUG=True

App/views/index.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from flask import Blueprint, redirect, render_template, request, send_from_directory, jsonify
2-
from App.models import db
3-
from App.controllers import create_user
2+
from App.controllers import create_user, initialize
43

54
index_views = Blueprint('index_views', __name__, template_folder='../templates')
65

@@ -10,9 +9,7 @@ def index_page():
109

1110
@index_views.route('/init', methods=['GET'])
1211
def init():
13-
db.drop_all()
14-
db.create_all()
15-
create_user('bob', 'bobpass')
12+
initialize()
1613
return jsonify(message='db initialized!')
1714

1815
@index_views.route('/health', methods=['GET'])

wsgi.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from App.database import db, get_migrate
66
from App.main import create_app
7-
from App.controllers import ( create_user, get_all_users_json, get_all_users )
7+
from App.controllers import ( create_user, get_all_users_json, get_all_users, initialize )
88

99
# This commands file allow you to create convenient CLI commands for testing controllers
1010

@@ -13,10 +13,8 @@
1313

1414
# This command creates and initializes the database
1515
@app.cli.command("init", help="Creates and initializes the database")
16-
def initialize():
17-
db.drop_all()
18-
db.create_all()
19-
create_user('bob', 'bobpass')
16+
def init():
17+
initialize()
2018
print('database intialized')
2119

2220
'''

0 commit comments

Comments
 (0)