initialise_database.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. async def init_db(pg):
  2. queries = [
  3. "CREATE TABLE IF NOT EXISTS \
  4. guild (\
  5. id SERIAL PRIMARY KEY, \
  6. guild_id BIGINT UNIQUE NOT NULL, \
  7. output_channel BIGINT REFERENCES channel (channel_id),\
  8. report_deleted BOOL DEFAULT FALSE, \
  9. report_edited BOOL DEFAULT FALSE, \
  10. games BOOL DEFAULT NULL, \
  11. interact BOOL DEFAULT NULL\
  12. )\
  13. ",
  14. "CREATE TABLE IF NOT EXISTS \
  15. channel (\
  16. id SERIAL PRIMARY KEY, \
  17. channel_id BIGINT UNIQUE NOT NULL, \
  18. guild BIGINT REFERENCES guild (guild_id), \
  19. interact BOOL DEFAULT FALSE, \
  20. games BOOL DEFAULT NULL\
  21. )\
  22. ",
  23. "CREATE TABLE IF NOT EXISTS \
  24. settings (\
  25. id SERIAL PRIMARY KEY, \
  26. crew_channel_id BIGINT UNIQUE NOT NULL\
  27. )\
  28. ",
  29. # "CREATE TABLE IF NOT EXISTS \
  30. # channel_settings (\
  31. # id SERIAL PRIMARY KEY, \
  32. # channel BIGINT UNIQUE NOT NULL REFERENCES channel (channel_id), \
  33. # guild BIGINT REFERENCES guild (guild_id)\
  34. # )\
  35. # ",
  36. "CREATE TABLE IF NOT EXISTS \
  37. \"user\" (\
  38. id SERIAL PRIMARY KEY, \
  39. user_id BIGINT UNIQUE NOT NULL, \
  40. ignore BOOL DEFAULT FALSE, \
  41. level INT DEFAULT 0, \
  42. xp_spent INT DEFAULT 0, \
  43. invites_created INT DEFAULT 0, \
  44. integrations_created INT DEFAULT 0, \
  45. member_updated INT DEFAULT 0, \
  46. user_updated INT DEFAULT 0, \
  47. member_banned INT DEFAULT 0, \
  48. member_unbanned INT DEFAULT 0, \
  49. presence_updated INT DEFAULT 0, \
  50. messages_edited INT DEFAULT 0, \
  51. messages_deleted INT DEFAULT 0, \
  52. reacted INT DEFAULT 0, \
  53. events_created INT DEFAULT 0, \
  54. events_joined INT DEFAULT 0, \
  55. threads_created INT DEFAULT 0, \
  56. threads_joined INT DEFAULT 0, \
  57. ability_points_spent INT DEFAULT 0, \
  58. coin INT DEFAULT 0, \
  59. karma INT DEFAULT 0, \
  60. defence_skill INT DEFAULT 0, \
  61. attack_skill INT DEFAULT 0, \
  62. stealth_skill INT DEFAULT 0, \
  63. perception_skill INT DEFAULT 0, \
  64. theft_skill INT DEFAULT 0, \
  65. created TIMESTAMP NOT NULL DEFAULT now()\
  66. )\
  67. ",
  68. "CREATE TABLE IF NOT EXISTS \
  69. guild_access_token (\
  70. id SERIAL PRIMARY KEY, \
  71. guild BIGINT REFERENCES guild (guild_id), \
  72. \"user\" BIGINT NOT NULL REFERENCES \"user\" (user_id), \
  73. token varchar[40] UNIQUE NOT NULL, \
  74. created TIMESTAMP NOT NULL DEFAULT now()\
  75. )\
  76. ",
  77. "CREATE TABLE IF NOT EXISTS \
  78. channel_user (\
  79. id SERIAL PRIMARY KEY, \
  80. channel BIGINT NOT NULL REFERENCES channel (channel_id), \
  81. \"user\" BIGINT NOT NULL REFERENCES \"user\" (user_id), \
  82. total_messages BIGINT DEFAULT 1, \
  83. UNIQUE (channel, \"user\")\
  84. )\
  85. ",
  86. ]
  87. for query in queries:
  88. await pg.execute(query)
  89. async def check_db(pg):
  90. await pg.fetchrow("SELECT id from \"user\"")