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()
|
||||
|
||||
def add_listitem_index():
|
||||
with db.session() as session:
|
||||
sql = "SELECT COUNT(*) AS c,list_id,item_id FROM listitem GROUP BY list_id, item_id HAVING c>1"
|
||||
doubles = [r for r in session.execute(sql)]
|
||||
for r in doubles:
|
||||
params = {'list_id': r[1], 'item_id': r[2]}
|
||||
sql = "DELETE FROM listitem WHERE list_id = :list_id AND item_id = :item_id"
|
||||
session.execute(sql, params)
|
||||
sql = "INSERT INTO listitem (list_id, item_id) VALUES (:list_id, :item_id)"
|
||||
session.execute(sql, params)
|
||||
session.commit()
|
||||
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS listitem_index on listitem(list_id,item_id)'
|
||||
session.execute(sql)
|
||||
session.commit()
|
||||
if db.table_exists('listitem'):
|
||||
with db.session() as session:
|
||||
sql = "SELECT COUNT(*) AS c,list_id,item_id FROM listitem GROUP BY list_id, item_id HAVING c>1"
|
||||
doubles = [r for r in session.execute(sql)]
|
||||
for r in doubles:
|
||||
params = {'list_id': r[1], 'item_id': r[2]}
|
||||
sql = "DELETE FROM listitem WHERE list_id = :list_id AND item_id = :item_id"
|
||||
session.execute(sql, params)
|
||||
sql = "INSERT INTO listitem (list_id, item_id) VALUES (:list_id, :item_id)"
|
||||
session.execute(sql, params)
|
||||
session.commit()
|
||||
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS listitem_index on listitem(list_id,item_id)'
|
||||
session.execute(sql)
|
||||
session.commit()
|
||||
|
||||
def add_useritem_index():
|
||||
with db.session() as session:
|
||||
sql = "SELECT COUNT(*) AS c,user_id,item_id FROM useritem GROUP BY user_id, item_id HAVING c>1"
|
||||
doubles = [r for r in session.execute(sql)]
|
||||
for r in doubles:
|
||||
params = {'user_id': r[1], 'item_id': r[2]}
|
||||
sql = "DELETE FROM useritem WHERE user_id = :user_id AND item_id = :item_id"
|
||||
session.execute(sql, params)
|
||||
sql = "INSERT INTO useritem (user_id, item_id) VALUES (:user_id, :item_id)"
|
||||
session.execute(sql, params)
|
||||
session.commit()
|
||||
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS useritem_index on useritem(user_id,item_id)'
|
||||
session.execute(sql)
|
||||
session.commit()
|
||||
if db.table_exists('useritem'):
|
||||
with db.session() as session:
|
||||
sql = "SELECT COUNT(*) AS c,user_id,item_id FROM useritem GROUP BY user_id, item_id HAVING c>1"
|
||||
doubles = [r for r in session.execute(sql)]
|
||||
for r in doubles:
|
||||
params = {'user_id': r[1], 'item_id': r[2]}
|
||||
sql = "DELETE FROM useritem WHERE user_id = :user_id AND item_id = :item_id"
|
||||
session.execute(sql, params)
|
||||
sql = "INSERT INTO useritem (user_id, item_id) VALUES (:user_id, :item_id)"
|
||||
session.execute(sql, params)
|
||||
session.commit()
|
||||
sql = 'CREATE UNIQUE INDEX IF NOT EXISTS useritem_index on useritem(user_id,item_id)'
|
||||
session.execute(sql)
|
||||
session.commit()
|
||||
|
||||
def add_list_username_index():
|
||||
from sqlalchemy.orm import load_only
|
||||
|
|
Loading…
Reference in a new issue