slidge 0.3.0a3__py3-none-any.whl → 0.3.0b2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. slidge/contact/contact.py +2 -2
  2. slidge/contact/roster.py +2 -0
  3. slidge/core/dispatcher/message/message.py +3 -1
  4. slidge/core/dispatcher/presence.py +5 -0
  5. slidge/core/gateway.py +1 -1
  6. slidge/core/mixins/attachment.py +31 -0
  7. slidge/core/mixins/avatar.py +8 -13
  8. slidge/core/session.py +7 -3
  9. slidge/db/alembic/versions/cef02a8b1451_initial_schema.py +361 -0
  10. slidge/group/participant.py +1 -1
  11. slidge/group/room.py +52 -53
  12. slidge/main.py +6 -4
  13. slidge/migration.py +14 -5
  14. slidge/util/conf.py +4 -1
  15. {slidge-0.3.0a3.dist-info → slidge-0.3.0b2.dist-info}/METADATA +1 -1
  16. {slidge-0.3.0a3.dist-info → slidge-0.3.0b2.dist-info}/RECORD +20 -43
  17. slidge/db/alembic/versions/0337c90c0b96_unify_legacy_xmpp_id_mappings.py +0 -183
  18. slidge/db/alembic/versions/04cf35e3cf85_add_participant_nickname_no_illegal.py +0 -33
  19. slidge/db/alembic/versions/09f27f098baa_add_missing_attributes_in_room.py +0 -36
  20. slidge/db/alembic/versions/15b0bd83407a_remove_bogus_unique_constraints_on_room_.py +0 -85
  21. slidge/db/alembic/versions/2461390c0af2_store_contacts_caps_verstring_in_db.py +0 -36
  22. slidge/db/alembic/versions/29f5280c61aa_store_subject_setter_in_room.py +0 -37
  23. slidge/db/alembic/versions/2b1f45ab7379_store_room_subject_setter_by_nickname.py +0 -41
  24. slidge/db/alembic/versions/3071e0fa69d4_add_contact_client_type.py +0 -52
  25. slidge/db/alembic/versions/3231d2c623bc_add_unique_contraint_for_attachment_.py +0 -33
  26. slidge/db/alembic/versions/45c24cc73c91_add_bob.py +0 -42
  27. slidge/db/alembic/versions/4dbd23a3f868_new_avatar_store.py +0 -105
  28. slidge/db/alembic/versions/54ce3cde350c_use_hash_for_avatar_filenames.py +0 -50
  29. slidge/db/alembic/versions/58b98dacf819_refactor.py +0 -118
  30. slidge/db/alembic/versions/5bd48bfdffa2_lift_room_legacy_id_constraint.py +0 -61
  31. slidge/db/alembic/versions/75a62b74b239_ditch_hats_table.py +0 -74
  32. slidge/db/alembic/versions/82a4af84b679_add_muc_history_filled.py +0 -48
  33. slidge/db/alembic/versions/8b993243a536_add_vcard_content_to_contact_table.py +0 -43
  34. slidge/db/alembic/versions/8d2ced764698_rely_on_db_to_store_contacts_rooms_and_.py +0 -139
  35. slidge/db/alembic/versions/aa9d82a7f6ef_db_creation.py +0 -50
  36. slidge/db/alembic/versions/abba1ae0edb3_store_avatar_legacy_id_in_the_contact_.py +0 -79
  37. slidge/db/alembic/versions/b33993e87db3_move_everything_to_persistent_db.py +0 -214
  38. slidge/db/alembic/versions/b64b1a793483_add_source_and_legacy_id_for_archived_.py +0 -52
  39. slidge/db/alembic/versions/c4a8ec35a0e8_per_room_user_nick.py +0 -34
  40. slidge/db/alembic/versions/e91195719c2c_store_users_avatars_persistently.py +0 -26
  41. {slidge-0.3.0a3.dist-info → slidge-0.3.0b2.dist-info}/WHEEL +0 -0
  42. {slidge-0.3.0a3.dist-info → slidge-0.3.0b2.dist-info}/entry_points.txt +0 -0
  43. {slidge-0.3.0a3.dist-info → slidge-0.3.0b2.dist-info}/licenses/LICENSE +0 -0
  44. {slidge-0.3.0a3.dist-info → slidge-0.3.0b2.dist-info}/top_level.txt +0 -0
@@ -1,85 +0,0 @@
1
- """Remove bogus unique constraints on room table
2
-
3
- Revision ID: 15b0bd83407a
4
- Revises: 45c24cc73c91
5
- Create Date: 2024-08-28 06:57:25.022994
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 = "15b0bd83407a"
18
- down_revision: Union[str, None] = "45c24cc73c91"
19
- branch_labels: Union[str, Sequence[str], None] = None
20
- depends_on: Union[str, Sequence[str], None] = None
21
-
22
- meta = sa.MetaData()
23
- room_table = sa.Table(
24
- "room",
25
- meta,
26
- sa.Column("id", sa.Integer(), nullable=False),
27
- sa.Column("user_account_id", sa.Integer(), nullable=False),
28
- sa.Column("legacy_id", sa.String(), nullable=False),
29
- sa.Column("jid", slidge.db.meta.JIDType(), nullable=False),
30
- sa.Column("avatar_id", sa.Integer(), nullable=True),
31
- sa.Column("name", sa.String(), nullable=True),
32
- sa.Column("description", sa.String(), nullable=True),
33
- sa.Column("subject", sa.String(), nullable=True),
34
- sa.Column("subject_date", sa.DateTime(), nullable=True),
35
- sa.Column("subject_setter", sa.String(), nullable=True),
36
- sa.Column("n_participants", sa.Integer(), nullable=True),
37
- sa.Column(
38
- "muc_type",
39
- sa.Enum("GROUP", "CHANNEL", "CHANNEL_NON_ANONYMOUS", name="muctype"),
40
- nullable=True,
41
- ),
42
- sa.Column("user_nick", sa.String(), nullable=True),
43
- sa.Column("user_resources", sa.String(), nullable=True),
44
- sa.Column("participants_filled", sa.Boolean(), nullable=False),
45
- sa.Column("history_filled", sa.Boolean(), nullable=False),
46
- sa.Column("extra_attributes", slidge.db.meta.JSONEncodedDict(), nullable=True),
47
- sa.Column("updated", sa.Boolean(), nullable=False),
48
- sa.Column("avatar_legacy_id", sa.String(), nullable=True),
49
- sa.ForeignKeyConstraint(
50
- ["avatar_id"],
51
- ["avatar.id"],
52
- ),
53
- sa.ForeignKeyConstraint(
54
- ["user_account_id"],
55
- ["user_account.id"],
56
- ),
57
- sa.PrimaryKeyConstraint("id"),
58
- )
59
-
60
-
61
- def upgrade() -> None:
62
- if op.get_bind().engine.name == "postgresql":
63
- return
64
- with op.batch_alter_table(
65
- "room",
66
- schema=None,
67
- # without copy_from, the newly created table keeps the constraints
68
- # we actually want to ditch.
69
- copy_from=room_table,
70
- ) as batch_op:
71
- batch_op.create_unique_constraint(
72
- "uq_room_user_account_id_jid", ["user_account_id", "jid"]
73
- )
74
- batch_op.create_unique_constraint(
75
- "uq_room_user_account_id_legacy_id", ["user_account_id", "legacy_id"]
76
- )
77
-
78
-
79
- def downgrade() -> None:
80
- # ### commands auto generated by Alembic - please adjust! ###
81
- with op.batch_alter_table("room", schema=None) as batch_op:
82
- batch_op.drop_constraint("uq_room_user_account_id_legacy_id", type_="unique")
83
- batch_op.drop_constraint("uq_room_user_account_id_jid", type_="unique")
84
-
85
- # ### end Alembic commands ###
@@ -1,36 +0,0 @@
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 ###
@@ -1,37 +0,0 @@
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")
@@ -1,41 +0,0 @@
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 ###
@@ -1,52 +0,0 @@
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 ###
@@ -1,33 +0,0 @@
1
- """Add unique contraint for attachment user/file_id
2
-
3
- Revision ID: 3231d2c623bc
4
- Revises: 75a62b74b239
5
- Create Date: 2025-05-14 06:08:15.425495
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 = "3231d2c623bc"
16
- down_revision: Union[str, None] = "75a62b74b239"
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("attachment", schema=None) as batch_op:
23
- batch_op.create_unique_constraint(
24
- batch_op.f("uq_attachment_user_account_id"),
25
- ["user_account_id", "legacy_file_id"],
26
- )
27
-
28
-
29
- def downgrade() -> None:
30
- with op.batch_alter_table("attachment", schema=None) as batch_op:
31
- batch_op.drop_constraint(
32
- batch_op.f("uq_attachment_user_account_id"), type_="unique"
33
- )
@@ -1,42 +0,0 @@
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 ###
@@ -1,105 +0,0 @@
1
- """New avatar store
2
-
3
- Revision ID: 4dbd23a3f868
4
- Revises: 04cf35e3cf85
5
- Create Date: 2025-04-14 21:57:49.030430
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 = "4dbd23a3f868"
16
- down_revision: Union[str, None] = "04cf35e3cf85"
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
- # a bug in slidge v0.3.0alpha0 lead to a crash during this migration which ended up with
23
- # this temporary tables in here
24
- op.execute("DROP TABLE IF EXISTS _alembic_tmp_avatar;")
25
- op.execute("DROP TABLE IF EXISTS _alembic_tmp_contact;")
26
-
27
- with op.batch_alter_table("avatar", schema=None) as batch_op:
28
- batch_op.add_column(sa.Column("legacy_id", sa.String(), nullable=True))
29
- batch_op.create_unique_constraint("avatar_unique_legacy_id", ["legacy_id"])
30
-
31
- batch_op.execute("""
32
- UPDATE avatar
33
- SET legacy_id = contact.avatar_legacy_id
34
- FROM contact
35
- WHERE avatar.id = contact.avatar_id
36
- """)
37
-
38
- batch_op.execute("""
39
- UPDATE avatar
40
- SET legacy_id = room.avatar_legacy_id
41
- FROM room
42
- WHERE avatar.id = room.avatar_id
43
- """)
44
-
45
- # the following 4 OPs have been added manually because somewhere before, we messed up
46
- # and the client_type server side default value was pc (no quote) instead of "pc"
47
- op.execute(
48
- """
49
- CREATE TABLE contact_new (
50
- id INTEGER NOT NULL,
51
- user_account_id INTEGER NOT NULL,
52
- legacy_id VARCHAR NOT NULL,
53
- jid TEXT NOT NULL,
54
- avatar_id INTEGER,
55
- nick VARCHAR,
56
- cached_presence BOOLEAN NOT NULL,
57
- last_seen DATETIME,
58
- ptype VARCHAR,
59
- pstatus VARCHAR,
60
- pshow VARCHAR,
61
- is_friend BOOLEAN NOT NULL,
62
- added_to_roster BOOLEAN NOT NULL,
63
- extra_attributes VARCHAR,
64
- updated BOOLEAN NOT NULL,
65
- caps_ver VARCHAR,
66
- vcard VARCHAR,
67
- vcard_fetched BOOLEAN DEFAULT 1 NOT NULL,
68
- avatar_legacy_id VARCHAR,
69
- client_type VARCHAR(8) DEFAULT 'pc' NOT NULL,
70
- PRIMARY KEY (id),
71
- FOREIGN KEY(user_account_id) REFERENCES user_account (id),
72
- FOREIGN KEY(avatar_id) REFERENCES avatar (id),
73
- UNIQUE (user_account_id, legacy_id) CONSTRAINT uq_user_account_legacy_id,
74
- UNIQUE (user_account_id, jid) CONSTRAINT uq_user_account_jid
75
- );
76
- """
77
- )
78
-
79
- op.execute(
80
- """
81
- INSERT INTO contact_new (id, user_account_id, legacy_id, jid, avatar_id, nick, cached_presence, last_seen, ptype, pstatus, pshow, is_friend, added_to_roster, extra_attributes, updated, caps_ver, vcard, vcard_fetched, avatar_legacy_id, client_type)
82
- SELECT id, user_account_id, legacy_id, jid, avatar_id, nick, cached_presence, last_seen, ptype, pstatus, pshow, is_friend, added_to_roster, extra_attributes, updated, caps_ver, vcard, vcard_fetched, avatar_legacy_id, client_type
83
- FROM contact;
84
- """
85
- )
86
- op.execute("DROP TABLE contact;")
87
- op.execute("ALTER TABLE contact_new RENAME TO contact;")
88
-
89
- with op.batch_alter_table("contact", schema=None) as batch_op:
90
- batch_op.drop_column("avatar_legacy_id")
91
-
92
- with op.batch_alter_table("room", schema=None) as batch_op:
93
- batch_op.drop_column("avatar_legacy_id")
94
-
95
-
96
- def downgrade() -> None:
97
- with op.batch_alter_table("room", schema=None) as batch_op:
98
- batch_op.add_column(sa.Column("avatar_legacy_id", sa.VARCHAR(), nullable=True))
99
-
100
- with op.batch_alter_table("contact", schema=None) as batch_op:
101
- batch_op.add_column(sa.Column("avatar_legacy_id", sa.VARCHAR(), nullable=True))
102
-
103
- with op.batch_alter_table("avatar", schema=None) as batch_op:
104
- batch_op.drop_constraint("avatar_unique_legacy_id", type_="unique")
105
- batch_op.drop_column("legacy_id")
@@ -1,50 +0,0 @@
1
- """Use hash for avatar filenames
2
-
3
- Revision ID: 54ce3cde350c
4
- Revises: 4dbd23a3f868
5
- Create Date: 2025-04-14 23:52:38.520744
6
-
7
- """
8
-
9
- from pathlib import Path
10
- from typing import Sequence, Union
11
-
12
- import sqlalchemy as sa
13
- from alembic import op
14
-
15
- # revision identifiers, used by Alembic.
16
- revision: str = "54ce3cde350c"
17
- down_revision: Union[str, None] = "4dbd23a3f868"
18
- branch_labels: Union[str, Sequence[str], None] = None
19
- depends_on: Union[str, Sequence[str], None] = None
20
-
21
-
22
- def upgrade() -> None:
23
- from slidge.core import config
24
-
25
- try:
26
- avatars_root = config.HOME_DIR / "slidge_avatars_v3"
27
- except AttributeError:
28
- avatars_root = Path(".")
29
-
30
- connection = op.get_bind()
31
- avatars = connection.execute(sa.text("SELECT id, filename, hash FROM avatar"))
32
- for avatar in avatars:
33
- filename = avatar[1]
34
- hash_value = avatar[2]
35
- if filename and hash_value:
36
- old_file_path = avatars_root / filename
37
- new_file_path = (avatars_root / hash_value).with_suffix(".png")
38
- if old_file_path.exists():
39
- old_file_path.rename(new_file_path)
40
-
41
- with op.batch_alter_table("avatar", schema=None) as batch_op:
42
- batch_op.drop_column("filename")
43
-
44
-
45
- def downgrade() -> None:
46
- # ### commands auto generated by Alembic - please adjust! ###
47
- with op.batch_alter_table("avatar", schema=None) as batch_op:
48
- batch_op.add_column(sa.Column("filename", sa.VARCHAR(), nullable=False))
49
-
50
- # ### end Alembic commands ###
@@ -1,118 +0,0 @@
1
- """Add unique constraints that we should have added before
2
-
3
- Revision ID: 58b98dacf819
4
- Revises: 54ce3cde350c
5
- Create Date: 2025-04-23 22:55:11.731158
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 = "58b98dacf819"
16
- down_revision: Union[str, None] = "54ce3cde350c"
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("avatar", schema=None) as batch_op:
24
- batch_op.drop_constraint("avatar_unique_legacy_id", type_="unique")
25
- batch_op.create_unique_constraint(batch_op.f("uq_avatar_hash"), ["hash"])
26
- batch_op.create_unique_constraint(
27
- batch_op.f("uq_avatar_legacy_id"), ["legacy_id"]
28
- )
29
-
30
- with op.batch_alter_table("bob", schema=None) as batch_op:
31
- batch_op.create_unique_constraint(batch_op.f("uq_bob_sha_1"), ["sha_1"])
32
- batch_op.create_unique_constraint(batch_op.f("uq_bob_sha_256"), ["sha_256"])
33
- batch_op.create_unique_constraint(batch_op.f("uq_bob_sha_512"), ["sha_512"])
34
-
35
- with op.batch_alter_table("contact", schema=None) as batch_op:
36
- batch_op.create_unique_constraint(
37
- batch_op.f("uq_contact_user_account_id"), ["user_account_id", "legacy_id"]
38
- )
39
-
40
- with op.batch_alter_table("contact_sent", schema=None) as batch_op:
41
- batch_op.create_unique_constraint(
42
- batch_op.f("uq_contact_sent_contact_id"), ["contact_id", "msg_id"]
43
- )
44
-
45
- with op.batch_alter_table("hat", schema=None) as batch_op:
46
- batch_op.create_unique_constraint(batch_op.f("uq_hat_title"), ["title", "uri"])
47
-
48
- with op.batch_alter_table("mam", schema=None) as batch_op:
49
- batch_op.create_unique_constraint(
50
- batch_op.f("uq_mam_room_id"), ["room_id", "stanza_id"]
51
- )
52
-
53
- with op.batch_alter_table("participant", schema=None) as batch_op:
54
- batch_op.alter_column("resource", existing_type=sa.VARCHAR(), nullable=False)
55
- batch_op.alter_column("nickname", existing_type=sa.VARCHAR(), nullable=False)
56
- batch_op.alter_column(
57
- "nickname_no_illegal", existing_type=sa.VARCHAR(), nullable=False
58
- )
59
- batch_op.create_unique_constraint(
60
- batch_op.f("uq_participant_room_id"), ["room_id", "resource"]
61
- )
62
-
63
- with op.batch_alter_table("room", schema=None) as batch_op:
64
- batch_op.alter_column(
65
- "muc_type", existing_type=sa.VARCHAR(length=21), nullable=False
66
- )
67
-
68
- with op.batch_alter_table("user_account", schema=None) as batch_op:
69
- batch_op.create_unique_constraint(batch_op.f("uq_user_account_jid"), ["jid"])
70
-
71
- # ### end Alembic commands ###
72
-
73
-
74
- def downgrade() -> None:
75
- # ### commands auto generated by Alembic - please adjust! ###
76
- with op.batch_alter_table("user_account", schema=None) as batch_op:
77
- batch_op.drop_constraint(batch_op.f("uq_user_account_jid"), type_="unique")
78
-
79
- with op.batch_alter_table("room", schema=None) as batch_op:
80
- batch_op.alter_column(
81
- "muc_type", existing_type=sa.VARCHAR(length=21), nullable=True
82
- )
83
-
84
- with op.batch_alter_table("participant", schema=None) as batch_op:
85
- batch_op.drop_constraint(batch_op.f("uq_participant_room_id"), type_="unique")
86
- batch_op.alter_column(
87
- "nickname_no_illegal", existing_type=sa.VARCHAR(), nullable=True
88
- )
89
- batch_op.alter_column("nickname", existing_type=sa.VARCHAR(), nullable=True)
90
- batch_op.alter_column("resource", existing_type=sa.VARCHAR(), nullable=True)
91
-
92
- with op.batch_alter_table("mam", schema=None) as batch_op:
93
- batch_op.drop_constraint(batch_op.f("uq_mam_room_id"), type_="unique")
94
-
95
- with op.batch_alter_table("hat", schema=None) as batch_op:
96
- batch_op.drop_constraint(batch_op.f("uq_hat_title"), type_="unique")
97
-
98
- with op.batch_alter_table("contact_sent", schema=None) as batch_op:
99
- batch_op.drop_constraint(
100
- batch_op.f("uq_contact_sent_contact_id"), type_="unique"
101
- )
102
-
103
- with op.batch_alter_table("contact", schema=None) as batch_op:
104
- batch_op.drop_constraint(
105
- batch_op.f("uq_contact_user_account_id"), type_="unique"
106
- )
107
-
108
- with op.batch_alter_table("bob", schema=None) as batch_op:
109
- batch_op.drop_constraint(batch_op.f("uq_bob_sha_512"), type_="unique")
110
- batch_op.drop_constraint(batch_op.f("uq_bob_sha_256"), type_="unique")
111
- batch_op.drop_constraint(batch_op.f("uq_bob_sha_1"), type_="unique")
112
-
113
- with op.batch_alter_table("avatar", schema=None) as batch_op:
114
- batch_op.drop_constraint(batch_op.f("uq_avatar_legacy_id"), type_="unique")
115
- batch_op.drop_constraint(batch_op.f("uq_avatar_hash"), type_="unique")
116
- batch_op.create_unique_constraint("avatar_unique_legacy_id", ["legacy_id"])
117
-
118
- # ### end Alembic commands ###
@@ -1,61 +0,0 @@
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__)