1
0

initialise_database.py 2.0 KB

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