initialise_database.py 3.3 KB

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