1
0

initialise_database.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. )\
  10. ",
  11. "CREATE TABLE IF NOT EXISTS \
  12. channel (\
  13. id SERIAL PRIMARY KEY, \
  14. channel_id BIGINT UNIQUE NOT NULL, \
  15. guild BIGINT REFERENCES guild (guild_id), \
  16. interact BOOL DEFAULT FALSE, \
  17. games BOOL DEFAULT FALSE\
  18. )\
  19. ",
  20. "CREATE TABLE IF NOT EXISTS \
  21. settings (\
  22. id SERIAL PRIMARY KEY, \
  23. crew_channel_id BIGINT UNIQUE NOT NULL\
  24. )\
  25. ",
  26. # "CREATE TABLE IF NOT EXISTS \
  27. # channel_settings (\
  28. # id SERIAL PRIMARY KEY, \
  29. # channel BIGINT UNIQUE NOT NULL REFERENCES channel (channel_id), \
  30. # guild BIGINT REFERENCES guild (guild_id)\
  31. # )\
  32. # ",
  33. "CREATE TABLE IF NOT EXISTS \
  34. \"user\" (\
  35. id SERIAL PRIMARY KEY, \
  36. user_id BIGINT UNIQUE NOT NULL, \
  37. ignore BOOL DEFAULT FALSE, \
  38. level INT DEFAULT 0, \
  39. xp_spent INT DEFAULT 0\
  40. )\
  41. ",
  42. "CREATE TABLE IF NOT EXISTS \
  43. guild_access_token (\
  44. id SERIAL PRIMARY KEY, \
  45. guild BIGINT REFERENCES guild (guild_id), \
  46. \"user\" BIGINT NOT NULL REFERENCES \"user\" (user_id), \
  47. token varchar[40] UNIQUE NOT NULL, \
  48. created TIMESTAMP NOT NULL DEFAULT now()\
  49. )\
  50. ",
  51. "CREATE TABLE IF NOT EXISTS \
  52. channel_user (\
  53. id SERIAL PRIMARY KEY, \
  54. channel BIGINT NOT NULL REFERENCES channel (channel_id), \
  55. \"user\" BIGINT NOT NULL REFERENCES \"user\" (user_id), \
  56. total_messages BIGINT DEFAULT 1, \
  57. UNIQUE (channel, \"user\")\
  58. )\
  59. ",
  60. ]
  61. for query in queries:
  62. await pg.execute(query)