mirror of
https://github.com/maubot/maubot.git
synced 2024-10-01 01:06:10 -04:00
Add device_id to client db
This commit is contained in:
parent
9578883bbb
commit
09108f6a73
@ -56,6 +56,7 @@ def run_migrations_offline():
|
|||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
literal_binds=True,
|
literal_binds=True,
|
||||||
dialect_opts={"paramstyle": "named"},
|
dialect_opts={"paramstyle": "named"},
|
||||||
|
render_as_batch=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
@ -77,7 +78,8 @@ def run_migrations_online():
|
|||||||
|
|
||||||
with connectable.connect() as connection:
|
with connectable.connect() as connection:
|
||||||
context.configure(
|
context.configure(
|
||||||
connection=connection, target_metadata=target_metadata
|
connection=connection, target_metadata=target_metadata,
|
||||||
|
render_as_batch=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
|
32
alembic/versions/4b93300852aa_add_device_id_to_clients.py
Normal file
32
alembic/versions/4b93300852aa_add_device_id_to_clients.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"""Add device_id to clients
|
||||||
|
|
||||||
|
Revision ID: 4b93300852aa
|
||||||
|
Revises: fccd1f95544d
|
||||||
|
Create Date: 2020-07-11 15:49:38.831459
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '4b93300852aa'
|
||||||
|
down_revision = 'fccd1f95544d'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('client', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('device_id', sa.String(length=255), nullable=True))
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('client', schema=None) as batch_op:
|
||||||
|
batch_op.drop_column('device_id')
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
@ -60,7 +60,7 @@ class Client:
|
|||||||
self.remote_avatar_url = None
|
self.remote_avatar_url = None
|
||||||
self.client = MaubotMatrixClient(mxid=self.id, base_url=self.homeserver,
|
self.client = MaubotMatrixClient(mxid=self.id, base_url=self.homeserver,
|
||||||
token=self.access_token, client_session=self.http_client,
|
token=self.access_token, client_session=self.http_client,
|
||||||
log=self.log, loop=self.loop,
|
log=self.log, loop=self.loop, device_id=self.device_id,
|
||||||
store=ClientStoreProxy(self.db_instance))
|
store=ClientStoreProxy(self.db_instance))
|
||||||
self.client.ignore_initial_sync = True
|
self.client.ignore_initial_sync = True
|
||||||
self.client.ignore_first_sync = True
|
self.client.ignore_first_sync = True
|
||||||
@ -273,6 +273,10 @@ class Client:
|
|||||||
def access_token(self) -> str:
|
def access_token(self) -> str:
|
||||||
return self.db_instance.access_token
|
return self.db_instance.access_token
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_id(self) -> str:
|
||||||
|
return self.db_instance.device_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self) -> bool:
|
def enabled(self) -> bool:
|
||||||
return self.db_instance.enabled
|
return self.db_instance.enabled
|
||||||
|
@ -21,7 +21,7 @@ from sqlalchemy import Column, String, Boolean, ForeignKey, Text
|
|||||||
from sqlalchemy.engine.base import Engine
|
from sqlalchemy.engine.base import Engine
|
||||||
import sqlalchemy as sql
|
import sqlalchemy as sql
|
||||||
|
|
||||||
from mautrix.types import UserID, FilterID, SyncToken, ContentURI
|
from mautrix.types import UserID, FilterID, DeviceID, SyncToken, ContentURI
|
||||||
from mautrix.util.db import Base
|
from mautrix.util.db import Base
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
@ -53,6 +53,7 @@ class DBClient(Base):
|
|||||||
id: UserID = Column(String(255), primary_key=True)
|
id: UserID = Column(String(255), primary_key=True)
|
||||||
homeserver: str = Column(String(255), nullable=False)
|
homeserver: str = Column(String(255), nullable=False)
|
||||||
access_token: str = Column(Text, nullable=False)
|
access_token: str = Column(Text, nullable=False)
|
||||||
|
device_id: DeviceID = Column(String(255), nullable=True)
|
||||||
enabled: bool = Column(Boolean, nullable=False, default=False)
|
enabled: bool = Column(Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
next_batch: SyncToken = Column(String(255), nullable=False, default="")
|
next_batch: SyncToken = Column(String(255), nullable=False, default="")
|
||||||
|
@ -21,10 +21,8 @@ class ClientStoreProxy(ClientStore):
|
|||||||
def __init__(self, db_instance) -> None:
|
def __init__(self, db_instance) -> None:
|
||||||
self.db_instance = db_instance
|
self.db_instance = db_instance
|
||||||
|
|
||||||
@property
|
async def put_next_batch(self, next_batch: SyncToken) -> None:
|
||||||
def next_batch(self) -> SyncToken:
|
self.db_instance.edit(next_batch=next_batch)
|
||||||
return self.db_instance.next_batch
|
|
||||||
|
|
||||||
@next_batch.setter
|
async def get_next_batch(self) -> SyncToken:
|
||||||
def next_batch(self, value: SyncToken) -> None:
|
return self.db_instance.next_batch
|
||||||
self.db_instance.edit(next_batch=value)
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
mautrix==0.5.7
|
mautrix==0.6.0.beta7
|
||||||
aiohttp>=3,<4
|
aiohttp>=3,<4
|
||||||
SQLAlchemy>=1,<2
|
SQLAlchemy>=1,<2
|
||||||
alembic>=1,<2
|
alembic>=1,<2
|
||||||
|
Loading…
Reference in New Issue
Block a user