Switch to BIGINT for Telegram IDs in database
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""Switch Telegram IDs to bigints
|
||||
|
||||
Revision ID: ec1d3dcc77e9
|
||||
Revises: 990f4395afc6
|
||||
Create Date: 2021-03-09 21:36:58.443727
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ec1d3dcc77e9'
|
||||
down_revision = '990f4395afc6'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
columns_to_upgrade = (
|
||||
("bot_chat", "id"),
|
||||
("message", "tgid"),
|
||||
("message", "tg_space"),
|
||||
("portal", "tgid"),
|
||||
("portal", "tg_receiver"),
|
||||
("puppet", "id"),
|
||||
("puppet", "displayname_source"),
|
||||
("user", "tgid"),
|
||||
("user_portal", "user"),
|
||||
("user_portal", "portal"),
|
||||
("user_portal", "portal_receiver"),
|
||||
("contact", "user"),
|
||||
("contact", "contact"),
|
||||
)
|
||||
|
||||
|
||||
def upgrade():
|
||||
if op.get_context().dialect.name == "postgresql":
|
||||
for table, column in columns_to_upgrade:
|
||||
op.alter_column(table, column, existing_type=sa.Integer, type_=sa.BigInteger)
|
||||
|
||||
|
||||
def downgrade():
|
||||
if op.get_context().dialect.name == "postgresql":
|
||||
for table, column in columns_to_upgrade:
|
||||
op.alter_column(table, column, existing_type=sa.BigInteger, type_=sa.Integer)
|
||||
@@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from typing import Iterable
|
||||
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from sqlalchemy import Column, BigInteger, String
|
||||
|
||||
from mautrix.util.db import Base
|
||||
|
||||
@@ -25,7 +25,7 @@ from ..types import TelegramID
|
||||
# Fucking Telegram not telling bots what chats they are in 3:<
|
||||
class BotChat(Base):
|
||||
__tablename__ = "bot_chat"
|
||||
id: TelegramID = Column(Integer, primary_key=True)
|
||||
id: TelegramID = Column(BigInteger, primary_key=True)
|
||||
type: str = Column(String, nullable=False)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from typing import Optional, Iterator, List
|
||||
|
||||
from sqlalchemy import (Column, UniqueConstraint, Integer, String, Boolean, and_, func, desc,
|
||||
select, false)
|
||||
from sqlalchemy import (Column, UniqueConstraint, BigInteger, Integer, String, Boolean, and_, func,
|
||||
desc, select, false)
|
||||
|
||||
from mautrix.types import RoomID, EventID
|
||||
from mautrix.util.db import Base
|
||||
@@ -29,8 +29,8 @@ class Message(Base):
|
||||
|
||||
mxid: EventID = Column(String)
|
||||
mx_room: RoomID = Column(String)
|
||||
tgid: TelegramID = Column(Integer, primary_key=True)
|
||||
tg_space: TelegramID = Column(Integer, primary_key=True)
|
||||
tgid: TelegramID = Column(BigInteger, primary_key=True)
|
||||
tg_space: TelegramID = Column(BigInteger, primary_key=True)
|
||||
edit_index: int = Column(Integer, primary_key=True)
|
||||
redacted: bool = Column(Boolean, server_default=false())
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from typing import Optional, Iterable
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Text, func, sql
|
||||
from sqlalchemy import Column, BigInteger, String, Boolean, Text, func, sql
|
||||
|
||||
from mautrix.types import RoomID, ContentURI
|
||||
from mautrix.util.db import Base
|
||||
@@ -27,8 +27,8 @@ class Portal(Base):
|
||||
__tablename__ = "portal"
|
||||
|
||||
# Telegram chat information
|
||||
tgid: TelegramID = Column(Integer, primary_key=True)
|
||||
tg_receiver: TelegramID = Column(Integer, primary_key=True)
|
||||
tgid: TelegramID = Column(BigInteger, primary_key=True)
|
||||
tg_receiver: TelegramID = Column(BigInteger, primary_key=True)
|
||||
peer_type: str = Column(String, nullable=False)
|
||||
megagroup: bool = Column(Boolean)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from typing import Optional, Iterable
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Text, Boolean
|
||||
from sqlalchemy import Column, BigInteger, String, Text, Boolean
|
||||
from sqlalchemy.sql import expression, func
|
||||
|
||||
from mautrix.types import UserID, SyncToken
|
||||
@@ -27,13 +27,13 @@ from ..types import TelegramID
|
||||
class Puppet(Base):
|
||||
__tablename__ = "puppet"
|
||||
|
||||
id: TelegramID = Column(Integer, primary_key=True)
|
||||
id: TelegramID = Column(BigInteger, primary_key=True)
|
||||
custom_mxid: UserID = Column(String, nullable=True)
|
||||
access_token: str = Column(String, nullable=True)
|
||||
next_batch: SyncToken = Column(String, nullable=True)
|
||||
base_url: str = Column(Text, nullable=True)
|
||||
displayname: str = Column(String, nullable=True)
|
||||
displayname_source: TelegramID = Column(Integer, nullable=True)
|
||||
displayname_source: TelegramID = Column(BigInteger, nullable=True)
|
||||
displayname_contact: bool = Column(Boolean, nullable=False, server_default=expression.true())
|
||||
username: str = Column(String, nullable=True)
|
||||
photo_id: str = Column(String, nullable=True)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from typing import Optional, Iterable, Tuple
|
||||
|
||||
from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, Integer, String, func
|
||||
from sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, BigInteger, Integer, String, func
|
||||
|
||||
from mautrix.types import UserID
|
||||
from mautrix.util.db import Base
|
||||
@@ -27,7 +27,7 @@ class User(Base):
|
||||
__tablename__ = "user"
|
||||
|
||||
mxid: UserID = Column(String, primary_key=True)
|
||||
tgid: Optional[TelegramID] = Column(Integer, nullable=True, unique=True)
|
||||
tgid: Optional[TelegramID] = Column(BigInteger, nullable=True, unique=True)
|
||||
tg_username: str = Column(String, nullable=True)
|
||||
tg_phone: str = Column(String, nullable=True)
|
||||
saved_contacts: int = Column(Integer, default=0, nullable=False)
|
||||
@@ -91,10 +91,10 @@ class User(Base):
|
||||
class UserPortal(Base):
|
||||
__tablename__ = "user_portal"
|
||||
|
||||
user: TelegramID = Column(Integer, ForeignKey("user.tgid", onupdate="CASCADE",
|
||||
user: TelegramID = Column(BigInteger, ForeignKey("user.tgid", onupdate="CASCADE",
|
||||
ondelete="CASCADE"), primary_key=True)
|
||||
portal: TelegramID = Column(Integer, primary_key=True)
|
||||
portal_receiver: TelegramID = Column(Integer, primary_key=True)
|
||||
portal: TelegramID = Column(BigInteger, primary_key=True)
|
||||
portal_receiver: TelegramID = Column(BigInteger, primary_key=True)
|
||||
|
||||
__table_args__ = (ForeignKeyConstraint(("portal", "portal_receiver"),
|
||||
("portal.tgid", "portal.tg_receiver"),
|
||||
@@ -104,5 +104,5 @@ class UserPortal(Base):
|
||||
class Contact(Base):
|
||||
__tablename__ = "contact"
|
||||
|
||||
user: TelegramID = Column(Integer, ForeignKey("user.tgid"), primary_key=True)
|
||||
contact: TelegramID = Column(Integer, ForeignKey("puppet.id"), primary_key=True)
|
||||
user: TelegramID = Column(BigInteger, ForeignKey("user.tgid"), primary_key=True)
|
||||
contact: TelegramID = Column(BigInteger, ForeignKey("puppet.id"), primary_key=True)
|
||||
|
||||
@@ -21,7 +21,7 @@ prometheus_client>=0.6,<0.10
|
||||
psycopg2-binary>=2,<3
|
||||
|
||||
#/e2be
|
||||
asyncpg>=0.20,<0.22
|
||||
asyncpg>=0.20,<0.23
|
||||
python-olm>=3,<4
|
||||
pycryptodome>=3,<4
|
||||
unpaddedbase64>=1,<2
|
||||
|
||||
Reference in New Issue
Block a user