Add alembic plumbing for database schema migrations.

This commit is contained in:
jakedt 2014-04-09 19:11:33 -04:00
parent 4d4f3b1c18
commit fc7756a3c2
6 changed files with 259 additions and 7 deletions

View file

@ -5,19 +5,39 @@ import uuid
from random import SystemRandom
from datetime import datetime
from peewee import *
from urlparse import urlparse
from app import app
logger = logging.getLogger(__name__)
DRIVER_LIST = {
'SqliteDatabase': SqliteDatabase,
'MySQLDatabase': MySQLDatabase,
SCHEME_DRIVERS = {
'mysql': MySQLDatabase,
'sqlite': SqliteDatabase,
}
db = DRIVER_LIST[app.config['DB_DRIVER_NAME']](app.config['DB_NAME'],
**app.config['DB_CONNECTION_ARGS'])
def generate_db(config_object):
db_kwargs = dict(config_object['DB_CONNECTION_ARGS'])
connection_string = config_object['DB_URI']
scheme, auth_and_host, dbname = urlparse(connection_string)[:3]
if auth_and_host:
if '@' in auth_and_host:
auth, db_kwargs['host'] = auth_and_host.split('@')
if ':' in auth:
db_kwargs['user'], db_kwargs['passwd'] = auth.split(':')
if scheme == 'sqlite':
dbname = dbname[1:]
return SCHEME_DRIVERS[scheme](dbname, **db_kwargs)
db = generate_db(app.config)
def random_string_generator(length=16):
def random_string():
@ -46,6 +66,7 @@ class User(BaseModel):
organization = BooleanField(default=False, index=True)
robot = BooleanField(default=False, index=True)
invoice_email = BooleanField(default=False)
new_user_field = CharField(null=True)
class TeamRole(BaseModel):