indices.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from sqlite3 import Cursor
  2. def create_indices(cursor: Cursor):
  3. print(' - Creating indices...')
  4. print(' - Creating indices...')
  5. cursor.execute('''
  6. CREATE INDEX IF NOT EXISTS ownership_ownable
  7. ON ownership (ownable_id)
  8. ''')
  9. cursor.execute('''
  10. CREATE INDEX IF NOT EXISTS transactions_ownable
  11. ON transactions (ownable_id)
  12. ''')
  13. cursor.execute('''
  14. CREATE INDEX IF NOT EXISTS orders_expiry
  15. ON orders (expiry_dt)
  16. ''')
  17. cursor.execute('''
  18. CREATE INDEX IF NOT EXISTS orders_ownership
  19. ON orders (ownership_id)
  20. ''')
  21. cursor.execute('''
  22. CREATE INDEX IF NOT EXISTS orders_limit
  23. ON orders ("limit")
  24. ''')
  25. cursor.execute('''
  26. CREATE INDEX IF NOT EXISTS transactions_dt
  27. ON transactions (dt)
  28. ''')
  29. cursor.execute('''
  30. CREATE INDEX IF NOT EXISTS news_dt
  31. ON news (dt)
  32. ''')
  33. cursor.execute('''
  34. CREATE INDEX IF NOT EXISTS ownables_name
  35. ON ownables (name)
  36. ''')
  37. cursor.execute('''
  38. CREATE INDEX IF NOT EXISTS users_name
  39. ON users (username)
  40. ''')
  41. cursor.execute('''
  42. CREATE INDEX IF NOT EXISTS sessions_id
  43. ON sessions (session_id)
  44. ''')
  45. cursor.execute('''
  46. CREATE INDEX IF NOT EXISTS sessions_user
  47. ON sessions (user_id)
  48. ''')
  49. cursor.execute('''
  50. CREATE INDEX IF NOT EXISTS transactions_seller
  51. ON transactions (seller_id)
  52. ''')
  53. cursor.execute('''
  54. CREATE INDEX IF NOT EXISTS transactions_buyer
  55. ON transactions (buyer_id)
  56. ''')
  57. cursor.execute('''
  58. CREATE INDEX IF NOT EXISTS order_history_id
  59. ON order_history (order_id)
  60. ''')
  61. cursor.execute('''
  62. CREATE INDEX IF NOT EXISTS order_canceled
  63. ON order_history (archived_dt)
  64. ''')
  65. cursor.execute('''
  66. CREATE INDEX IF NOT EXISTS order_history_ownership
  67. ON order_history (ownership_id)
  68. ''')
  69. cursor.execute('''
  70. CREATE INDEX IF NOT EXISTS loan_by_user
  71. ON loans (user_id, last_interest_pay_dt)
  72. ''')