Browse Source

Split schema upgrades into separate files

Tulir Asokan 3 years ago
parent
commit
d8ad6680ee

+ 2 - 2
mautrix_signal/db/message.py

@@ -22,7 +22,7 @@ import asyncpg
 
 from mausignald.types import Address, GroupID
 from mautrix.types import EventID, RoomID
-from mautrix.util.async_db import Database
+from mautrix.util.async_db import Database, Scheme
 
 from ..util import id_to_str
 
@@ -113,7 +113,7 @@ class Message:
 
     @classmethod
     async def find_by_timestamps(cls, timestamps: list[int]) -> list[Message]:
-        if cls.db.scheme == "postgres":
+        if cls.db.scheme in (Scheme.POSTGRES, Scheme.COCKROACH):
             q = """
             SELECT mxid, mx_room, sender, timestamp, signal_chat_id, signal_receiver FROM message
             WHERE timestamp=ANY($1)

+ 0 - 230
mautrix_signal/db/upgrade.py

@@ -1,230 +0,0 @@
-# mautrix-signal - A Matrix-Signal puppeting bridge
-# Copyright (C) 2021 Tulir Asokan
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-from asyncpg import Connection
-
-from mautrix.util.async_db import UpgradeTable
-
-upgrade_table = UpgradeTable()
-
-
-@upgrade_table.register(description="Initial revision")
-async def upgrade_v1(conn: Connection) -> None:
-    await conn.execute(
-        """
-        CREATE TABLE portal (
-            chat_id     TEXT,
-            receiver    TEXT,
-            mxid        TEXT,
-            name        TEXT,
-            encrypted   BOOLEAN NOT NULL DEFAULT false,
-
-            PRIMARY KEY (chat_id, receiver)
-        )
-        """
-    )
-    await conn.execute(
-        """
-        CREATE TABLE "user" (
-            mxid        TEXT PRIMARY KEY,
-            username    TEXT,
-            uuid        UUID,
-            notice_room TEXT
-        )
-        """
-    )
-    await conn.execute(
-        """
-        CREATE TABLE puppet (
-            uuid      UUID UNIQUE,
-            number    TEXT UNIQUE,
-            name      TEXT,
-
-            uuid_registered   BOOLEAN NOT NULL DEFAULT false,
-            number_registered BOOLEAN NOT NULL DEFAULT false,
-
-            custom_mxid  TEXT,
-            access_token TEXT,
-            next_batch   TEXT
-        )
-        """
-    )
-    await conn.execute(
-        """
-        CREATE TABLE user_portal (
-            "user"          TEXT,
-            portal          TEXT,
-            portal_receiver TEXT,
-            in_community    BOOLEAN NOT NULL DEFAULT false,
-
-            FOREIGN KEY (portal, portal_receiver) REFERENCES portal(chat_id, receiver)
-                ON UPDATE CASCADE ON DELETE CASCADE
-        )
-        """
-    )
-    await conn.execute(
-        """
-        CREATE TABLE message (
-            mxid    TEXT NOT NULL,
-            mx_room TEXT NOT NULL,
-            sender          UUID,
-            timestamp       BIGINT,
-            signal_chat_id  TEXT,
-            signal_receiver TEXT,
-
-            PRIMARY KEY (sender, timestamp, signal_chat_id, signal_receiver),
-            FOREIGN KEY (signal_chat_id, signal_receiver) REFERENCES portal(chat_id, receiver)
-                ON UPDATE CASCADE ON DELETE CASCADE,
-            UNIQUE (mxid, mx_room)
-        )
-        """
-    )
-    await conn.execute(
-        """
-        CREATE TABLE reaction (
-            mxid    TEXT NOT NULL,
-            mx_room TEXT NOT NULL,
-
-            signal_chat_id  TEXT   NOT NULL,
-            signal_receiver TEXT   NOT NULL,
-            msg_author      UUID   NOT NULL,
-            msg_timestamp   BIGINT NOT NULL,
-            author          UUID   NOT NULL,
-
-            emoji TEXT NOT NULL,
-
-            PRIMARY KEY (signal_chat_id, signal_receiver, msg_author, msg_timestamp, author),
-            FOREIGN KEY (msg_author, msg_timestamp, signal_chat_id, signal_receiver)
-                REFERENCES message(sender, timestamp, signal_chat_id, signal_receiver)
-                ON DELETE CASCADE ON UPDATE CASCADE,
-            UNIQUE (mxid, mx_room)
-        )
-        """
-    )
-
-
-@upgrade_table.register(description="Add avatar info to portal table")
-async def upgrade_v2(conn: Connection) -> None:
-    await conn.execute("ALTER TABLE portal ADD COLUMN avatar_hash TEXT")
-    await conn.execute("ALTER TABLE portal ADD COLUMN avatar_url TEXT")
-
-
-@upgrade_table.register(description="Add double-puppeting base_url to puppe table")
-async def upgrade_v3(conn: Connection) -> None:
-    await conn.execute("ALTER TABLE puppet ADD COLUMN base_url TEXT")
-
-
-@upgrade_table.register(description="Allow phone numbers as message sender identifiers")
-async def upgrade_v4(conn: Connection, scheme: str) -> None:
-    if scheme == "sqlite":
-        # SQLite doesn't have anything in the tables yet,
-        # so just recreate them without migrating data
-        await conn.execute("DROP TABLE message")
-        await conn.execute("DROP TABLE reaction")
-        await conn.execute(
-            """
-            CREATE TABLE message (
-                mxid    TEXT NOT NULL,
-                mx_room TEXT NOT NULL,
-                sender          TEXT,
-                timestamp       BIGINT,
-                signal_chat_id  TEXT,
-                signal_receiver TEXT,
-
-                PRIMARY KEY (sender, timestamp, signal_chat_id, signal_receiver),
-                FOREIGN KEY (signal_chat_id, signal_receiver) REFERENCES portal(chat_id, receiver)
-                    ON UPDATE CASCADE ON DELETE CASCADE,
-                UNIQUE (mxid, mx_room)
-            )
-            """
-        )
-        await conn.execute(
-            """
-            CREATE TABLE reaction (
-                mxid    TEXT NOT NULL,
-                mx_room TEXT NOT NULL,
-
-                signal_chat_id  TEXT   NOT NULL,
-                signal_receiver TEXT   NOT NULL,
-                msg_author      TEXT   NOT NULL,
-                msg_timestamp   BIGINT NOT NULL,
-                author          TEXT   NOT NULL,
-
-                emoji TEXT NOT NULL,
-
-                PRIMARY KEY (signal_chat_id, signal_receiver, msg_author, msg_timestamp, author),
-                FOREIGN KEY (msg_author, msg_timestamp, signal_chat_id, signal_receiver)
-                    REFERENCES message(sender, timestamp, signal_chat_id, signal_receiver)
-                    ON DELETE CASCADE ON UPDATE CASCADE,
-                UNIQUE (mxid, mx_room)
-            )
-            """
-        )
-        return
-
-    cname = await conn.fetchval(
-        "SELECT constraint_name FROM information_schema.table_constraints "
-        "WHERE table_name='reaction' AND constraint_name LIKE '%_fkey'"
-    )
-    await conn.execute(f"ALTER TABLE reaction DROP CONSTRAINT {cname}")
-    await conn.execute("ALTER TABLE reaction ALTER COLUMN msg_author SET DATA TYPE TEXT")
-    await conn.execute("ALTER TABLE reaction ALTER COLUMN author SET DATA TYPE TEXT")
-    await conn.execute("ALTER TABLE message ALTER COLUMN sender SET DATA TYPE TEXT")
-    await conn.execute(
-        f"ALTER TABLE reaction ADD CONSTRAINT {cname} "
-        "FOREIGN KEY (msg_author, msg_timestamp, signal_chat_id, signal_receiver) "
-        "  REFERENCES message(sender, timestamp, signal_chat_id, signal_receiver) "
-        "  ON DELETE CASCADE ON UPDATE CASCADE"
-    )
-
-
-@upgrade_table.register(description="Add avatar info to puppet table")
-async def upgrade_v5(conn: Connection) -> None:
-    await conn.execute("ALTER TABLE puppet ADD COLUMN avatar_hash TEXT")
-    await conn.execute("ALTER TABLE puppet ADD COLUMN avatar_url TEXT")
-    await conn.execute("ALTER TABLE puppet ADD COLUMN name_set BOOLEAN NOT NULL DEFAULT false")
-    await conn.execute("ALTER TABLE puppet ADD COLUMN avatar_set BOOLEAN NOT NULL DEFAULT false")
-    await conn.execute("UPDATE puppet SET name_set=true WHERE name<>''")
-
-
-@upgrade_table.register(description="Add revision to portal table")
-async def upgrade_v6(conn: Connection) -> None:
-    await conn.execute("ALTER TABLE portal ADD COLUMN name_set BOOLEAN NOT NULL DEFAULT false")
-    await conn.execute("ALTER TABLE portal ADD COLUMN avatar_set BOOLEAN NOT NULL DEFAULT false")
-    await conn.execute("ALTER TABLE portal ADD COLUMN revision INTEGER NOT NULL DEFAULT 0")
-    await conn.execute("UPDATE portal SET name_set=true WHERE name<>''")
-    await conn.execute("UPDATE portal SET avatar_set=true WHERE avatar_hash<>''")
-
-
-@upgrade_table.register(description="Add relay user field to portal table")
-async def upgrade_v7(conn: Connection) -> None:
-    await conn.execute("ALTER TABLE portal ADD COLUMN relay_user_id TEXT")
-
-
-@upgrade_table.register(description="Add support for disappearing messages")
-async def upgrade_v8(conn: Connection) -> None:
-    await conn.execute(
-        """
-        CREATE TABLE disappearing_message (
-            room_id             TEXT,
-            mxid                TEXT,
-            expiration_seconds  BIGINT,
-            expiration_ts       BIGINT,
-
-            PRIMARY KEY (room_id, mxid)
-        )
-        """
-    )
-    await conn.execute("ALTER TABLE portal ADD COLUMN expiration_time BIGINT")

+ 14 - 0
mautrix_signal/db/upgrade/__init__.py

@@ -0,0 +1,14 @@
+from mautrix.util.async_db import UpgradeTable
+
+upgrade_table = UpgradeTable()
+
+from . import (
+    v00_latest_revision,
+    v02_portal_avatar_info,
+    v03_puppet_base_url,
+    v04_phone_sender_identifier,
+    v05_puppet_avatar_info,
+    v06_portal_revision,
+    v07_portal_relay_user,
+    v08_disappearing_messages,
+)

+ 123 - 0
mautrix_signal/db/upgrade/v00_latest_revision.py

@@ -0,0 +1,123 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Initial revision", upgrades_to=8)
+async def upgrade_latest(conn: Connection) -> None:
+    await conn.execute(
+        """CREATE TABLE portal (
+            chat_id     TEXT,
+            receiver    TEXT,
+            mxid        TEXT,
+            name        TEXT,
+            encrypted   BOOLEAN NOT NULL DEFAULT false,
+            avatar_hash TEXT,
+            avatar_url  TEXT,
+            name_set    BOOLEAN NOT NULL DEFAULT false,
+            avatar_set  BOOLEAN NOT NULL DEFAULT false,
+            revision    INTEGER NOT NULL DEFAULT 0,
+            expiration_time BIGINT,
+            relay_user_id   TEXT,
+
+            PRIMARY KEY (chat_id, receiver)
+        )"""
+    )
+    await conn.execute(
+        """CREATE TABLE "user" (
+            mxid        TEXT PRIMARY KEY,
+            username    TEXT,
+            uuid        UUID,
+            notice_room TEXT
+        )"""
+    )
+    await conn.execute(
+        """CREATE TABLE puppet (
+            uuid        UUID UNIQUE,
+            number      TEXT UNIQUE,
+            name        TEXT,
+            avatar_hash TEXT,
+            avatar_url  TEXT,
+            name_set    BOOLEAN NOT NULL DEFAULT false,
+            avatar_set  BOOLEAN NOT NULL DEFAULT false,
+
+            uuid_registered   BOOLEAN NOT NULL DEFAULT false,
+            number_registered BOOLEAN NOT NULL DEFAULT false,
+
+            custom_mxid  TEXT,
+            access_token TEXT,
+            next_batch   TEXT,
+            base_url     TEXT
+        )"""
+    )
+    await conn.execute(
+        """CREATE TABLE user_portal (
+            "user"          TEXT,
+            portal          TEXT,
+            portal_receiver TEXT,
+            in_community    BOOLEAN NOT NULL DEFAULT false,
+
+            FOREIGN KEY (portal, portal_receiver) REFERENCES portal(chat_id, receiver)
+                ON UPDATE CASCADE ON DELETE CASCADE
+        )"""
+    )
+    await conn.execute(
+        """CREATE TABLE message (
+            mxid    TEXT NOT NULL,
+            mx_room TEXT NOT NULL,
+            sender          TEXT,
+            timestamp       BIGINT,
+            signal_chat_id  TEXT,
+            signal_receiver TEXT,
+
+            PRIMARY KEY (sender, timestamp, signal_chat_id, signal_receiver),
+            FOREIGN KEY (signal_chat_id, signal_receiver) REFERENCES portal(chat_id, receiver)
+                ON UPDATE CASCADE ON DELETE CASCADE,
+            UNIQUE (mxid, mx_room)
+        )"""
+    )
+    await conn.execute(
+        """CREATE TABLE reaction (
+            mxid    TEXT NOT NULL,
+            mx_room TEXT NOT NULL,
+
+            signal_chat_id  TEXT   NOT NULL,
+            signal_receiver TEXT   NOT NULL,
+            msg_author      TEXT   NOT NULL,
+            msg_timestamp   BIGINT NOT NULL,
+            author          TEXT   NOT NULL,
+
+            emoji TEXT NOT NULL,
+
+            PRIMARY KEY (signal_chat_id, signal_receiver, msg_author, msg_timestamp, author),
+            FOREIGN KEY (msg_author, msg_timestamp, signal_chat_id, signal_receiver)
+                REFERENCES message(sender, timestamp, signal_chat_id, signal_receiver)
+                ON DELETE CASCADE ON UPDATE CASCADE,
+            UNIQUE (mxid, mx_room)
+        )"""
+    )
+    await conn.execute(
+        """CREATE TABLE disappearing_message (
+            room_id             TEXT,
+            mxid                TEXT,
+            expiration_seconds  BIGINT,
+            expiration_ts       BIGINT,
+
+            PRIMARY KEY (room_id, mxid)
+        )"""
+    )

+ 24 - 0
mautrix_signal/db/upgrade/v02_portal_avatar_info.py

@@ -0,0 +1,24 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Add avatar info to portal table")
+async def upgrade_v2(conn: Connection) -> None:
+    await conn.execute("ALTER TABLE portal ADD COLUMN avatar_hash TEXT")
+    await conn.execute("ALTER TABLE portal ADD COLUMN avatar_url TEXT")

+ 23 - 0
mautrix_signal/db/upgrade/v03_puppet_base_url.py

@@ -0,0 +1,23 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Add double puppeting base_url to puppet table")
+async def upgrade_v3(conn: Connection) -> None:
+    await conn.execute("ALTER TABLE puppet ADD COLUMN base_url TEXT")

+ 38 - 0
mautrix_signal/db/upgrade/v04_phone_sender_identifier.py

@@ -0,0 +1,38 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection, Scheme
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Allow phone numbers as message sender identifiers")
+async def upgrade_v4(conn: Connection, scheme: Scheme) -> None:
+    assert scheme != Scheme.SQLITE, "There shouldn't be any SQLites with this old schemes"
+
+    cname = await conn.fetchval(
+        "SELECT constraint_name FROM information_schema.table_constraints "
+        "WHERE table_name='reaction' AND constraint_name LIKE '%_fkey'"
+    )
+    await conn.execute(f"ALTER TABLE reaction DROP CONSTRAINT {cname}")
+    await conn.execute("ALTER TABLE reaction ALTER COLUMN msg_author SET DATA TYPE TEXT")
+    await conn.execute("ALTER TABLE reaction ALTER COLUMN author SET DATA TYPE TEXT")
+    await conn.execute("ALTER TABLE message ALTER COLUMN sender SET DATA TYPE TEXT")
+    await conn.execute(
+        f"ALTER TABLE reaction ADD CONSTRAINT {cname} "
+        "FOREIGN KEY (msg_author, msg_timestamp, signal_chat_id, signal_receiver) "
+        "  REFERENCES message(sender, timestamp, signal_chat_id, signal_receiver) "
+        "  ON DELETE CASCADE ON UPDATE CASCADE"
+    )

+ 27 - 0
mautrix_signal/db/upgrade/v05_puppet_avatar_info.py

@@ -0,0 +1,27 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Add avatar info to puppet table")
+async def upgrade_v5(conn: Connection) -> None:
+    await conn.execute("ALTER TABLE puppet ADD COLUMN avatar_hash TEXT")
+    await conn.execute("ALTER TABLE puppet ADD COLUMN avatar_url TEXT")
+    await conn.execute("ALTER TABLE puppet ADD COLUMN name_set BOOLEAN NOT NULL DEFAULT false")
+    await conn.execute("ALTER TABLE puppet ADD COLUMN avatar_set BOOLEAN NOT NULL DEFAULT false")
+    await conn.execute("UPDATE puppet SET name_set=true WHERE name<>''")

+ 27 - 0
mautrix_signal/db/upgrade/v06_portal_revision.py

@@ -0,0 +1,27 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Add revision to portal table")
+async def upgrade_v6(conn: Connection) -> None:
+    await conn.execute("ALTER TABLE portal ADD COLUMN name_set BOOLEAN NOT NULL DEFAULT false")
+    await conn.execute("ALTER TABLE portal ADD COLUMN avatar_set BOOLEAN NOT NULL DEFAULT false")
+    await conn.execute("ALTER TABLE portal ADD COLUMN revision INTEGER NOT NULL DEFAULT 0")
+    await conn.execute("UPDATE portal SET name_set=true WHERE name<>''")
+    await conn.execute("UPDATE portal SET avatar_set=true WHERE avatar_hash<>''")

+ 23 - 0
mautrix_signal/db/upgrade/v07_portal_relay_user.py

@@ -0,0 +1,23 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Add relay user field to portal table")
+async def upgrade_v7(conn: Connection) -> None:
+    await conn.execute("ALTER TABLE portal ADD COLUMN relay_user_id TEXT")

+ 33 - 0
mautrix_signal/db/upgrade/v08_disappearing_messages.py

@@ -0,0 +1,33 @@
+# mautrix-signal - A Matrix-Signal puppeting bridge
+# Copyright (C) 2022 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.async_db import Connection
+
+from . import upgrade_table
+
+
+@upgrade_table.register(description="Add support for disappearing messages")
+async def upgrade_v8(conn: Connection) -> None:
+    await conn.execute(
+        """CREATE TABLE disappearing_message (
+            room_id             TEXT,
+            mxid                TEXT,
+            expiration_seconds  BIGINT,
+            expiration_ts       BIGINT,
+
+            PRIMARY KEY (room_id, mxid)
+        )"""
+    )
+    await conn.execute("ALTER TABLE portal ADD COLUMN expiration_time BIGINT")

+ 1 - 1
requirements.txt

@@ -4,5 +4,5 @@ commonmark>=0.8,<0.10
 aiohttp>=3,<4
 yarl>=1,<2
 attrs>=19.1
-mautrix>=0.14.8,<0.15
+mautrix==0.15.0rc1
 asyncpg>=0.20,<0.26