slidge 0.1.3__py3-none-any.whl → 0.2.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- slidge/__init__.py +3 -5
- slidge/__main__.py +2 -197
- slidge/__version__.py +5 -0
- slidge/command/adhoc.py +40 -17
- slidge/command/admin.py +24 -12
- slidge/command/base.py +10 -8
- slidge/command/categories.py +13 -3
- slidge/command/chat_command.py +29 -2
- slidge/command/register.py +32 -16
- slidge/command/user.py +106 -13
- slidge/contact/contact.py +254 -50
- slidge/contact/roster.py +124 -53
- slidge/core/config.py +19 -13
- slidge/core/dispatcher/__init__.py +3 -0
- slidge/core/{gateway → dispatcher}/caps.py +12 -8
- slidge/core/{gateway → dispatcher}/disco.py +10 -18
- slidge/core/dispatcher/message/__init__.py +10 -0
- slidge/core/dispatcher/message/chat_state.py +40 -0
- slidge/core/dispatcher/message/marker.py +62 -0
- slidge/core/dispatcher/message/message.py +397 -0
- slidge/core/dispatcher/muc/__init__.py +12 -0
- slidge/core/dispatcher/muc/admin.py +98 -0
- slidge/core/{gateway → dispatcher/muc}/mam.py +25 -17
- slidge/core/dispatcher/muc/misc.py +121 -0
- slidge/core/dispatcher/muc/owner.py +96 -0
- slidge/core/{gateway → dispatcher/muc}/ping.py +11 -17
- slidge/core/dispatcher/presence.py +176 -0
- slidge/core/dispatcher/registration.py +85 -0
- slidge/core/{gateway → dispatcher}/search.py +9 -16
- slidge/core/dispatcher/session_dispatcher.py +84 -0
- slidge/core/dispatcher/util.py +174 -0
- slidge/core/{gateway/vcard_temp.py → dispatcher/vcard.py} +35 -19
- slidge/core/{gateway/base.py → gateway.py} +176 -153
- slidge/core/mixins/__init__.py +11 -1
- slidge/core/mixins/attachment.py +106 -67
- slidge/core/mixins/avatar.py +94 -25
- slidge/core/mixins/base.py +10 -4
- slidge/core/mixins/db.py +18 -0
- slidge/core/mixins/disco.py +0 -10
- slidge/core/mixins/lock.py +10 -8
- slidge/core/mixins/message.py +11 -195
- slidge/core/mixins/message_maker.py +17 -9
- slidge/core/mixins/message_text.py +211 -0
- slidge/core/mixins/presence.py +17 -4
- slidge/core/pubsub.py +114 -288
- slidge/core/session.py +101 -40
- slidge/db/__init__.py +4 -0
- slidge/db/alembic/__init__.py +0 -0
- slidge/db/alembic/env.py +64 -0
- slidge/db/alembic/old_user_store.py +183 -0
- slidge/db/alembic/script.py.mako +26 -0
- slidge/db/alembic/versions/09f27f098baa_add_missing_attributes_in_room.py +36 -0
- slidge/db/alembic/versions/15b0bd83407a_remove_bogus_unique_constraints_on_room_.py +85 -0
- slidge/db/alembic/versions/2461390c0af2_store_contacts_caps_verstring_in_db.py +36 -0
- slidge/db/alembic/versions/29f5280c61aa_store_subject_setter_in_room.py +37 -0
- slidge/db/alembic/versions/2b1f45ab7379_store_room_subject_setter_by_nickname.py +41 -0
- slidge/db/alembic/versions/3071e0fa69d4_add_contact_client_type.py +52 -0
- slidge/db/alembic/versions/45c24cc73c91_add_bob.py +42 -0
- slidge/db/alembic/versions/5bd48bfdffa2_lift_room_legacy_id_constraint.py +61 -0
- slidge/db/alembic/versions/82a4af84b679_add_muc_history_filled.py +48 -0
- slidge/db/alembic/versions/8b993243a536_add_vcard_content_to_contact_table.py +43 -0
- slidge/db/alembic/versions/8d2ced764698_rely_on_db_to_store_contacts_rooms_and_.py +139 -0
- slidge/db/alembic/versions/aa9d82a7f6ef_db_creation.py +101 -0
- slidge/db/alembic/versions/abba1ae0edb3_store_avatar_legacy_id_in_the_contact_.py +79 -0
- slidge/db/alembic/versions/b33993e87db3_move_everything_to_persistent_db.py +214 -0
- slidge/db/alembic/versions/b64b1a793483_add_source_and_legacy_id_for_archived_.py +52 -0
- slidge/db/alembic/versions/c4a8ec35a0e8_per_room_user_nick.py +34 -0
- slidge/db/alembic/versions/e91195719c2c_store_users_avatars_persistently.py +26 -0
- slidge/db/avatar.py +205 -0
- slidge/db/meta.py +72 -0
- slidge/db/models.py +405 -0
- slidge/db/store.py +1257 -0
- slidge/group/archive.py +58 -14
- slidge/group/bookmarks.py +89 -65
- slidge/group/participant.py +107 -40
- slidge/group/room.py +402 -213
- slidge/main.py +202 -0
- slidge/migration.py +45 -1
- slidge/slixfix/__init__.py +31 -1
- slidge/{core/gateway → slixfix}/delivery_receipt.py +1 -1
- slidge/slixfix/roster.py +13 -4
- slidge/slixfix/xep_0292/vcard4.py +1 -87
- slidge/util/archive_msg.py +2 -1
- slidge/util/db.py +4 -228
- slidge/util/test.py +91 -4
- slidge/util/types.py +39 -4
- slidge/util/util.py +45 -2
- {slidge-0.1.3.dist-info → slidge-0.2.0.dist-info}/METADATA +10 -5
- slidge-0.2.0.dist-info/RECORD +131 -0
- slidge-0.2.0.dist-info/entry_points.txt +3 -0
- slidge/core/cache.py +0 -183
- slidge/core/gateway/__init__.py +0 -3
- slidge/core/gateway/muc_admin.py +0 -35
- slidge/core/gateway/presence.py +0 -95
- slidge/core/gateway/registration.py +0 -53
- slidge/core/gateway/session_dispatcher.py +0 -804
- slidge/util/schema.sql +0 -126
- slidge/util/sql.py +0 -508
- slidge-0.1.3.dist-info/RECORD +0 -96
- slidge-0.1.3.dist-info/entry_points.txt +0 -3
- {slidge-0.1.3.dist-info → slidge-0.2.0.dist-info}/LICENSE +0 -0
- {slidge-0.1.3.dist-info → slidge-0.2.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
"""Store contacts caps verstring in DB
|
2
|
+
|
3
|
+
Revision ID: 2461390c0af2
|
4
|
+
Revises: 2b1f45ab7379
|
5
|
+
Create Date: 2024-07-20 08:00:11.675735
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = "2461390c0af2"
|
16
|
+
down_revision: Union[str, None] = "2b1f45ab7379"
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
23
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
24
|
+
batch_op.add_column(sa.Column("caps_ver_bare", sa.String(), nullable=True))
|
25
|
+
batch_op.add_column(sa.Column("caps_ver", sa.String(), nullable=True))
|
26
|
+
|
27
|
+
# ### end Alembic commands ###
|
28
|
+
|
29
|
+
|
30
|
+
def downgrade() -> None:
|
31
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
32
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
33
|
+
batch_op.drop_column("caps_ver")
|
34
|
+
batch_op.drop_column("caps_ver_bare")
|
35
|
+
|
36
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"""Store subject setter in Room
|
2
|
+
|
3
|
+
Revision ID: 29f5280c61aa
|
4
|
+
Revises: 8d2ced764698
|
5
|
+
Create Date: 2024-07-10 13:09:25.181594
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = "29f5280c61aa"
|
16
|
+
down_revision: Union[str, None] = "8d2ced764698"
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
23
|
+
batch_op.add_column(sa.Column("subject_setter_id", sa.Integer(), nullable=True))
|
24
|
+
# we give this constraint a name a workaround for
|
25
|
+
# https://github.com/sqlalchemy/alembic/issues/1195
|
26
|
+
batch_op.create_foreign_key(
|
27
|
+
"subject_setter_id_foreign_key",
|
28
|
+
"participant",
|
29
|
+
["subject_setter_id"],
|
30
|
+
["id"],
|
31
|
+
)
|
32
|
+
|
33
|
+
|
34
|
+
def downgrade() -> None:
|
35
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
36
|
+
batch_op.drop_constraint("subject_setter_id_foreign_key", type_="foreignkey")
|
37
|
+
batch_op.drop_column("subject_setter_id")
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"""Store room subject setter by nickname
|
2
|
+
|
3
|
+
Revision ID: 2b1f45ab7379
|
4
|
+
Revises: c4a8ec35a0e8
|
5
|
+
Create Date: 2024-07-20 00:14:36.882689
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = "2b1f45ab7379"
|
16
|
+
down_revision: Union[str, None] = "c4a8ec35a0e8"
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
23
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
24
|
+
batch_op.add_column(sa.Column("subject_setter", sa.String(), nullable=True))
|
25
|
+
batch_op.drop_constraint("subject_setter_id_foreign_key", type_="foreignkey")
|
26
|
+
batch_op.drop_column("subject_setter_id")
|
27
|
+
# ### end Alembic commands ###
|
28
|
+
|
29
|
+
|
30
|
+
def downgrade() -> None:
|
31
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
32
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
33
|
+
batch_op.add_column(sa.Column("subject_setter_id", sa.INTEGER(), nullable=True))
|
34
|
+
batch_op.create_foreign_key(
|
35
|
+
"subject_setter_id_foreign_key",
|
36
|
+
"participant",
|
37
|
+
["subject_setter_id"],
|
38
|
+
["id"],
|
39
|
+
)
|
40
|
+
batch_op.drop_column("subject_setter")
|
41
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"""Add Contact.client_type
|
2
|
+
|
3
|
+
Revision ID: 3071e0fa69d4
|
4
|
+
Revises: abba1ae0edb3
|
5
|
+
Create Date: 2024-07-30 23:12:49.345593
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = "3071e0fa69d4"
|
16
|
+
down_revision: Union[str, None] = "abba1ae0edb3"
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
23
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
24
|
+
batch_op.add_column(
|
25
|
+
sa.Column(
|
26
|
+
"client_type",
|
27
|
+
sa.Enum(
|
28
|
+
"bot",
|
29
|
+
"console",
|
30
|
+
"game",
|
31
|
+
"handheld",
|
32
|
+
"pc",
|
33
|
+
"phone",
|
34
|
+
"sms",
|
35
|
+
"tablet",
|
36
|
+
"web",
|
37
|
+
native_enum=False,
|
38
|
+
),
|
39
|
+
nullable=False,
|
40
|
+
server_default=sa.literal("pc"),
|
41
|
+
)
|
42
|
+
)
|
43
|
+
|
44
|
+
# ### end Alembic commands ###
|
45
|
+
|
46
|
+
|
47
|
+
def downgrade() -> None:
|
48
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
49
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
50
|
+
batch_op.drop_column("client_type")
|
51
|
+
|
52
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"""Add BoB
|
2
|
+
|
3
|
+
Revision ID: 45c24cc73c91
|
4
|
+
Revises: 3071e0fa69d4
|
5
|
+
Create Date: 2024-08-01 22:30:07.073935
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = "45c24cc73c91"
|
16
|
+
down_revision: Union[str, None] = "3071e0fa69d4"
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
23
|
+
op.create_table(
|
24
|
+
"bob",
|
25
|
+
sa.Column("id", sa.Integer(), nullable=False),
|
26
|
+
sa.Column("file_name", sa.String(), nullable=False),
|
27
|
+
sa.Column("sha_1", sa.String(), nullable=False),
|
28
|
+
sa.Column("sha_256", sa.String(), nullable=False),
|
29
|
+
sa.Column("sha_512", sa.String(), nullable=False),
|
30
|
+
sa.Column("content_type", sa.String(), nullable=False),
|
31
|
+
sa.PrimaryKeyConstraint("id"),
|
32
|
+
sa.UniqueConstraint("sha_1"),
|
33
|
+
sa.UniqueConstraint("sha_256"),
|
34
|
+
sa.UniqueConstraint("sha_512"),
|
35
|
+
)
|
36
|
+
# ### end Alembic commands ###
|
37
|
+
|
38
|
+
|
39
|
+
def downgrade() -> None:
|
40
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
41
|
+
op.drop_table("bob")
|
42
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"""Lift room legacy ID constraint
|
2
|
+
|
3
|
+
Revision ID: 5bd48bfdffa2
|
4
|
+
Revises: b64b1a793483
|
5
|
+
Create Date: 2024-07-24 10:29:23.467851
|
6
|
+
|
7
|
+
Broken; fixed by "Remove bogus unique constraints on room table",
|
8
|
+
rev 15b0bd83407a.
|
9
|
+
|
10
|
+
"""
|
11
|
+
|
12
|
+
import logging
|
13
|
+
from typing import Sequence, Union
|
14
|
+
|
15
|
+
from alembic import op
|
16
|
+
|
17
|
+
from slidge.db.models import Room
|
18
|
+
|
19
|
+
# revision identifiers, used by Alembic.
|
20
|
+
revision: str = "5bd48bfdffa2"
|
21
|
+
down_revision: Union[str, None] = "b64b1a793483"
|
22
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
23
|
+
depends_on: Union[str, Sequence[str], None] = None
|
24
|
+
|
25
|
+
|
26
|
+
def upgrade() -> None:
|
27
|
+
try:
|
28
|
+
with op.batch_alter_table(
|
29
|
+
"room",
|
30
|
+
schema=None,
|
31
|
+
# without copy_from, the newly created table keeps the constraints
|
32
|
+
# we actually want to ditch.
|
33
|
+
# LATER EDIT: this actually does not work, I should have copied the
|
34
|
+
# schema in here.
|
35
|
+
copy_from=Room.__table__, # type:ignore
|
36
|
+
) as batch_op:
|
37
|
+
batch_op.create_unique_constraint(
|
38
|
+
"uq_room_user_account_id_jid", ["user_account_id", "jid"]
|
39
|
+
)
|
40
|
+
batch_op.create_unique_constraint(
|
41
|
+
"uq_room_user_account_id_legacy_id", ["user_account_id", "legacy_id"]
|
42
|
+
)
|
43
|
+
except Exception:
|
44
|
+
# This only works when upgrading rev by rev because I messed up. It
|
45
|
+
# wouldn't be necessary if the constraint was named in the first place,
|
46
|
+
# cf https://alembic.sqlalchemy.org/en/latest/naming.html
|
47
|
+
# This is fixed by rev 15b0bd83407a
|
48
|
+
log.info("Skipping")
|
49
|
+
pass
|
50
|
+
|
51
|
+
|
52
|
+
def downgrade() -> None:
|
53
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
54
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
55
|
+
batch_op.drop_constraint("uq_room_user_account_id_legacy_id", type_="unique")
|
56
|
+
batch_op.drop_constraint("uq_room_user_account_id_jid", type_="unique")
|
57
|
+
|
58
|
+
# ### end Alembic commands ###
|
59
|
+
|
60
|
+
|
61
|
+
log = logging.getLogger(__name__)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"""Add MUC.history_filled
|
2
|
+
|
3
|
+
Also drop caps_ver_bare column that should never have been added.
|
4
|
+
|
5
|
+
Revision ID: 82a4af84b679
|
6
|
+
Revises: 2461390c0af2
|
7
|
+
Create Date: 2024-07-22 07:01:05.352737
|
8
|
+
|
9
|
+
"""
|
10
|
+
|
11
|
+
from typing import Sequence, Union
|
12
|
+
|
13
|
+
import sqlalchemy as sa
|
14
|
+
from alembic import op
|
15
|
+
|
16
|
+
# revision identifiers, used by Alembic.
|
17
|
+
revision: str = "82a4af84b679"
|
18
|
+
down_revision: Union[str, None] = "2461390c0af2"
|
19
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
20
|
+
depends_on: Union[str, Sequence[str], None] = None
|
21
|
+
|
22
|
+
|
23
|
+
def upgrade() -> None:
|
24
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
25
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
26
|
+
batch_op.drop_column("caps_ver_bare")
|
27
|
+
|
28
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
29
|
+
batch_op.add_column(
|
30
|
+
sa.Column(
|
31
|
+
"history_filled",
|
32
|
+
sa.Boolean(),
|
33
|
+
nullable=False,
|
34
|
+
server_default=sa.False_(), # manually added
|
35
|
+
)
|
36
|
+
)
|
37
|
+
# ### end Alembic commands ###
|
38
|
+
|
39
|
+
|
40
|
+
def downgrade() -> None:
|
41
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
42
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
43
|
+
batch_op.drop_column("history_filled")
|
44
|
+
|
45
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
46
|
+
batch_op.add_column(sa.Column("caps_ver_bare", sa.VARCHAR(), nullable=True))
|
47
|
+
|
48
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"""Add vcard content to contact table
|
2
|
+
|
3
|
+
Revision ID: 8b993243a536
|
4
|
+
Revises: 5bd48bfdffa2
|
5
|
+
Create Date: 2024-07-24 07:02:47.770894
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = "8b993243a536"
|
16
|
+
down_revision: Union[str, None] = "5bd48bfdffa2"
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
23
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
24
|
+
batch_op.add_column(sa.Column("vcard", sa.String(), nullable=True))
|
25
|
+
batch_op.add_column(
|
26
|
+
sa.Column(
|
27
|
+
"vcard_fetched",
|
28
|
+
sa.Boolean(),
|
29
|
+
nullable=False,
|
30
|
+
server_default=sa.sql.true(),
|
31
|
+
)
|
32
|
+
)
|
33
|
+
|
34
|
+
# ### end Alembic commands ###
|
35
|
+
|
36
|
+
|
37
|
+
def downgrade() -> None:
|
38
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
39
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
40
|
+
batch_op.drop_column("vcard_fetched")
|
41
|
+
batch_op.drop_column("vcard")
|
42
|
+
|
43
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"""Rely on DB to store contacts, rooms and participants
|
2
|
+
|
3
|
+
Revision ID: 8d2ced764698
|
4
|
+
Revises: b33993e87db3
|
5
|
+
Create Date: 2024-07-08 14:39:47.022088
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
import slidge.db.meta
|
15
|
+
|
16
|
+
# revision identifiers, used by Alembic.
|
17
|
+
revision: str = "8d2ced764698"
|
18
|
+
down_revision: Union[str, None] = "b33993e87db3"
|
19
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
20
|
+
depends_on: Union[str, Sequence[str], None] = None
|
21
|
+
|
22
|
+
|
23
|
+
def upgrade() -> None:
|
24
|
+
op.create_table(
|
25
|
+
"hat",
|
26
|
+
sa.Column("id", sa.Integer(), nullable=False),
|
27
|
+
sa.Column("title", sa.String(), nullable=False),
|
28
|
+
sa.Column("uri", sa.String(), nullable=False),
|
29
|
+
sa.PrimaryKeyConstraint("id"),
|
30
|
+
sa.UniqueConstraint("title", "uri"),
|
31
|
+
)
|
32
|
+
op.create_table(
|
33
|
+
"contact_sent",
|
34
|
+
sa.Column("id", sa.Integer(), nullable=False),
|
35
|
+
sa.Column("contact_id", sa.Integer(), nullable=False),
|
36
|
+
sa.Column("msg_id", sa.String(), nullable=False),
|
37
|
+
sa.ForeignKeyConstraint(
|
38
|
+
["contact_id"],
|
39
|
+
["contact.id"],
|
40
|
+
),
|
41
|
+
sa.PrimaryKeyConstraint("id"),
|
42
|
+
sa.UniqueConstraint("contact_id", "msg_id"),
|
43
|
+
)
|
44
|
+
op.create_table(
|
45
|
+
"participant",
|
46
|
+
sa.Column("id", sa.Integer(), nullable=False),
|
47
|
+
sa.Column("room_id", sa.Integer(), nullable=False),
|
48
|
+
sa.Column("contact_id", sa.Integer(), nullable=True),
|
49
|
+
sa.Column("is_user", sa.Boolean(), nullable=False),
|
50
|
+
sa.Column(
|
51
|
+
"affiliation",
|
52
|
+
sa.Enum("outcast", "member", "admin", "owner", "none", native_enum=False),
|
53
|
+
nullable=False,
|
54
|
+
),
|
55
|
+
sa.Column(
|
56
|
+
"role",
|
57
|
+
sa.Enum("moderator", "participant", "visitor", "none", native_enum=False),
|
58
|
+
nullable=False,
|
59
|
+
),
|
60
|
+
sa.Column("presence_sent", sa.Boolean(), nullable=False),
|
61
|
+
sa.Column("resource", sa.String(), nullable=True),
|
62
|
+
sa.Column("nickname", sa.String(), nullable=True),
|
63
|
+
sa.Column("extra_attributes", slidge.db.meta.JSONEncodedDict(), nullable=True),
|
64
|
+
sa.ForeignKeyConstraint(
|
65
|
+
["contact_id"],
|
66
|
+
["contact.id"],
|
67
|
+
),
|
68
|
+
sa.ForeignKeyConstraint(
|
69
|
+
["room_id"],
|
70
|
+
["room.id"],
|
71
|
+
),
|
72
|
+
sa.PrimaryKeyConstraint("id"),
|
73
|
+
)
|
74
|
+
op.create_table(
|
75
|
+
"participant_hats",
|
76
|
+
sa.Column("participant_id", sa.Integer(), nullable=False),
|
77
|
+
sa.Column("hat_id", sa.Integer(), nullable=False),
|
78
|
+
sa.ForeignKeyConstraint(
|
79
|
+
["hat_id"],
|
80
|
+
["hat.id"],
|
81
|
+
),
|
82
|
+
sa.ForeignKeyConstraint(
|
83
|
+
["participant_id"],
|
84
|
+
["participant.id"],
|
85
|
+
),
|
86
|
+
sa.PrimaryKeyConstraint("participant_id", "hat_id"),
|
87
|
+
)
|
88
|
+
op.add_column("contact", sa.Column("is_friend", sa.Boolean(), nullable=False))
|
89
|
+
op.add_column("contact", sa.Column("added_to_roster", sa.Boolean(), nullable=False))
|
90
|
+
op.add_column(
|
91
|
+
"contact",
|
92
|
+
sa.Column("extra_attributes", slidge.db.meta.JSONEncodedDict(), nullable=True),
|
93
|
+
)
|
94
|
+
op.add_column("contact", sa.Column("updated", sa.Boolean(), nullable=False))
|
95
|
+
op.add_column("room", sa.Column("description", sa.String(), nullable=True))
|
96
|
+
op.add_column("room", sa.Column("subject", sa.String(), nullable=True))
|
97
|
+
op.add_column("room", sa.Column("subject_date", sa.DateTime(), nullable=True))
|
98
|
+
|
99
|
+
if op.get_bind().engine.name == "postgresql":
|
100
|
+
op.execute(
|
101
|
+
"CREATE TYPE muctype AS ENUM ('GROUP', 'CHANNEL', 'CHANNEL_NON_ANONYMOUS')"
|
102
|
+
)
|
103
|
+
|
104
|
+
op.add_column(
|
105
|
+
"room",
|
106
|
+
sa.Column(
|
107
|
+
"muc_type",
|
108
|
+
sa.Enum("GROUP", "CHANNEL", "CHANNEL_NON_ANONYMOUS", name="muctype"),
|
109
|
+
nullable=True,
|
110
|
+
),
|
111
|
+
)
|
112
|
+
op.add_column("room", sa.Column("user_resources", sa.String(), nullable=True))
|
113
|
+
op.add_column(
|
114
|
+
"room", sa.Column("participants_filled", sa.Boolean(), nullable=False)
|
115
|
+
)
|
116
|
+
op.add_column(
|
117
|
+
"room",
|
118
|
+
sa.Column("extra_attributes", slidge.db.meta.JSONEncodedDict(), nullable=True),
|
119
|
+
)
|
120
|
+
op.add_column("room", sa.Column("updated", sa.Boolean(), nullable=False))
|
121
|
+
|
122
|
+
|
123
|
+
def downgrade() -> None:
|
124
|
+
op.drop_column("room", "updated")
|
125
|
+
op.drop_column("room", "extra_attributes")
|
126
|
+
op.drop_column("room", "participants_filled")
|
127
|
+
op.drop_column("room", "user_resources")
|
128
|
+
op.drop_column("room", "muc_type")
|
129
|
+
op.drop_column("room", "subject_date")
|
130
|
+
op.drop_column("room", "subject")
|
131
|
+
op.drop_column("room", "description")
|
132
|
+
op.drop_column("contact", "updated")
|
133
|
+
op.drop_column("contact", "extra_attributes")
|
134
|
+
op.drop_column("contact", "added_to_roster")
|
135
|
+
op.drop_column("contact", "is_friend")
|
136
|
+
op.drop_table("participant_hats")
|
137
|
+
op.drop_table("participant")
|
138
|
+
op.drop_table("contact_sent")
|
139
|
+
op.drop_table("hat")
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"""DB Creation
|
2
|
+
|
3
|
+
Including a migration from the user_store shelf
|
4
|
+
|
5
|
+
Revision ID: aa9d82a7f6ef
|
6
|
+
Revises:
|
7
|
+
Create Date: 2024-04-17 20:57:01.357041
|
8
|
+
|
9
|
+
"""
|
10
|
+
|
11
|
+
import logging
|
12
|
+
from datetime import datetime
|
13
|
+
from typing import Sequence, Union
|
14
|
+
|
15
|
+
import sqlalchemy as sa
|
16
|
+
from alembic import op
|
17
|
+
|
18
|
+
import slidge.db.meta
|
19
|
+
|
20
|
+
# revision identifiers, used by Alembic.
|
21
|
+
revision: str = "aa9d82a7f6ef"
|
22
|
+
down_revision: Union[str, None] = None
|
23
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
24
|
+
depends_on: Union[str, Sequence[str], None] = None
|
25
|
+
|
26
|
+
|
27
|
+
def upgrade() -> None:
|
28
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
29
|
+
accounts = op.create_table(
|
30
|
+
"user_account",
|
31
|
+
sa.Column("id", sa.Integer(), nullable=False),
|
32
|
+
sa.Column("jid", slidge.db.meta.JIDType(), nullable=False),
|
33
|
+
sa.Column(
|
34
|
+
"registration_date",
|
35
|
+
sa.DateTime(),
|
36
|
+
server_default=sa.text("(CURRENT_TIMESTAMP)"),
|
37
|
+
nullable=False,
|
38
|
+
),
|
39
|
+
sa.Column(
|
40
|
+
"legacy_module_data", slidge.db.meta.JSONEncodedDict(), nullable=False
|
41
|
+
),
|
42
|
+
sa.Column("preferences", slidge.db.meta.JSONEncodedDict(), nullable=False),
|
43
|
+
sa.PrimaryKeyConstraint("id"),
|
44
|
+
sa.UniqueConstraint("jid"),
|
45
|
+
)
|
46
|
+
# ### end Alembic commands ###
|
47
|
+
try:
|
48
|
+
migrate_from_shelf(accounts)
|
49
|
+
except Exception:
|
50
|
+
downgrade()
|
51
|
+
raise
|
52
|
+
|
53
|
+
|
54
|
+
def downgrade() -> None:
|
55
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
56
|
+
op.drop_table("user_account")
|
57
|
+
# ### end Alembic commands ###
|
58
|
+
|
59
|
+
|
60
|
+
def migrate_from_shelf(accounts: sa.Table) -> None:
|
61
|
+
from slidge import global_config
|
62
|
+
|
63
|
+
home = getattr(global_config, "HOME_DIR", None)
|
64
|
+
if home is None:
|
65
|
+
return
|
66
|
+
|
67
|
+
db_file = home / "slidge.db"
|
68
|
+
if not db_file.exists():
|
69
|
+
return
|
70
|
+
|
71
|
+
try:
|
72
|
+
from slidge.db.alembic.old_user_store import user_store
|
73
|
+
except ImportError:
|
74
|
+
return
|
75
|
+
|
76
|
+
user_store.set_file(db_file, global_config.SECRET_KEY)
|
77
|
+
|
78
|
+
try:
|
79
|
+
users = list(user_store.get_all())
|
80
|
+
except AttributeError:
|
81
|
+
return
|
82
|
+
logging.info("Migrating %s users from the deprecated user_store shelf", len(users))
|
83
|
+
op.bulk_insert(
|
84
|
+
accounts,
|
85
|
+
[
|
86
|
+
{
|
87
|
+
"jid": user.jid,
|
88
|
+
"registration_date": (
|
89
|
+
user.registration_date
|
90
|
+
if user.registration_date is not None
|
91
|
+
else datetime.now()
|
92
|
+
),
|
93
|
+
"legacy_module_data": user.registration_form,
|
94
|
+
"preferences": {},
|
95
|
+
}
|
96
|
+
for user in users
|
97
|
+
],
|
98
|
+
)
|
99
|
+
|
100
|
+
user_store.close()
|
101
|
+
db_file.unlink()
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"""Store avatar legacy ID in the Contact and Room table
|
2
|
+
|
3
|
+
Revision ID: abba1ae0edb3
|
4
|
+
Revises: 8b993243a536
|
5
|
+
Create Date: 2024-07-29 15:44:41.557388
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
from alembic import op
|
13
|
+
|
14
|
+
from slidge.db.models import Contact, Room
|
15
|
+
|
16
|
+
# revision identifiers, used by Alembic.
|
17
|
+
revision: str = "abba1ae0edb3"
|
18
|
+
down_revision: Union[str, None] = "8b993243a536"
|
19
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
20
|
+
depends_on: Union[str, Sequence[str], None] = None
|
21
|
+
|
22
|
+
|
23
|
+
def upgrade() -> None:
|
24
|
+
conn = op.get_bind()
|
25
|
+
room_avatars = conn.execute(
|
26
|
+
sa.text(
|
27
|
+
"select room.id, avatar.legacy_id from room join avatar on room.avatar_id = avatar.id"
|
28
|
+
)
|
29
|
+
).all()
|
30
|
+
contact_avatars = conn.execute(
|
31
|
+
sa.text(
|
32
|
+
"select contact.id, avatar.legacy_id from contact join avatar on contact.avatar_id = avatar.id"
|
33
|
+
)
|
34
|
+
).all()
|
35
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
36
|
+
batch_op.add_column(sa.Column("avatar_legacy_id", sa.String(), nullable=True))
|
37
|
+
|
38
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
39
|
+
batch_op.add_column(sa.Column("avatar_legacy_id", sa.String(), nullable=True))
|
40
|
+
if op.get_bind().engine.name != "postgresql":
|
41
|
+
batch_op.create_unique_constraint(
|
42
|
+
"uq_room_user_account_id_jid", ["user_account_id", "jid"]
|
43
|
+
)
|
44
|
+
batch_op.create_unique_constraint(
|
45
|
+
"uq_room_user_account_id_legacy_id", ["user_account_id", "legacy_id"]
|
46
|
+
)
|
47
|
+
|
48
|
+
for room_pk, avatar_legacy_id in room_avatars:
|
49
|
+
conn.execute(
|
50
|
+
sa.update(Room)
|
51
|
+
.where(Room.id == room_pk)
|
52
|
+
.values(avatar_legacy_id=avatar_legacy_id)
|
53
|
+
)
|
54
|
+
for contact_pk, avatar_legacy_id in contact_avatars:
|
55
|
+
conn.execute(
|
56
|
+
sa.update(Contact)
|
57
|
+
.where(Contact.id == contact_pk)
|
58
|
+
.values(avatar_legacy_id=avatar_legacy_id)
|
59
|
+
)
|
60
|
+
# conn.commit()
|
61
|
+
|
62
|
+
with op.batch_alter_table("avatar", schema=None) as batch_op:
|
63
|
+
batch_op.drop_column("legacy_id")
|
64
|
+
|
65
|
+
|
66
|
+
def downgrade() -> None:
|
67
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
68
|
+
with op.batch_alter_table("room", schema=None) as batch_op:
|
69
|
+
batch_op.drop_constraint("uq_room_user_account_id_legacy_id", type_="unique")
|
70
|
+
batch_op.drop_constraint("uq_room_user_account_id_jid", type_="unique")
|
71
|
+
batch_op.drop_column("avatar_legacy_id")
|
72
|
+
|
73
|
+
with op.batch_alter_table("contact", schema=None) as batch_op:
|
74
|
+
batch_op.drop_column("avatar_legacy_id")
|
75
|
+
|
76
|
+
with op.batch_alter_table("avatar", schema=None) as batch_op:
|
77
|
+
batch_op.add_column(sa.Column("legacy_id", sa.VARCHAR(), nullable=True))
|
78
|
+
|
79
|
+
# ### end Alembic commands ###
|