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,97 @@
1
+ import asyncio
2
+ from logging.config import fileConfig
3
+
4
+ from sqlalchemy import pool, text
5
+ from sqlalchemy.engine import Connection
6
+ from sqlalchemy.ext.asyncio import async_engine_from_config
7
+
8
+ from alembic import context
9
+ from core_framework.core import settings
10
+
11
+ # this is the Alembic Config object, which provides
12
+ # access to the values within the .ini file in use.
13
+ config = context.config
14
+
15
+ # Interpret the config file for Python logging.
16
+ # This line sets up loggers basically.
17
+ if config.config_file_name is not None:
18
+ fileConfig(config.config_file_name)
19
+
20
+ # add your model's MetaData object here
21
+ # for 'autogenerate' support
22
+ # from myapp import mymodel
23
+ # target_metadata = mymodel.Base.metadata
24
+ target_metadata = None
25
+
26
+ # other values from the config, defined by the needs of env.py,
27
+ # can be acquired:
28
+ # my_important_option = config.get_main_option("my_important_option")
29
+ # ... etc.
30
+ config.set_main_option("sqlalchemy.url", settings.write_postgres.alembic_postgres_url)
31
+
32
+
33
+ def run_migrations_offline() -> None:
34
+ """Run migrations in 'offline' mode.
35
+
36
+ This configures the context with just a URL
37
+ and not an Engine, though an Engine is acceptable
38
+ here as well. By skipping the Engine creation
39
+ we don't even need a DBAPI to be available.
40
+
41
+ Calls to context.execute() here emit the given string to the
42
+ script output.
43
+
44
+ """
45
+ url = config.get_main_option("sqlalchemy.url")
46
+ context.configure(
47
+ url=url,
48
+ target_metadata=target_metadata,
49
+ literal_binds=True,
50
+ dialect_opts={"paramstyle": "named"},
51
+ )
52
+
53
+ with context.begin_transaction():
54
+ context.run_migrations()
55
+
56
+
57
+ def do_run_migrations(connection: Connection) -> None:
58
+ quoted_schema_name = f'"{settings.postgres_schemas.schema_post.replace('"', '""')}"'
59
+
60
+ connection.execute(text(f"create schema if not exists {quoted_schema_name}"))
61
+ connection.execute(text(f"set search_path to {quoted_schema_name}"))
62
+ connection.commit()
63
+
64
+ context.configure(connection=connection, target_metadata=target_metadata)
65
+
66
+ with context.begin_transaction():
67
+ context.run_migrations()
68
+
69
+
70
+ async def run_async_migrations() -> None:
71
+ """In this scenario we need to create an Engine
72
+ and associate a connection with the context.
73
+
74
+ """
75
+
76
+ connectable = async_engine_from_config(
77
+ config.get_section(config.config_ini_section, {}),
78
+ prefix="sqlalchemy.",
79
+ poolclass=pool.NullPool,
80
+ )
81
+
82
+ async with connectable.connect() as connection:
83
+ await connection.run_sync(do_run_migrations)
84
+
85
+ await connectable.dispose()
86
+
87
+
88
+ def run_migrations_online() -> None:
89
+ """Run migrations in 'online' mode."""
90
+
91
+ asyncio.run(run_async_migrations())
92
+
93
+
94
+ if context.is_offline_mode():
95
+ run_migrations_offline()
96
+ else:
97
+ run_migrations_online()
@@ -0,0 +1,28 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ """Upgrade schema."""
23
+ ${upgrades if upgrades else "pass"}
24
+
25
+
26
+ def downgrade() -> None:
27
+ """Downgrade schema."""
28
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,41 @@
1
+ """add lookup tables for restrictions and blocks
2
+
3
+ Revision ID: 51542673f5c8
4
+ Revises: e56723f2afff
5
+ Create Date: 2026-02-26 05:49:19.200098
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 = "51542673f5c8"
15
+ down_revision: str | Sequence[str] | None = "e56723f2afff"
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 user_restrictions_lookup (
23
+ user_id varchar(128) primary key,
24
+ restriction_type varchar(16) not null,
25
+ constraint user_restrictions_lookup_restriction_type_valid
26
+ check (restriction_type in ('muted', 'banned'))
27
+ );
28
+ """)
29
+ op.execute("""
30
+ create table user_blocks_lookup (
31
+ blocker_id varchar(128) not null,
32
+ blocked_id varchar(128) not null,
33
+ primary key (blocker_id, blocked_id),
34
+ constraint user_blocks_lookup_no_self_block check (blocker_id != blocked_id)
35
+ );
36
+ """)
37
+
38
+
39
+ def downgrade() -> None:
40
+ op.execute("drop table if exists user_blocks_lookup;")
41
+ op.execute("drop table if exists user_restrictions_lookup;")
@@ -0,0 +1,45 @@
1
+ """add post_views table
2
+
3
+ Revision ID: 5beeeae40a4a
4
+ Revises: 51542673f5c8
5
+ Create Date: 2026-02-28 06:17:01.503252
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 = "5beeeae40a4a"
15
+ down_revision: str | Sequence[str] | None = "51542673f5c8"
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
+ alter table post_stats
23
+ add column view_count_aggregated_at timestamptz null;
24
+ """)
25
+ op.execute("""
26
+ create table post_views (
27
+ post_id varchar(26) not null references posts(id) on delete cascade,
28
+ token varchar(256) not null,
29
+ created_at timestamptz not null default now(),
30
+ request_context jsonb not null default '{}'::jsonb,
31
+ primary key (post_id, token)
32
+ );
33
+ """)
34
+ op.execute("""
35
+ create index idx_post_views_post_id_created_at on post_views (post_id, created_at);
36
+ """)
37
+
38
+
39
+ def downgrade() -> None:
40
+ op.execute("drop index if exists idx_post_views_post_id_created_at;")
41
+ op.execute("drop table if exists post_views;")
42
+ op.execute("""
43
+ alter table post_stats
44
+ drop column if exists view_count_aggregated_at;
45
+ """)
@@ -0,0 +1,55 @@
1
+ """init
2
+
3
+ Revision ID: 620971509a8b
4
+ Revises:
5
+ Create Date: 2026-02-22 06:41:21.953571
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 = "620971509a8b"
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 post_visibility as enum (
23
+ 'public',
24
+ 'followers',
25
+ 'private',
26
+ 'unlisted'
27
+ );
28
+ """)
29
+ op.execute("""
30
+ create type post_status as enum (
31
+ 'active',
32
+ 'deleted'
33
+ );
34
+ """)
35
+ op.execute("""
36
+ create table posts (
37
+ id varchar(26) primary key,
38
+ author_id varchar(128) not null,
39
+ content text not null,
40
+ visibility post_visibility not null default 'public',
41
+ status post_status not null default 'active',
42
+ edited_at timestamptz null,
43
+ edited_count int not null default 0,
44
+ created_at timestamptz not null default now(),
45
+ updated_at timestamptz not null default now(),
46
+ constraint posts_edited_count_non_negative check (edited_count >= 0),
47
+ constraint posts_content_not_blank check (length(trim(content)) > 0)
48
+ );
49
+ """)
50
+
51
+
52
+ def downgrade() -> None:
53
+ op.execute("drop table if exists posts;")
54
+ op.execute("drop type if exists post_status;")
55
+ op.execute("drop type if exists post_visibility;")
@@ -0,0 +1,44 @@
1
+ """add indexes
2
+
3
+ Revision ID: a1b2c3d4e5f6
4
+ Revises: fbc723ac58cc
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 = "a1b2c3d4e5f6"
14
+ down_revision: str | Sequence[str] | None = "fbc723ac58cc"
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_posts_status_created_at
22
+ on posts (status, created_at desc)
23
+ where status = 'active'
24
+ """)
25
+ op.execute("""
26
+ create index idx_posts_author_created_at
27
+ on posts (author_id, created_at desc)
28
+ where status = 'active'
29
+ """)
30
+ op.execute("""
31
+ create index idx_post_likes_liker_id
32
+ on post_likes (liker_id)
33
+ """)
34
+ op.execute("""
35
+ create index idx_user_blocks_lookup_blocked_id
36
+ on user_blocks_lookup (blocked_id)
37
+ """)
38
+
39
+
40
+ def downgrade() -> None:
41
+ op.execute("drop index if exists idx_posts_status_created_at")
42
+ op.execute("drop index if exists idx_posts_author_created_at")
43
+ op.execute("drop index if exists idx_post_likes_liker_id")
44
+ op.execute("drop index if exists idx_user_blocks_lookup_blocked_id")
@@ -0,0 +1,36 @@
1
+ """add post_hashtags table
2
+
3
+ Revision ID: c1d2e3f4a5b6
4
+ Revises: a1b2c3d4e5f6
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 = "c1d2e3f4a5b6"
14
+ down_revision: str | Sequence[str] | None = "a1b2c3d4e5f6"
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 table post_hashtags (
22
+ post_id varchar(26) not null references posts(id) on delete cascade,
23
+ hashtag varchar(50) not null,
24
+ created_at timestamptz not null default now(),
25
+ primary key (post_id, hashtag)
26
+ );
27
+ """)
28
+ op.execute("""
29
+ create index idx_post_hashtags_hashtag
30
+ on post_hashtags (hashtag);
31
+ """)
32
+
33
+
34
+ def downgrade() -> None:
35
+ op.execute("drop index if exists idx_post_hashtags_hashtag")
36
+ op.execute("drop table if exists post_hashtags")
@@ -0,0 +1,39 @@
1
+ """add post_stats table
2
+
3
+ Revision ID: e56723f2afff
4
+ Revises: 620971509a8b
5
+ Create Date: 2026-02-24 06:16:15.098541
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 = "e56723f2afff"
15
+ down_revision: str | Sequence[str] | None = "620971509a8b"
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 post_stats (
23
+ post_id varchar(26) primary key references posts(id) on delete cascade,
24
+ like_count bigint not null default 0,
25
+ comment_count bigint not null default 0,
26
+ view_count bigint not null default 0,
27
+ report_count bigint not null default 0,
28
+ created_at timestamptz not null default now(),
29
+ updated_at timestamptz not null default now(),
30
+ constraint post_stats_like_count_non_negative check (like_count >= 0),
31
+ constraint post_stats_comment_count_non_negative check (comment_count >= 0),
32
+ constraint post_stats_view_count_non_negative check (view_count >= 0),
33
+ constraint post_stats_report_count_non_negative check (report_count >= 0)
34
+ );
35
+ """)
36
+
37
+
38
+ def downgrade() -> None:
39
+ op.execute("drop table if exists post_stats;")
@@ -0,0 +1,32 @@
1
+ """add post_likes table
2
+
3
+ Revision ID: fbc723ac58cc
4
+ Revises: 5beeeae40a4a
5
+ Create Date: 2026-03-03 05:31:52.487057
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 = "fbc723ac58cc"
15
+ down_revision: str | Sequence[str] | None = "5beeeae40a4a"
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 post_likes (
23
+ post_id varchar(26) not null references posts(id) on delete cascade,
24
+ liker_id varchar(128) not null,
25
+ created_at timestamptz not null default now(),
26
+ primary key (post_id, liker_id)
27
+ );
28
+ """)
29
+
30
+
31
+ def downgrade() -> None:
32
+ op.execute("drop table if exists post_likes;")
@@ -0,0 +1,149 @@
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
+ # Or organize into date-based subdirectories (requires recursive_version_locations = true)
16
+ # file_template = %%(year)d/%%(month).2d/%%(day).2d_%%(hour).2d%%(minute).2d_%%(second).2d_%%(rev)s_%%(slug)s
17
+
18
+ # sys.path path, will be prepended to sys.path if present.
19
+ # defaults to the current working directory. for multiple paths, the path separator
20
+ # is defined by "path_separator" below.
21
+ prepend_sys_path = .
22
+
23
+ # timezone to use when rendering the date within the migration file
24
+ # as well as the filename.
25
+ # If specified, requires the tzdata library which can be installed by adding
26
+ # `alembic[tz]` to the pip requirements.
27
+ # string value is passed to ZoneInfo()
28
+ # leave blank for localtime
29
+ # timezone =
30
+
31
+ # max length of characters to apply to the "slug" field
32
+ # truncate_slug_length = 40
33
+
34
+ # set to 'true' to run the environment during
35
+ # the 'revision' command, regardless of autogenerate
36
+ # revision_environment = false
37
+
38
+ # set to 'true' to allow .pyc and .pyo files without
39
+ # a source .py file to be detected as revisions in the
40
+ # versions/ directory
41
+ # sourceless = false
42
+
43
+ # version location specification; This defaults
44
+ # to <script_location>/versions. When using multiple version
45
+ # directories, initial revisions must be specified with --version-path.
46
+ # The path separator used here should be the separator specified by "path_separator"
47
+ # below.
48
+ # version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
49
+
50
+ # path_separator; This indicates what character is used to split lists of file
51
+ # paths, including version_locations and prepend_sys_path within configparser
52
+ # files such as alembic.ini.
53
+ # The default rendered in new alembic.ini files is "os", which uses os.pathsep
54
+ # to provide os-dependent path splitting.
55
+ #
56
+ # Note that in order to support legacy alembic.ini files, this default does NOT
57
+ # take place if path_separator is not present in alembic.ini. If this
58
+ # option is omitted entirely, fallback logic is as follows:
59
+ #
60
+ # 1. Parsing of the version_locations option falls back to using the legacy
61
+ # "version_path_separator" key, which if absent then falls back to the legacy
62
+ # behavior of splitting on spaces and/or commas.
63
+ # 2. Parsing of the prepend_sys_path option falls back to the legacy
64
+ # behavior of splitting on spaces, commas, or colons.
65
+ #
66
+ # Valid values for path_separator are:
67
+ #
68
+ # path_separator = :
69
+ # path_separator = ;
70
+ # path_separator = space
71
+ # path_separator = newline
72
+ #
73
+ # Use os.pathsep. Default configuration used for new projects.
74
+ path_separator = os
75
+
76
+
77
+ # set to 'true' to search source files recursively
78
+ # in each "version_locations" directory
79
+ # new in Alembic version 1.10
80
+ # recursive_version_locations = false
81
+
82
+ # the output encoding used when revision files
83
+ # are written from script.py.mako
84
+ # output_encoding = utf-8
85
+
86
+ # database URL. This is consumed by the user-maintained env.py script only.
87
+ # other means of configuring database URLs may be customized within the env.py
88
+ # file.
89
+ sqlalchemy.url = driver://user:pass@localhost/dbname
90
+
91
+
92
+ [post_write_hooks]
93
+ # post_write_hooks defines scripts or Python functions that are run
94
+ # on newly generated revision scripts. See the documentation for further
95
+ # detail and examples
96
+
97
+ # format using "black" - use the console_scripts runner, against the "black" entrypoint
98
+ # hooks = black
99
+ # black.type = console_scripts
100
+ # black.entrypoint = black
101
+ # black.options = -l 79 REVISION_SCRIPT_FILENAME
102
+
103
+ # lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
104
+ # hooks = ruff
105
+ # ruff.type = module
106
+ # ruff.module = ruff
107
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
108
+
109
+ # Alternatively, use the exec runner to execute a binary found on your PATH
110
+ # hooks = ruff
111
+ # ruff.type = exec
112
+ # ruff.executable = ruff
113
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
114
+
115
+ # Logging configuration. This is also consumed by the user-maintained
116
+ # env.py script only.
117
+ [loggers]
118
+ keys = root,sqlalchemy,alembic
119
+
120
+ [handlers]
121
+ keys = console
122
+
123
+ [formatters]
124
+ keys = generic
125
+
126
+ [logger_root]
127
+ level = WARNING
128
+ handlers = console
129
+ qualname =
130
+
131
+ [logger_sqlalchemy]
132
+ level = WARNING
133
+ handlers =
134
+ qualname = sqlalchemy.engine
135
+
136
+ [logger_alembic]
137
+ level = INFO
138
+ handlers =
139
+ qualname = alembic
140
+
141
+ [handler_console]
142
+ class = StreamHandler
143
+ args = (sys.stderr,)
144
+ level = NOTSET
145
+ formatter = generic
146
+
147
+ [formatter_generic]
148
+ format = %(levelname)-5.5s [%(name)s] %(message)s
149
+ datefmt = %H:%M:%S
@@ -0,0 +1 @@
1
+ Generic single-database configuration with an async dbapi.
@@ -0,0 +1,98 @@
1
+ import asyncio
2
+ from logging.config import fileConfig
3
+
4
+ from sqlalchemy import pool, text
5
+ from sqlalchemy.engine import Connection
6
+ from sqlalchemy.ext.asyncio import async_engine_from_config
7
+
8
+ from alembic import context
9
+ from core_framework.core import settings
10
+
11
+ # this is the Alembic Config object, which provides
12
+ # access to the values within the .ini file in use.
13
+ config = context.config
14
+
15
+ # Interpret the config file for Python logging.
16
+ # This line sets up loggers basically.
17
+ if config.config_file_name is not None:
18
+ fileConfig(config.config_file_name)
19
+
20
+ # add your model's MetaData object here
21
+ # for 'autogenerate' support
22
+ # from myapp import mymodel
23
+ # target_metadata = mymodel.Base.metadata
24
+ target_metadata = None
25
+
26
+ # other values from the config, defined by the needs of env.py,
27
+ # can be acquired:
28
+ # my_important_option = config.get_main_option("my_important_option")
29
+ # ... etc.
30
+
31
+ config.set_main_option("sqlalchemy.url", settings.write_postgres.alembic_postgres_url)
32
+
33
+
34
+ def run_migrations_offline() -> None:
35
+ """Run migrations in 'offline' mode.
36
+
37
+ This configures the context with just a URL
38
+ and not an Engine, though an Engine is acceptable
39
+ here as well. By skipping the Engine creation
40
+ we don't even need a DBAPI to be available.
41
+
42
+ Calls to context.execute() here emit the given string to the
43
+ script output.
44
+
45
+ """
46
+ url = config.get_main_option("sqlalchemy.url")
47
+ context.configure(
48
+ url=url,
49
+ target_metadata=target_metadata,
50
+ literal_binds=True,
51
+ dialect_opts={"paramstyle": "named"},
52
+ )
53
+
54
+ with context.begin_transaction():
55
+ context.run_migrations()
56
+
57
+
58
+ def do_run_migrations(connection: Connection) -> None:
59
+ quoted_schema_name = f'"{settings.postgres_schemas.schema_user.replace('"', '""')}"'
60
+
61
+ connection.execute(text(f"create schema if not exists {quoted_schema_name}"))
62
+ connection.execute(text(f"set search_path to {quoted_schema_name}"))
63
+ connection.commit()
64
+
65
+ context.configure(connection=connection, target_metadata=target_metadata)
66
+
67
+ with context.begin_transaction():
68
+ context.run_migrations()
69
+
70
+
71
+ async def run_async_migrations() -> None:
72
+ """In this scenario we need to create an Engine
73
+ and associate a connection with the context.
74
+
75
+ """
76
+
77
+ connectable = async_engine_from_config(
78
+ config.get_section(config.config_ini_section, {}),
79
+ prefix="sqlalchemy.",
80
+ poolclass=pool.NullPool,
81
+ )
82
+
83
+ async with connectable.connect() as connection:
84
+ await connection.run_sync(do_run_migrations)
85
+
86
+ await connectable.dispose()
87
+
88
+
89
+ def run_migrations_online() -> None:
90
+ """Run migrations in 'online' mode."""
91
+
92
+ asyncio.run(run_async_migrations())
93
+
94
+
95
+ if context.is_offline_mode():
96
+ run_migrations_offline()
97
+ else:
98
+ run_migrations_online()