core-framework 0.3.0__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 (222) hide show
  1. core_framework/__init__.py +0 -0
  2. core_framework/alembic/comment/alembic/README +1 -0
  3. core_framework/alembic/comment/alembic/env.py +72 -0
  4. core_framework/alembic/comment/alembic/script.py.mako +28 -0
  5. core_framework/alembic/comment/alembic/versions/30334fd1347b_init.py +59 -0
  6. core_framework/alembic/comment/alembic/versions/a2b3c4d5e6f7_improve_comment_indexes.py +54 -0
  7. core_framework/alembic/comment/alembic/versions/bcc8e00cfc8b_add_extra_tables.py +64 -0
  8. core_framework/alembic/comment/alembic/versions/d1e2f3a4b5c6_add_comment_stats_dirty_table.py +29 -0
  9. core_framework/alembic/comment/alembic/versions/e3f4a5b6c7d8_cascade_delete_comment_descendants.py +49 -0
  10. core_framework/alembic/comment/alembic/versions/f7e6d5c4b3a2_comments_path_to_ltree.py +60 -0
  11. core_framework/alembic/comment/alembic.ini +52 -0
  12. core_framework/alembic/extension/alembic/README +1 -0
  13. core_framework/alembic/extension/alembic/env.py +98 -0
  14. core_framework/alembic/extension/alembic/script.py.mako +28 -0
  15. core_framework/alembic/extension/alembic/versions/0389226049cb_add_pg_trgm_extension.py +25 -0
  16. core_framework/alembic/extension/alembic/versions/5dc58b016cf5_add_citext_extension.py +25 -0
  17. core_framework/alembic/extension/alembic/versions/b0ba0d8a284e_add_pg_stat_statements_extension.py +25 -0
  18. core_framework/alembic/extension/alembic/versions/c9d0e1f2a3b4_add_ltree_extension.py +25 -0
  19. core_framework/alembic/extension/alembic.ini +147 -0
  20. core_framework/alembic/moderation/alembic/README +1 -0
  21. core_framework/alembic/moderation/alembic/env.py +98 -0
  22. core_framework/alembic/moderation/alembic/script.py.mako +28 -0
  23. core_framework/alembic/moderation/alembic/versions/085ba9021850_add_category_to_user_restrictions.py +93 -0
  24. core_framework/alembic/moderation/alembic/versions/5f9e4fc14a41_create_moderation_appeals_table.py +69 -0
  25. core_framework/alembic/moderation/alembic/versions/63e37381e73b_add_user_reports_table.py +33 -0
  26. core_framework/alembic/moderation/alembic/versions/6a2ae31b7ac6_add_moderation_actions_table.py +34 -0
  27. core_framework/alembic/moderation/alembic/versions/716aa1735c03_improve_indexes.py +36 -0
  28. core_framework/alembic/moderation/alembic/versions/7d243ddbfde1_add_post_reports_table.py +35 -0
  29. core_framework/alembic/moderation/alembic/versions/8fba1f72dd46_add_indexes.py +64 -0
  30. core_framework/alembic/moderation/alembic/versions/95cc35a51984_update_restriction_history.py +91 -0
  31. core_framework/alembic/moderation/alembic/versions/9ad79d0af730_add_unique_constraint_user_reports_.py +28 -0
  32. core_framework/alembic/moderation/alembic/versions/a5e569f5df1a_create_user_restrictions_table.py +38 -0
  33. core_framework/alembic/moderation/alembic/versions/b2c3d4e5f6a7_add_indexes.py +42 -0
  34. core_framework/alembic/moderation/alembic/versions/c3d4e5f6a7b8_improve_report_indexes.py +48 -0
  35. core_framework/alembic/moderation/alembic/versions/d4af74643ff5_add_internal_notes_table.py +38 -0
  36. core_framework/alembic/moderation/alembic/versions/db20f2fb7390_add_comment_reports_table.py +35 -0
  37. core_framework/alembic/moderation/alembic/versions/e66226952ea6_add_report_category_to_user_reports_.py +54 -0
  38. core_framework/alembic/moderation/alembic/versions/f5e8cb275c30_enforce_1_pending_appeal.py +29 -0
  39. core_framework/alembic/moderation/alembic/versions/fe1faad2832d_create_restriction_history_table.py +69 -0
  40. core_framework/alembic/moderation/alembic.ini +147 -0
  41. core_framework/alembic/post/alembic/README +1 -0
  42. core_framework/alembic/post/alembic/env.py +97 -0
  43. core_framework/alembic/post/alembic/script.py.mako +28 -0
  44. core_framework/alembic/post/alembic/versions/51542673f5c8_add_tables_for_muted_banned_users.py +41 -0
  45. core_framework/alembic/post/alembic/versions/5beeeae40a4a_add_post_views_table.py +45 -0
  46. core_framework/alembic/post/alembic/versions/620971509a8b_init.py +55 -0
  47. core_framework/alembic/post/alembic/versions/a1b2c3d4e5f6_add_indexes.py +44 -0
  48. core_framework/alembic/post/alembic/versions/c1d2e3f4a5b6_add_post_hashtags_table.py +36 -0
  49. core_framework/alembic/post/alembic/versions/e56723f2afff_add_post_stats_table.py +39 -0
  50. core_framework/alembic/post/alembic/versions/fbc723ac58cc_add_post_likes_table.py +32 -0
  51. core_framework/alembic/post/alembic.ini +149 -0
  52. core_framework/alembic/user/alembic/README +1 -0
  53. core_framework/alembic/user/alembic/env.py +98 -0
  54. core_framework/alembic/user/alembic/script.py.mako +28 -0
  55. core_framework/alembic/user/alembic/versions/1a8bb99726ed_remove_avatar_id_from_users.py +81 -0
  56. core_framework/alembic/user/alembic/versions/2ccacf455941_improve_indexes.py +34 -0
  57. core_framework/alembic/user/alembic/versions/47f47ce2110e_create_user_deletions_table.py +31 -0
  58. core_framework/alembic/user/alembic/versions/5976db3f0175_drop_user_states.py +26 -0
  59. core_framework/alembic/user/alembic/versions/62417002cf32_add_indexes.py +46 -0
  60. core_framework/alembic/user/alembic/versions/6f7ccf3c226b_refactor_user_login_events.py +66 -0
  61. core_framework/alembic/user/alembic/versions/73432817015b_add_user_preferences_table.py +33 -0
  62. core_framework/alembic/user/alembic/versions/765bc01a7a59_create_user_blocks_table.py +33 -0
  63. core_framework/alembic/user/alembic/versions/7a56631f9927_create_user_login_events_table.py +49 -0
  64. core_framework/alembic/user/alembic/versions/831611e589bc_create_user_state.py +31 -0
  65. core_framework/alembic/user/alembic/versions/83c98ab2a779_add_user_profiles_table.py +88 -0
  66. core_framework/alembic/user/alembic/versions/8a94362cad6d_create_user_role.py +31 -0
  67. core_framework/alembic/user/alembic/versions/94b973923895_add_user_change_history_table.py +97 -0
  68. core_framework/alembic/user/alembic/versions/cbc0f4efe84f_add_avatar_id_column_to_users_table.py +31 -0
  69. core_framework/alembic/user/alembic/versions/d8b98ac6b073_add_index_for_get_admin_user_ids_query.py +29 -0
  70. core_framework/alembic/user/alembic/versions/ddb70cc09d16_create_user_states_table.py +34 -0
  71. core_framework/alembic/user/alembic/versions/f9ba10815ecd_add_users_table.py +33 -0
  72. core_framework/alembic/user/alembic.ini +147 -0
  73. core_framework/api/__init__.py +0 -0
  74. core_framework/api/admin/__init__.py +0 -0
  75. core_framework/api/admin/comments/router.py +69 -0
  76. core_framework/api/admin/comments/schemas.py +53 -0
  77. core_framework/api/admin/moderation/__init__.py +0 -0
  78. core_framework/api/admin/moderation/router.py +205 -0
  79. core_framework/api/admin/moderation/schemas.py +110 -0
  80. core_framework/api/admin/posts/router.py +62 -0
  81. core_framework/api/admin/posts/schemas.py +29 -0
  82. core_framework/api/admin/router.py +17 -0
  83. core_framework/api/admin/users/__init__.py +0 -0
  84. core_framework/api/admin/users/router.py +181 -0
  85. core_framework/api/admin/users/schemas.py +137 -0
  86. core_framework/api/auth/__init__.py +0 -0
  87. core_framework/api/auth/router.py +21 -0
  88. core_framework/api/auth/schemas.py +28 -0
  89. core_framework/api/comments/authenticated/router.py +126 -0
  90. core_framework/api/comments/authenticated/schemas.py +27 -0
  91. core_framework/api/comments/public/router.py +103 -0
  92. core_framework/api/comments/public/schemas.py +36 -0
  93. core_framework/api/comments/router.py +9 -0
  94. core_framework/api/comments/schemas.py +17 -0
  95. core_framework/api/dependencies.py +168 -0
  96. core_framework/api/events/router.py +39 -0
  97. core_framework/api/events/schemas.py +20 -0
  98. core_framework/api/posts/authenticated/router.py +83 -0
  99. core_framework/api/posts/authenticated/schemas.py +37 -0
  100. core_framework/api/posts/public/router.py +100 -0
  101. core_framework/api/posts/public/schemas.py +39 -0
  102. core_framework/api/posts/router.py +9 -0
  103. core_framework/api/posts/schemas.py +39 -0
  104. core_framework/api/router.py +19 -0
  105. core_framework/api/schemas.py +9 -0
  106. core_framework/api/system/__init__.py +0 -0
  107. core_framework/api/system/router.py +108 -0
  108. core_framework/api/users/__init__.py +0 -0
  109. core_framework/api/users/authenticated/__init__.py +0 -0
  110. core_framework/api/users/authenticated/router.py +244 -0
  111. core_framework/api/users/authenticated/schemas.py +81 -0
  112. core_framework/api/users/public/__init__.py +0 -0
  113. core_framework/api/users/public/router.py +25 -0
  114. core_framework/api/users/public/schemas.py +7 -0
  115. core_framework/api/users/router.py +9 -0
  116. core_framework/api/users/shared/schemas.py +174 -0
  117. core_framework/application/__init__.py +0 -0
  118. core_framework/application/auth/__init__.py +0 -0
  119. core_framework/application/auth/access_service.py +26 -0
  120. core_framework/application/auth/auth_service.py +10 -0
  121. core_framework/application/auth/models.py +10 -0
  122. core_framework/application/bootstrap.py +19 -0
  123. core_framework/application/comments/admin_service.py +236 -0
  124. core_framework/application/comments/aggregation_service.py +28 -0
  125. core_framework/application/comments/authenticated_service.py +89 -0
  126. core_framework/application/comments/public_service.py +218 -0
  127. core_framework/application/events/README.md +26 -0
  128. core_framework/application/events/event_service.py +51 -0
  129. core_framework/application/events/event_token.py +46 -0
  130. core_framework/application/events/models.py +9 -0
  131. core_framework/application/moderation/__init__.py +0 -0
  132. core_framework/application/moderation/appeal_service.py +98 -0
  133. core_framework/application/moderation/moderator_service.py +46 -0
  134. core_framework/application/moderation/report_service.py +180 -0
  135. core_framework/application/moderation/scheduled_service.py +5 -0
  136. core_framework/application/moderation/user_service.py +180 -0
  137. core_framework/application/posts/admin_service.py +104 -0
  138. core_framework/application/posts/aggregation_service.py +28 -0
  139. core_framework/application/posts/authenticated_service.py +72 -0
  140. core_framework/application/posts/public_service.py +197 -0
  141. core_framework/application/shared/__init__.py +0 -0
  142. core_framework/application/shared/enums.py +16 -0
  143. core_framework/application/shared/exceptions.py +16 -0
  144. core_framework/application/shared/user_agent.py +24 -0
  145. core_framework/application/users/__init__.py +0 -0
  146. core_framework/application/users/admin_service.py +298 -0
  147. core_framework/application/users/authenticated_service.py +179 -0
  148. core_framework/application/users/public_service.py +7 -0
  149. core_framework/application/users/scheduled_service.py +5 -0
  150. core_framework/bundled_alembic.py +57 -0
  151. core_framework/core/__init__.py +37 -0
  152. core_framework/core/cache.py +234 -0
  153. core_framework/core/context.py +14 -0
  154. core_framework/core/database.py +111 -0
  155. core_framework/core/exception_handlers/__init__.py +3 -0
  156. core_framework/core/exception_handlers/comment.py +99 -0
  157. core_framework/core/exception_handlers/common.py +5 -0
  158. core_framework/core/exception_handlers/moderation.py +104 -0
  159. core_framework/core/exception_handlers/post.py +54 -0
  160. core_framework/core/exception_handlers/setup.py +80 -0
  161. core_framework/core/exception_handlers/user.py +72 -0
  162. core_framework/core/http_client.py +64 -0
  163. core_framework/core/logging.py +99 -0
  164. core_framework/core/middleware.py +64 -0
  165. core_framework/core/observability.py +36 -0
  166. core_framework/core/pagination.py +203 -0
  167. core_framework/core/redis.py +135 -0
  168. core_framework/core/runtime.py +66 -0
  169. core_framework/core/settings.py +189 -0
  170. core_framework/domains/__init__.py +0 -0
  171. core_framework/domains/comment/README.md +243 -0
  172. core_framework/domains/comment/__init__.py +25 -0
  173. core_framework/domains/comment/constants.py +3 -0
  174. core_framework/domains/comment/dependencies.py +29 -0
  175. core_framework/domains/comment/enums.py +11 -0
  176. core_framework/domains/comment/exceptions.py +31 -0
  177. core_framework/domains/comment/models.py +54 -0
  178. core_framework/domains/comment/repository.py +947 -0
  179. core_framework/domains/comment/service.py +259 -0
  180. core_framework/domains/moderation/README.md +138 -0
  181. core_framework/domains/moderation/__init__.py +47 -0
  182. core_framework/domains/moderation/dependencies.py +29 -0
  183. core_framework/domains/moderation/enums.py +62 -0
  184. core_framework/domains/moderation/exceptions.py +31 -0
  185. core_framework/domains/moderation/models.py +94 -0
  186. core_framework/domains/moderation/repository.py +828 -0
  187. core_framework/domains/moderation/service.py +334 -0
  188. core_framework/domains/post/README.md +182 -0
  189. core_framework/domains/post/__init__.py +22 -0
  190. core_framework/domains/post/constants.py +3 -0
  191. core_framework/domains/post/dependencies.py +29 -0
  192. core_framework/domains/post/enums.py +18 -0
  193. core_framework/domains/post/exceptions.py +21 -0
  194. core_framework/domains/post/models.py +53 -0
  195. core_framework/domains/post/repository.py +791 -0
  196. core_framework/domains/post/service.py +204 -0
  197. core_framework/domains/user/README.md +74 -0
  198. core_framework/domains/user/__init__.py +39 -0
  199. core_framework/domains/user/constants.py +8 -0
  200. core_framework/domains/user/dependencies.py +29 -0
  201. core_framework/domains/user/enums.py +19 -0
  202. core_framework/domains/user/exceptions.py +31 -0
  203. core_framework/domains/user/models.py +124 -0
  204. core_framework/domains/user/repository.py +612 -0
  205. core_framework/domains/user/service.py +257 -0
  206. core_framework/domains/user/utils.py +182 -0
  207. core_framework/main.py +104 -0
  208. core_framework/worker/__init__.py +0 -0
  209. core_framework/worker/main.py +56 -0
  210. core_framework/worker/schedules/__init__.py +35 -0
  211. core_framework/worker/schedules/schedule_aggregate_comment_stats.py +32 -0
  212. core_framework/worker/schedules/schedule_aggregate_post_view_counts.py +28 -0
  213. core_framework/worker/schedules/schedule_expired_account_deletions.py +24 -0
  214. core_framework/worker/schedules/schedule_expired_mute_lifts.py +24 -0
  215. core_framework/worker/tasks/__init__.py +11 -0
  216. core_framework/worker/tasks/process_account_deletion.py +13 -0
  217. core_framework/worker/tasks/process_aggregate_comment_stats.py +19 -0
  218. core_framework/worker/tasks/process_aggregate_post_stats.py +12 -0
  219. core_framework/worker/tasks/process_mute_lift.py +13 -0
  220. core_framework-0.3.0.dist-info/METADATA +22 -0
  221. core_framework-0.3.0.dist-info/RECORD +222 -0
  222. core_framework-0.3.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,91 @@
1
+ """update restriction_history
2
+
3
+ Revision ID: 95cc35a51984
4
+ Revises: 085ba9021850
5
+ Create Date: 2026-02-07 10:34:42.293915
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "95cc35a51984"
15
+ down_revision: str | Sequence[str] | None = "085ba9021850"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ update moderation.restriction_history
23
+ set restriction_type = 'warned'::moderation.restriction_type
24
+ where restriction_type is null;
25
+ """)
26
+ op.execute("""
27
+ update moderation.restriction_history
28
+ set category = 'other'::moderation.restriction_category
29
+ where category is null;
30
+ """)
31
+ op.execute("""
32
+ update moderation.restriction_history
33
+ set reason = ''
34
+ where reason is null;
35
+ """)
36
+ op.execute("""
37
+ update moderation.user_restrictions
38
+ set reason = ''
39
+ where reason is null;
40
+ """)
41
+ op.execute("""
42
+ alter table moderation.restriction_history
43
+ alter column restriction_type set not null;
44
+ """)
45
+ op.execute("""
46
+ alter table moderation.restriction_history
47
+ alter column category set not null;
48
+ """)
49
+ op.execute("""
50
+ alter table moderation.restriction_history
51
+ alter column reason set default '';
52
+ """)
53
+ op.execute("""
54
+ alter table moderation.restriction_history
55
+ alter column reason set not null;
56
+ """)
57
+ op.execute("""
58
+ alter table moderation.user_restrictions
59
+ alter column reason set default '';
60
+ """)
61
+ op.execute("""
62
+ alter table moderation.user_restrictions
63
+ alter column reason set not null;
64
+ """)
65
+
66
+
67
+ def downgrade() -> None:
68
+ op.execute("""
69
+ alter table moderation.restriction_history
70
+ alter column restriction_type drop not null;
71
+ """)
72
+ op.execute("""
73
+ alter table moderation.restriction_history
74
+ alter column category drop not null;
75
+ """)
76
+ op.execute("""
77
+ alter table moderation.restriction_history
78
+ alter column reason drop not null;
79
+ """)
80
+ op.execute("""
81
+ alter table moderation.restriction_history
82
+ alter column reason drop default;
83
+ """)
84
+ op.execute("""
85
+ alter table moderation.user_restrictions
86
+ alter column reason drop not null;
87
+ """)
88
+ op.execute("""
89
+ alter table moderation.user_restrictions
90
+ alter column reason drop default;
91
+ """)
@@ -0,0 +1,28 @@
1
+ """add_unique_constraint_user_reports_reporter_target
2
+
3
+ Revision ID: 9ad79d0af730
4
+ Revises: 7d243ddbfde1
5
+ Create Date: 2026-03-05 11:02:07.361067
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "9ad79d0af730"
15
+ down_revision: str | Sequence[str] | None = "7d243ddbfde1"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("drop index if exists idx_user_reports_cooldown")
22
+ op.execute("""
23
+ alter table user_reports
24
+ add constraint user_reports_reporter_target_unique unique (reporter_id, target_id)
25
+ """)
26
+
27
+
28
+ def downgrade() -> None: ...
@@ -0,0 +1,38 @@
1
+ """create user_restrictions table
2
+
3
+ Revision ID: a5e569f5df1a
4
+ Revises:
5
+ Create Date: 2026-01-21 06:40:49.987880
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "a5e569f5df1a"
15
+ down_revision: str | Sequence[str] | None = None
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ create type restriction_type as enum ('warned', 'muted', 'banned');
23
+ """)
24
+ op.execute("""
25
+ create table user_restrictions (
26
+ user_id varchar(128) primary key,
27
+ restriction_type restriction_type not null,
28
+ reason text,
29
+ expires_at timestamptz not null default 'infinity',
30
+ created_at timestamptz not null default now(),
31
+ updated_at timestamptz not null default now()
32
+ );
33
+ """)
34
+
35
+
36
+ def downgrade() -> None:
37
+ op.execute("drop table if exists user_restrictions;")
38
+ op.execute("drop type if exists restriction_type;")
@@ -0,0 +1,42 @@
1
+ """add indexes
2
+
3
+ Revision ID: b2c3d4e5f6a7
4
+ Revises: 9ad79d0af730
5
+ Create Date: 2026-03-06 12:00:00.000000
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ revision: str = "b2c3d4e5f6a7"
14
+ down_revision: str | Sequence[str] | None = "9ad79d0af730"
15
+ branch_labels: str | Sequence[str] | None = None
16
+ depends_on: str | Sequence[str] | None = None
17
+
18
+
19
+ def upgrade() -> None:
20
+ op.execute("""
21
+ create index idx_post_reports_target_id
22
+ on post_reports (target_id)
23
+ """)
24
+ op.execute("""
25
+ create index idx_moderation_actions_actor_created
26
+ on moderation_actions (actor_id, created_at desc)
27
+ """)
28
+ op.execute("drop index if exists idx_internal_notes_target_user_id")
29
+ op.execute("""
30
+ create index idx_internal_notes_target_user_created
31
+ on internal_notes (target_user_id, created_at desc)
32
+ """)
33
+
34
+
35
+ def downgrade() -> None:
36
+ op.execute("drop index if exists idx_post_reports_target_id")
37
+ op.execute("drop index if exists idx_moderation_actions_actor_created")
38
+ op.execute("drop index if exists idx_internal_notes_target_user_created")
39
+ op.execute("""
40
+ create index idx_internal_notes_target_user_id
41
+ on internal_notes (target_user_id)
42
+ """)
@@ -0,0 +1,48 @@
1
+ """improve report indexes
2
+
3
+ Revision ID: c3d4e5f6a7b8
4
+ Revises: db20f2fb7390
5
+ Create Date: 2026-03-22 20:00:00.000000
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "c3d4e5f6a7b8"
15
+ down_revision: str | Sequence[str] | None = "db20f2fb7390"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ create index idx_comment_reports_target_id
23
+ on comment_reports (target_id)
24
+ """)
25
+
26
+ op.execute("""
27
+ create index idx_post_reports_created_at
28
+ on post_reports (created_at desc)
29
+ include (id, reporter_id, target_id, category, reason)
30
+ """)
31
+
32
+ op.execute("""
33
+ create index idx_comment_reports_created_at
34
+ on comment_reports (created_at desc)
35
+ include (id, reporter_id, target_id, category, reason)
36
+ """)
37
+
38
+ op.execute("drop index if exists idx_user_reports_reporter_id")
39
+
40
+
41
+ def downgrade() -> None:
42
+ op.execute("""
43
+ create index idx_user_reports_reporter_id
44
+ on user_reports (reporter_id)
45
+ """)
46
+ op.execute("drop index if exists idx_comment_reports_created_at")
47
+ op.execute("drop index if exists idx_post_reports_created_at")
48
+ op.execute("drop index if exists idx_comment_reports_target_id")
@@ -0,0 +1,38 @@
1
+ """add internal_notes table
2
+
3
+ Revision ID: d4af74643ff5
4
+ Revises: 716aa1735c03
5
+ Create Date: 2026-02-14 06:11:00.738789
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "d4af74643ff5"
15
+ down_revision: str | Sequence[str] | None = "716aa1735c03"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ create table internal_notes (
23
+ id bigint generated always as identity primary key,
24
+ target_user_id varchar(128) not null,
25
+ actor_id varchar(128) not null,
26
+ content text not null,
27
+ created_at timestamptz not null default now()
28
+ )
29
+ """)
30
+ op.execute("""
31
+ create index idx_internal_notes_target_user_id
32
+ on internal_notes (target_user_id)
33
+ """)
34
+
35
+
36
+ def downgrade() -> None:
37
+ op.execute("drop index if exists idx_internal_notes_target_user_id")
38
+ op.execute("drop table if exists internal_notes")
@@ -0,0 +1,35 @@
1
+ """add comment_reports table
2
+
3
+ Revision ID: db20f2fb7390
4
+ Revises: b2c3d4e5f6a7
5
+ Create Date: 2026-03-13 06:38:06.978358
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "db20f2fb7390"
15
+ down_revision: str | Sequence[str] | None = "b2c3d4e5f6a7"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ create table comment_reports (
23
+ id bigint generated always as identity primary key,
24
+ reporter_id varchar(128) not null,
25
+ target_id varchar(26) not null,
26
+ category report_category not null default 'other',
27
+ reason text not null default '',
28
+ created_at timestamptz not null default now(),
29
+ constraint comment_reports_reporter_target_unique unique (reporter_id, target_id)
30
+ )
31
+ """)
32
+
33
+
34
+ def downgrade() -> None:
35
+ op.execute("drop table if exists comment_reports")
@@ -0,0 +1,54 @@
1
+ """add report_category to user_reports table
2
+
3
+ Revision ID: e66226952ea6
4
+ Revises: 8fba1f72dd46
5
+ Create Date: 2026-02-05 08:06:50.220525
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "e66226952ea6"
15
+ down_revision: str | Sequence[str] | None = "8fba1f72dd46"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ create type report_category as enum (
23
+ 'spam',
24
+ 'harassment',
25
+ 'inappropriate_content',
26
+ 'impersonation',
27
+ 'self_harm',
28
+ 'hate_speech',
29
+ 'violence',
30
+ 'scam',
31
+ 'other'
32
+ );
33
+ """)
34
+ op.execute("""
35
+ alter table user_reports
36
+ add column category report_category not null default 'other';
37
+ """)
38
+ op.execute("""
39
+ alter table user_reports
40
+ alter column reason set default '';
41
+ """)
42
+ op.execute("""
43
+ drop index if exists idx_user_reports_created_at;
44
+ """)
45
+ op.execute("""
46
+ create index idx_user_reports_created_at
47
+ on user_reports (created_at desc)
48
+ include (id, reporter_id, target_id, category, reason);
49
+ """)
50
+
51
+
52
+ def downgrade() -> None:
53
+ """Downgrade schema."""
54
+ pass
@@ -0,0 +1,29 @@
1
+ """enforce 1 pending appeal
2
+
3
+ Revision ID: f5e8cb275c30
4
+ Revises: fe1faad2832d
5
+ Create Date: 2026-01-28 06:30:15.617564
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "f5e8cb275c30"
15
+ down_revision: str | Sequence[str] | None = "fe1faad2832d"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ create unique index if not exists one_pending_appeal_per_user
23
+ on appeals (user_id)
24
+ where status = 'pending';
25
+ """)
26
+
27
+
28
+ def downgrade() -> None:
29
+ op.execute("drop index if exists one_pending_appeal_per_user;")
@@ -0,0 +1,69 @@
1
+ """create restriction_history table
2
+
3
+ Revision ID: fe1faad2832d
4
+ Revises: 5f9e4fc14a41
5
+ Create Date: 2026-01-26 12:21:01.674950
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ from alembic import op
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = "fe1faad2832d"
15
+ down_revision: str | Sequence[str] | None = "5f9e4fc14a41"
16
+ branch_labels: str | Sequence[str] | None = None
17
+ depends_on: str | Sequence[str] | None = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.execute("""
22
+ create type history_action as enum ('inserted', 'updated', 'deleted');
23
+ """)
24
+ op.execute("""
25
+ create table restriction_history (
26
+ id bigint generated always as identity primary key,
27
+ user_id varchar(128) not null,
28
+ action history_action not null,
29
+ restriction_type restriction_type,
30
+ reason text,
31
+ expires_at timestamptz,
32
+ actor_id varchar(128),
33
+ created_at timestamptz not null default now()
34
+ );
35
+ """)
36
+ op.execute("""
37
+ create or replace function log_restriction_change()
38
+ returns trigger as $$
39
+ begin
40
+ if tg_op = 'INSERT' then
41
+ insert into moderation.restriction_history (user_id, action, restriction_type, reason, expires_at, actor_id)
42
+ values (new.user_id, 'inserted', new.restriction_type, new.reason, new.expires_at, current_setting('app.actor_id', true));
43
+ return new;
44
+ elsif tg_op = 'UPDATE' then
45
+ insert into moderation.restriction_history (user_id, action, restriction_type, reason, expires_at, actor_id)
46
+ values (new.user_id, 'updated', new.restriction_type, new.reason, new.expires_at, current_setting('app.actor_id', true));
47
+ return new;
48
+ elsif tg_op = 'DELETE' then
49
+ insert into moderation.restriction_history (user_id, action, restriction_type, reason, expires_at, actor_id)
50
+ values (old.user_id, 'deleted', old.restriction_type, old.reason, old.expires_at, current_setting('app.actor_id', true));
51
+ return old;
52
+ end if;
53
+ return null;
54
+ end;
55
+ $$ language plpgsql;
56
+ """)
57
+ op.execute("""
58
+ create trigger restriction_history_trigger
59
+ after insert or update or delete on user_restrictions
60
+ for each row
61
+ execute function log_restriction_change();
62
+ """)
63
+
64
+
65
+ def downgrade() -> None:
66
+ op.execute("drop trigger if exists restriction_history_trigger on user_restrictions;")
67
+ op.execute("drop function if exists log_restriction_change();")
68
+ op.execute("drop table if exists restriction_history;")
69
+ op.execute("drop type if exists history_action;")
@@ -0,0 +1,147 @@
1
+ # A generic, single database configuration.
2
+
3
+ [alembic]
4
+ # path to migration scripts.
5
+ # this is typically a path given in POSIX (e.g. forward slashes)
6
+ # format, relative to the token %(here)s which refers to the location of this
7
+ # ini file
8
+ script_location = %(here)s/alembic
9
+
10
+ # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
11
+ # Uncomment the line below if you want the files to be prepended with date and time
12
+ # see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
13
+ # for all available tokens
14
+ # file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
15
+
16
+ # sys.path path, will be prepended to sys.path if present.
17
+ # defaults to the current working directory. for multiple paths, the path separator
18
+ # is defined by "path_separator" below.
19
+ prepend_sys_path = .
20
+
21
+ # timezone to use when rendering the date within the migration file
22
+ # as well as the filename.
23
+ # If specified, requires the tzdata library which can be installed by adding
24
+ # `alembic[tz]` to the pip requirements.
25
+ # string value is passed to ZoneInfo()
26
+ # leave blank for localtime
27
+ # timezone =
28
+
29
+ # max length of characters to apply to the "slug" field
30
+ # truncate_slug_length = 40
31
+
32
+ # set to 'true' to run the environment during
33
+ # the 'revision' command, regardless of autogenerate
34
+ # revision_environment = false
35
+
36
+ # set to 'true' to allow .pyc and .pyo files without
37
+ # a source .py file to be detected as revisions in the
38
+ # versions/ directory
39
+ # sourceless = false
40
+
41
+ # version location specification; This defaults
42
+ # to <script_location>/versions. When using multiple version
43
+ # directories, initial revisions must be specified with --version-path.
44
+ # The path separator used here should be the separator specified by "path_separator"
45
+ # below.
46
+ # version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
47
+
48
+ # path_separator; This indicates what character is used to split lists of file
49
+ # paths, including version_locations and prepend_sys_path within configparser
50
+ # files such as alembic.ini.
51
+ # The default rendered in new alembic.ini files is "os", which uses os.pathsep
52
+ # to provide os-dependent path splitting.
53
+ #
54
+ # Note that in order to support legacy alembic.ini files, this default does NOT
55
+ # take place if path_separator is not present in alembic.ini. If this
56
+ # option is omitted entirely, fallback logic is as follows:
57
+ #
58
+ # 1. Parsing of the version_locations option falls back to using the legacy
59
+ # "version_path_separator" key, which if absent then falls back to the legacy
60
+ # behavior of splitting on spaces and/or commas.
61
+ # 2. Parsing of the prepend_sys_path option falls back to the legacy
62
+ # behavior of splitting on spaces, commas, or colons.
63
+ #
64
+ # Valid values for path_separator are:
65
+ #
66
+ # path_separator = :
67
+ # path_separator = ;
68
+ # path_separator = space
69
+ # path_separator = newline
70
+ #
71
+ # Use os.pathsep. Default configuration used for new projects.
72
+ path_separator = os
73
+
74
+
75
+ # set to 'true' to search source files recursively
76
+ # in each "version_locations" directory
77
+ # new in Alembic version 1.10
78
+ # recursive_version_locations = false
79
+
80
+ # the output encoding used when revision files
81
+ # are written from script.py.mako
82
+ # output_encoding = utf-8
83
+
84
+ # database URL. This is consumed by the user-maintained env.py script only.
85
+ # other means of configuring database URLs may be customized within the env.py
86
+ # file.
87
+ sqlalchemy.url = driver://user:pass@localhost/dbname
88
+
89
+
90
+ [post_write_hooks]
91
+ # post_write_hooks defines scripts or Python functions that are run
92
+ # on newly generated revision scripts. See the documentation for further
93
+ # detail and examples
94
+
95
+ # format using "black" - use the console_scripts runner, against the "black" entrypoint
96
+ # hooks = black
97
+ # black.type = console_scripts
98
+ # black.entrypoint = black
99
+ # black.options = -l 79 REVISION_SCRIPT_FILENAME
100
+
101
+ # lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
102
+ # hooks = ruff
103
+ # ruff.type = module
104
+ # ruff.module = ruff
105
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
106
+
107
+ # Alternatively, use the exec runner to execute a binary found on your PATH
108
+ # hooks = ruff
109
+ # ruff.type = exec
110
+ # ruff.executable = ruff
111
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
112
+
113
+ # Logging configuration. This is also consumed by the user-maintained
114
+ # env.py script only.
115
+ [loggers]
116
+ keys = root,sqlalchemy,alembic
117
+
118
+ [handlers]
119
+ keys = console
120
+
121
+ [formatters]
122
+ keys = generic
123
+
124
+ [logger_root]
125
+ level = WARNING
126
+ handlers = console
127
+ qualname =
128
+
129
+ [logger_sqlalchemy]
130
+ level = WARNING
131
+ handlers =
132
+ qualname = sqlalchemy.engine
133
+
134
+ [logger_alembic]
135
+ level = INFO
136
+ handlers =
137
+ qualname = alembic
138
+
139
+ [handler_console]
140
+ class = StreamHandler
141
+ args = (sys.stderr,)
142
+ level = NOTSET
143
+ formatter = generic
144
+
145
+ [formatter_generic]
146
+ format = %(levelname)-5.5s [%(name)s] %(message)s
147
+ datefmt = %H:%M:%S
@@ -0,0 +1 @@
1
+ Generic single-database configuration with an async dbapi.