another fix for new installs
This commit is contained in:
parent
58f516ff46
commit
9145ef5df6
1 changed files with 28 additions and 26 deletions
54
oml/setup.py
54
oml/setup.py
|
@ -487,34 +487,36 @@ def update_database():
|
||||||
item.models.update_sort_table()
|
item.models.update_sort_table()
|
||||||
|
|
||||||
def add_listitem_index():
|
def add_listitem_index():
|
||||||
with db.session() as session:
|
if db.table_exists('listitem'):
|
||||||
sql = "SELECT COUNT(*) AS c,list_id,item_id FROM listitem GROUP BY list_id, item_id HAVING c>1"
|
with db.session() as session:
|
||||||
doubles = [r for r in session.execute(sql)]
|
sql = "SELECT COUNT(*) AS c,list_id,item_id FROM listitem GROUP BY list_id, item_id HAVING c>1"
|
||||||
for r in doubles:
|
doubles = [r for r in session.execute(sql)]
|
||||||
params = {'list_id': r[1], 'item_id': r[2]}
|
for r in doubles:
|
||||||
sql = "DELETE FROM listitem WHERE list_id = :list_id AND item_id = :item_id"
|
params = {'list_id': r[1], 'item_id': r[2]}
|
||||||
session.execute(sql, params)
|
sql = "DELETE FROM listitem WHERE list_id = :list_id AND item_id = :item_id"
|
||||||
sql = "INSERT INTO listitem (list_id, item_id) VALUES (:list_id, :item_id)"
|
session.execute(sql, params)
|
||||||
session.execute(sql, params)
|
sql = "INSERT INTO listitem (list_id, item_id) VALUES (:list_id, :item_id)"
|
||||||
session.commit()
|
session.execute(sql, params)
|
||||||
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS listitem_index on listitem(list_id,item_id)'
|
session.commit()
|
||||||
session.execute(sql)
|
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS listitem_index on listitem(list_id,item_id)'
|
||||||
session.commit()
|
session.execute(sql)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
def add_useritem_index():
|
def add_useritem_index():
|
||||||
with db.session() as session:
|
if db.table_exists('useritem'):
|
||||||
sql = "SELECT COUNT(*) AS c,user_id,item_id FROM useritem GROUP BY user_id, item_id HAVING c>1"
|
with db.session() as session:
|
||||||
doubles = [r for r in session.execute(sql)]
|
sql = "SELECT COUNT(*) AS c,user_id,item_id FROM useritem GROUP BY user_id, item_id HAVING c>1"
|
||||||
for r in doubles:
|
doubles = [r for r in session.execute(sql)]
|
||||||
params = {'user_id': r[1], 'item_id': r[2]}
|
for r in doubles:
|
||||||
sql = "DELETE FROM useritem WHERE user_id = :user_id AND item_id = :item_id"
|
params = {'user_id': r[1], 'item_id': r[2]}
|
||||||
session.execute(sql, params)
|
sql = "DELETE FROM useritem WHERE user_id = :user_id AND item_id = :item_id"
|
||||||
sql = "INSERT INTO useritem (user_id, item_id) VALUES (:user_id, :item_id)"
|
session.execute(sql, params)
|
||||||
session.execute(sql, params)
|
sql = "INSERT INTO useritem (user_id, item_id) VALUES (:user_id, :item_id)"
|
||||||
session.commit()
|
session.execute(sql, params)
|
||||||
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS useritem_index on useritem(user_id,item_id)'
|
session.commit()
|
||||||
session.execute(sql)
|
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS useritem_index on useritem(user_id,item_id)'
|
||||||
session.commit()
|
session.execute(sql)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
def add_list_username_index():
|
def add_list_username_index():
|
||||||
from sqlalchemy.orm import load_only
|
from sqlalchemy.orm import load_only
|
||||||
|
|
Loading…
Reference in a new issue