f867edb by Anon Ray at 2014-04-10 1
# -*- coding: utf-8 -*-
2
# swtstore->dbsetup.py
3
4
# Create and setup databases for the first time run of the application
75d3bd6 by Anon Ray at 2014-02-19 5
6
import sys, os
7
f867edb by Anon Ray at 2014-04-10 8
# Get the path to the base directory of the app
75d3bd6 by Anon Ray at 2014-02-19 9
BASE_DIR = os.path.join(os.path.dirname(__file__))
10
f867edb by Anon Ray at 2014-04-10 11
# append the path to the WSGI env path
75d3bd6 by Anon Ray at 2014-02-19 12
sys.path.insert(0, BASE_DIR)
13
f867edb by Anon Ray at 2014-04-10 14
# Import and create the app; also get the db instance from the current app
75d3bd6 by Anon Ray at 2014-02-19 15
from swtstore import create_app, getDBInstance
16
17
app = create_app()
18
19
db = getDBInstance()
20
f867edb by Anon Ray at 2014-04-10 21
# Import all modules which represents a SQLAlchemy model;
22
# they have corresponding tables that are needed to be created
d120774 by Anon Ray at 2014-03-08 23
from swtstore.classes.models import Sweet, Context, Client
24
from swtstore.classes.models.um import User, Group, Membership
25
f867edb by Anon Ray at 2014-04-10 26
# Create them!
75d3bd6 by Anon Ray at 2014-02-19 27
db.create_all()
d120774 by Anon Ray at 2014-03-08 28
29