You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.2 KiB

  1. # maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
  2. # Copyright (C) 2020 Tulir Asokan
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. from asyncpg import Connection
  17. from mautrix.util.async_db.upgrade import UpgradeTable
  18. upgrade_table = UpgradeTable()
  19. @upgrade_table.register(description="Initial revision")
  20. async def upgrade_v1(conn: Connection) -> None:
  21. await conn.execute("""CREATE TABLE "user" (
  22. id TEXT PRIMARY KEY,
  23. widget_secret TEXT NOT NULL,
  24. homeserver_url TEXT NOT NULL
  25. )""")
  26. await conn.execute("""CREATE TABLE access_token (
  27. token_id SERIAL PRIMARY KEY,
  28. user_id TEXT NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
  29. token_hash BYTEA NOT NULL,
  30. last_seen_ip TEXT,
  31. last_seen_date TIMESTAMP
  32. )""")
  33. await conn.execute("""CREATE TABLE pack (
  34. id TEXT PRIMARY KEY,
  35. owner TEXT REFERENCES "user"(id) ON DELETE SET NULL,
  36. title TEXT NOT NULL,
  37. meta JSONB NOT NULL
  38. )""")
  39. await conn.execute("""CREATE TABLE user_pack (
  40. user_id TEXT REFERENCES "user"(id) ON DELETE CASCADE,
  41. pack_id TEXT REFERENCES pack(id) ON DELETE CASCADE,
  42. "order" INT NOT NULL DEFAULT 0,
  43. PRIMARY KEY (user_id, pack_id)
  44. )""")
  45. await conn.execute("""CREATE TABLE sticker (
  46. id TEXT,
  47. pack_id TEXT REFERENCES pack(id) ON DELETE CASCADE,
  48. url TEXT NOT NULL,
  49. body TEXT NOT NULL,
  50. meta JSONB NOT NULL,
  51. "order" INT NOT NULL DEFAULT 0,
  52. PRIMARY KEY (id, pack_id)
  53. )""")