2014-05-04 17:26:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
2014-08-09 15:03:16 +00:00
|
|
|
import os
|
|
|
|
|
2014-05-04 17:26:43 +00:00
|
|
|
import settings
|
2014-08-09 15:03:16 +00:00
|
|
|
from db import session
|
|
|
|
|
2014-05-04 17:26:43 +00:00
|
|
|
from user.models import List, User
|
|
|
|
|
2014-08-09 15:03:16 +00:00
|
|
|
|
|
|
|
def create_db():
|
|
|
|
if not os.path.exists(settings.db_path):
|
|
|
|
print 'create db'
|
|
|
|
session.connection().execute("PRAGMA journal_mode=WAL")
|
|
|
|
session.commit()
|
|
|
|
upgrade_db('0')
|
|
|
|
|
|
|
|
def upgrade_db(old):
|
|
|
|
if old <= '20140527-120-3cb9819':
|
|
|
|
create_index('ix_find_findvalue', 'find', ['findvalue'], unique=False)
|
|
|
|
|
2014-05-04 17:26:43 +00:00
|
|
|
def create_default_lists(user_id=None):
|
|
|
|
user_id = user_id or settings.USER_ID
|
|
|
|
user = User.get_or_create(user_id)
|
2014-05-25 12:16:04 +00:00
|
|
|
user.update_name()
|
2014-05-04 17:26:43 +00:00
|
|
|
for list in settings.config['lists']:
|
|
|
|
l = List.get(user_id, list['title'])
|
|
|
|
if not l:
|
|
|
|
l = List.create(user_id, list['title'], list.get('query'))
|
|
|
|
|