2022-02-25 02:22:50 -05:00
|
|
|
# matrix-appservice-kakaotalk - A Matrix-KakaoTalk puppeting bridge.
|
|
|
|
# Copyright (C) 2022 Tulir Asokan, Andrew Ferrazzutti
|
|
|
|
#
|
|
|
|
# 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 __future__ import annotations
|
|
|
|
|
|
|
|
from mautrix.util.async_db import Connection
|
|
|
|
|
|
|
|
from . import upgrade_table
|
|
|
|
|
|
|
|
|
|
|
|
@upgrade_table.register(description="Initial revision", transaction=False)
|
|
|
|
async def upgrade_v1(conn: Connection) -> None:
|
|
|
|
async with conn.transaction():
|
|
|
|
await create_v1_tables(conn)
|
|
|
|
|
|
|
|
|
|
|
|
async def create_v1_tables(conn: Connection) -> None:
|
|
|
|
await conn.execute(
|
|
|
|
"""CREATE TABLE "user" (
|
|
|
|
mxid TEXT PRIMARY KEY,
|
2022-03-11 03:43:00 -05:00
|
|
|
ktid BIGINT UNIQUE,
|
2022-02-25 02:22:50 -05:00
|
|
|
uuid TEXT,
|
|
|
|
access_token TEXT,
|
|
|
|
refresh_token TEXT,
|
|
|
|
notice_room TEXT
|
|
|
|
)"""
|
|
|
|
)
|
|
|
|
await conn.execute(
|
|
|
|
"""CREATE TABLE portal (
|
2022-03-11 03:43:00 -05:00
|
|
|
ktid BIGINT,
|
|
|
|
kt_receiver BIGINT,
|
2022-03-26 03:37:53 -04:00
|
|
|
kt_type TEXT NOT NULL,
|
2022-02-25 02:22:50 -05:00
|
|
|
mxid TEXT UNIQUE,
|
|
|
|
name TEXT,
|
|
|
|
photo_id TEXT,
|
|
|
|
avatar_url TEXT,
|
|
|
|
encrypted BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
name_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
relay_user_id TEXT,
|
|
|
|
PRIMARY KEY (ktid, kt_receiver)
|
|
|
|
)"""
|
|
|
|
)
|
|
|
|
await conn.execute(
|
|
|
|
"""CREATE TABLE puppet (
|
2022-03-11 03:43:00 -05:00
|
|
|
ktid BIGINT PRIMARY KEY,
|
2022-02-25 02:22:50 -05:00
|
|
|
name TEXT,
|
|
|
|
photo_id TEXT,
|
|
|
|
photo_mxc TEXT,
|
|
|
|
|
|
|
|
name_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
is_registered BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
|
|
|
|
custom_mxid TEXT,
|
|
|
|
access_token TEXT,
|
|
|
|
next_batch TEXT,
|
|
|
|
base_url TEXT
|
|
|
|
)"""
|
|
|
|
)
|
|
|
|
await conn.execute(
|
|
|
|
"""CREATE TABLE message (
|
2022-03-26 03:37:53 -04:00
|
|
|
mxid TEXT NOT NULL,
|
|
|
|
mx_room TEXT NOT NULL,
|
2022-03-11 03:43:00 -05:00
|
|
|
ktid BIGINT,
|
2022-03-26 03:37:53 -04:00
|
|
|
kt_receiver BIGINT NOT NULL,
|
|
|
|
"index" SMALLINT NOT NULL,
|
|
|
|
kt_chat BIGINT NOT NULL,
|
|
|
|
timestamp BIGINT NOT NULL,
|
2022-02-25 02:22:50 -05:00
|
|
|
PRIMARY KEY (ktid, kt_receiver, "index"),
|
|
|
|
FOREIGN KEY (kt_chat, kt_receiver) REFERENCES portal(ktid, kt_receiver)
|
|
|
|
ON UPDATE CASCADE ON DELETE CASCADE,
|
|
|
|
UNIQUE (mxid, mx_room)
|
|
|
|
)"""
|
|
|
|
)
|
|
|
|
await conn.execute(
|
|
|
|
"""CREATE TABLE reaction (
|
|
|
|
mxid TEXT,
|
|
|
|
mx_room TEXT,
|
|
|
|
kt_msgid TEXT,
|
2022-03-11 03:43:00 -05:00
|
|
|
kt_receiver BIGINT,
|
|
|
|
kt_sender BIGINT,
|
2022-02-25 02:22:50 -05:00
|
|
|
reaction TEXT,
|
|
|
|
PRIMARY KEY (kt_msgid, kt_receiver, kt_sender),
|
|
|
|
UNIQUE (mxid, mx_room)
|
|
|
|
)"""
|
|
|
|
)
|