matrix-appservice-kakaotalk/matrix_appservice_kakaotalk/db/upgrade/v01_initial_revision.py
Andrew Ferrazzutti 4158788496 Clean up Long
Keep it as an int in Python, and do all fancy conversions in Node
2022-03-11 20:40:33 -05:00

100 lines
3.3 KiB
Python

# 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,
ktid BIGINT UNIQUE,
uuid TEXT,
access_token TEXT,
refresh_token TEXT,
notice_room TEXT
)"""
)
await conn.execute(
"""CREATE TABLE portal (
ktid BIGINT,
kt_receiver BIGINT,
kt_type TEXT,
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 (
ktid BIGINT PRIMARY KEY,
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 (
mxid TEXT,
mx_room TEXT,
ktid BIGINT,
kt_receiver BIGINT,
"index" SMALLINT,
kt_chat BIGINT,
timestamp BIGINT,
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,
kt_receiver BIGINT,
kt_sender BIGINT,
reaction TEXT,
PRIMARY KEY (kt_msgid, kt_receiver, kt_sender),
UNIQUE (mxid, mx_room)
)"""
)