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.
- core_framework/__init__.py +0 -0
- core_framework/alembic/comment/alembic/README +1 -0
- core_framework/alembic/comment/alembic/env.py +72 -0
- core_framework/alembic/comment/alembic/script.py.mako +28 -0
- core_framework/alembic/comment/alembic/versions/30334fd1347b_init.py +59 -0
- core_framework/alembic/comment/alembic/versions/a2b3c4d5e6f7_improve_comment_indexes.py +54 -0
- core_framework/alembic/comment/alembic/versions/bcc8e00cfc8b_add_extra_tables.py +64 -0
- core_framework/alembic/comment/alembic/versions/d1e2f3a4b5c6_add_comment_stats_dirty_table.py +29 -0
- core_framework/alembic/comment/alembic/versions/e3f4a5b6c7d8_cascade_delete_comment_descendants.py +49 -0
- core_framework/alembic/comment/alembic/versions/f7e6d5c4b3a2_comments_path_to_ltree.py +60 -0
- core_framework/alembic/comment/alembic.ini +52 -0
- core_framework/alembic/extension/alembic/README +1 -0
- core_framework/alembic/extension/alembic/env.py +98 -0
- core_framework/alembic/extension/alembic/script.py.mako +28 -0
- core_framework/alembic/extension/alembic/versions/0389226049cb_add_pg_trgm_extension.py +25 -0
- core_framework/alembic/extension/alembic/versions/5dc58b016cf5_add_citext_extension.py +25 -0
- core_framework/alembic/extension/alembic/versions/b0ba0d8a284e_add_pg_stat_statements_extension.py +25 -0
- core_framework/alembic/extension/alembic/versions/c9d0e1f2a3b4_add_ltree_extension.py +25 -0
- core_framework/alembic/extension/alembic.ini +147 -0
- core_framework/alembic/moderation/alembic/README +1 -0
- core_framework/alembic/moderation/alembic/env.py +98 -0
- core_framework/alembic/moderation/alembic/script.py.mako +28 -0
- core_framework/alembic/moderation/alembic/versions/085ba9021850_add_category_to_user_restrictions.py +93 -0
- core_framework/alembic/moderation/alembic/versions/5f9e4fc14a41_create_moderation_appeals_table.py +69 -0
- core_framework/alembic/moderation/alembic/versions/63e37381e73b_add_user_reports_table.py +33 -0
- core_framework/alembic/moderation/alembic/versions/6a2ae31b7ac6_add_moderation_actions_table.py +34 -0
- core_framework/alembic/moderation/alembic/versions/716aa1735c03_improve_indexes.py +36 -0
- core_framework/alembic/moderation/alembic/versions/7d243ddbfde1_add_post_reports_table.py +35 -0
- core_framework/alembic/moderation/alembic/versions/8fba1f72dd46_add_indexes.py +64 -0
- core_framework/alembic/moderation/alembic/versions/95cc35a51984_update_restriction_history.py +91 -0
- core_framework/alembic/moderation/alembic/versions/9ad79d0af730_add_unique_constraint_user_reports_.py +28 -0
- core_framework/alembic/moderation/alembic/versions/a5e569f5df1a_create_user_restrictions_table.py +38 -0
- core_framework/alembic/moderation/alembic/versions/b2c3d4e5f6a7_add_indexes.py +42 -0
- core_framework/alembic/moderation/alembic/versions/c3d4e5f6a7b8_improve_report_indexes.py +48 -0
- core_framework/alembic/moderation/alembic/versions/d4af74643ff5_add_internal_notes_table.py +38 -0
- core_framework/alembic/moderation/alembic/versions/db20f2fb7390_add_comment_reports_table.py +35 -0
- core_framework/alembic/moderation/alembic/versions/e66226952ea6_add_report_category_to_user_reports_.py +54 -0
- core_framework/alembic/moderation/alembic/versions/f5e8cb275c30_enforce_1_pending_appeal.py +29 -0
- core_framework/alembic/moderation/alembic/versions/fe1faad2832d_create_restriction_history_table.py +69 -0
- core_framework/alembic/moderation/alembic.ini +147 -0
- core_framework/alembic/post/alembic/README +1 -0
- core_framework/alembic/post/alembic/env.py +97 -0
- core_framework/alembic/post/alembic/script.py.mako +28 -0
- core_framework/alembic/post/alembic/versions/51542673f5c8_add_tables_for_muted_banned_users.py +41 -0
- core_framework/alembic/post/alembic/versions/5beeeae40a4a_add_post_views_table.py +45 -0
- core_framework/alembic/post/alembic/versions/620971509a8b_init.py +55 -0
- core_framework/alembic/post/alembic/versions/a1b2c3d4e5f6_add_indexes.py +44 -0
- core_framework/alembic/post/alembic/versions/c1d2e3f4a5b6_add_post_hashtags_table.py +36 -0
- core_framework/alembic/post/alembic/versions/e56723f2afff_add_post_stats_table.py +39 -0
- core_framework/alembic/post/alembic/versions/fbc723ac58cc_add_post_likes_table.py +32 -0
- core_framework/alembic/post/alembic.ini +149 -0
- core_framework/alembic/user/alembic/README +1 -0
- core_framework/alembic/user/alembic/env.py +98 -0
- core_framework/alembic/user/alembic/script.py.mako +28 -0
- core_framework/alembic/user/alembic/versions/1a8bb99726ed_remove_avatar_id_from_users.py +81 -0
- core_framework/alembic/user/alembic/versions/2ccacf455941_improve_indexes.py +34 -0
- core_framework/alembic/user/alembic/versions/47f47ce2110e_create_user_deletions_table.py +31 -0
- core_framework/alembic/user/alembic/versions/5976db3f0175_drop_user_states.py +26 -0
- core_framework/alembic/user/alembic/versions/62417002cf32_add_indexes.py +46 -0
- core_framework/alembic/user/alembic/versions/6f7ccf3c226b_refactor_user_login_events.py +66 -0
- core_framework/alembic/user/alembic/versions/73432817015b_add_user_preferences_table.py +33 -0
- core_framework/alembic/user/alembic/versions/765bc01a7a59_create_user_blocks_table.py +33 -0
- core_framework/alembic/user/alembic/versions/7a56631f9927_create_user_login_events_table.py +49 -0
- core_framework/alembic/user/alembic/versions/831611e589bc_create_user_state.py +31 -0
- core_framework/alembic/user/alembic/versions/83c98ab2a779_add_user_profiles_table.py +88 -0
- core_framework/alembic/user/alembic/versions/8a94362cad6d_create_user_role.py +31 -0
- core_framework/alembic/user/alembic/versions/94b973923895_add_user_change_history_table.py +97 -0
- core_framework/alembic/user/alembic/versions/cbc0f4efe84f_add_avatar_id_column_to_users_table.py +31 -0
- core_framework/alembic/user/alembic/versions/d8b98ac6b073_add_index_for_get_admin_user_ids_query.py +29 -0
- core_framework/alembic/user/alembic/versions/ddb70cc09d16_create_user_states_table.py +34 -0
- core_framework/alembic/user/alembic/versions/f9ba10815ecd_add_users_table.py +33 -0
- core_framework/alembic/user/alembic.ini +147 -0
- core_framework/api/__init__.py +0 -0
- core_framework/api/admin/__init__.py +0 -0
- core_framework/api/admin/comments/router.py +69 -0
- core_framework/api/admin/comments/schemas.py +53 -0
- core_framework/api/admin/moderation/__init__.py +0 -0
- core_framework/api/admin/moderation/router.py +205 -0
- core_framework/api/admin/moderation/schemas.py +110 -0
- core_framework/api/admin/posts/router.py +62 -0
- core_framework/api/admin/posts/schemas.py +29 -0
- core_framework/api/admin/router.py +17 -0
- core_framework/api/admin/users/__init__.py +0 -0
- core_framework/api/admin/users/router.py +181 -0
- core_framework/api/admin/users/schemas.py +137 -0
- core_framework/api/auth/__init__.py +0 -0
- core_framework/api/auth/router.py +21 -0
- core_framework/api/auth/schemas.py +28 -0
- core_framework/api/comments/authenticated/router.py +126 -0
- core_framework/api/comments/authenticated/schemas.py +27 -0
- core_framework/api/comments/public/router.py +103 -0
- core_framework/api/comments/public/schemas.py +36 -0
- core_framework/api/comments/router.py +9 -0
- core_framework/api/comments/schemas.py +17 -0
- core_framework/api/dependencies.py +168 -0
- core_framework/api/events/router.py +39 -0
- core_framework/api/events/schemas.py +20 -0
- core_framework/api/posts/authenticated/router.py +83 -0
- core_framework/api/posts/authenticated/schemas.py +37 -0
- core_framework/api/posts/public/router.py +100 -0
- core_framework/api/posts/public/schemas.py +39 -0
- core_framework/api/posts/router.py +9 -0
- core_framework/api/posts/schemas.py +39 -0
- core_framework/api/router.py +19 -0
- core_framework/api/schemas.py +9 -0
- core_framework/api/system/__init__.py +0 -0
- core_framework/api/system/router.py +108 -0
- core_framework/api/users/__init__.py +0 -0
- core_framework/api/users/authenticated/__init__.py +0 -0
- core_framework/api/users/authenticated/router.py +244 -0
- core_framework/api/users/authenticated/schemas.py +81 -0
- core_framework/api/users/public/__init__.py +0 -0
- core_framework/api/users/public/router.py +25 -0
- core_framework/api/users/public/schemas.py +7 -0
- core_framework/api/users/router.py +9 -0
- core_framework/api/users/shared/schemas.py +174 -0
- core_framework/application/__init__.py +0 -0
- core_framework/application/auth/__init__.py +0 -0
- core_framework/application/auth/access_service.py +26 -0
- core_framework/application/auth/auth_service.py +10 -0
- core_framework/application/auth/models.py +10 -0
- core_framework/application/bootstrap.py +19 -0
- core_framework/application/comments/admin_service.py +236 -0
- core_framework/application/comments/aggregation_service.py +28 -0
- core_framework/application/comments/authenticated_service.py +89 -0
- core_framework/application/comments/public_service.py +218 -0
- core_framework/application/events/README.md +26 -0
- core_framework/application/events/event_service.py +51 -0
- core_framework/application/events/event_token.py +46 -0
- core_framework/application/events/models.py +9 -0
- core_framework/application/moderation/__init__.py +0 -0
- core_framework/application/moderation/appeal_service.py +98 -0
- core_framework/application/moderation/moderator_service.py +46 -0
- core_framework/application/moderation/report_service.py +180 -0
- core_framework/application/moderation/scheduled_service.py +5 -0
- core_framework/application/moderation/user_service.py +180 -0
- core_framework/application/posts/admin_service.py +104 -0
- core_framework/application/posts/aggregation_service.py +28 -0
- core_framework/application/posts/authenticated_service.py +72 -0
- core_framework/application/posts/public_service.py +197 -0
- core_framework/application/shared/__init__.py +0 -0
- core_framework/application/shared/enums.py +16 -0
- core_framework/application/shared/exceptions.py +16 -0
- core_framework/application/shared/user_agent.py +24 -0
- core_framework/application/users/__init__.py +0 -0
- core_framework/application/users/admin_service.py +298 -0
- core_framework/application/users/authenticated_service.py +179 -0
- core_framework/application/users/public_service.py +7 -0
- core_framework/application/users/scheduled_service.py +5 -0
- core_framework/bundled_alembic.py +57 -0
- core_framework/core/__init__.py +37 -0
- core_framework/core/cache.py +234 -0
- core_framework/core/context.py +14 -0
- core_framework/core/database.py +111 -0
- core_framework/core/exception_handlers/__init__.py +3 -0
- core_framework/core/exception_handlers/comment.py +99 -0
- core_framework/core/exception_handlers/common.py +5 -0
- core_framework/core/exception_handlers/moderation.py +104 -0
- core_framework/core/exception_handlers/post.py +54 -0
- core_framework/core/exception_handlers/setup.py +80 -0
- core_framework/core/exception_handlers/user.py +72 -0
- core_framework/core/http_client.py +64 -0
- core_framework/core/logging.py +99 -0
- core_framework/core/middleware.py +64 -0
- core_framework/core/observability.py +36 -0
- core_framework/core/pagination.py +203 -0
- core_framework/core/redis.py +135 -0
- core_framework/core/runtime.py +66 -0
- core_framework/core/settings.py +189 -0
- core_framework/domains/__init__.py +0 -0
- core_framework/domains/comment/README.md +243 -0
- core_framework/domains/comment/__init__.py +25 -0
- core_framework/domains/comment/constants.py +3 -0
- core_framework/domains/comment/dependencies.py +29 -0
- core_framework/domains/comment/enums.py +11 -0
- core_framework/domains/comment/exceptions.py +31 -0
- core_framework/domains/comment/models.py +54 -0
- core_framework/domains/comment/repository.py +947 -0
- core_framework/domains/comment/service.py +259 -0
- core_framework/domains/moderation/README.md +138 -0
- core_framework/domains/moderation/__init__.py +47 -0
- core_framework/domains/moderation/dependencies.py +29 -0
- core_framework/domains/moderation/enums.py +62 -0
- core_framework/domains/moderation/exceptions.py +31 -0
- core_framework/domains/moderation/models.py +94 -0
- core_framework/domains/moderation/repository.py +828 -0
- core_framework/domains/moderation/service.py +334 -0
- core_framework/domains/post/README.md +182 -0
- core_framework/domains/post/__init__.py +22 -0
- core_framework/domains/post/constants.py +3 -0
- core_framework/domains/post/dependencies.py +29 -0
- core_framework/domains/post/enums.py +18 -0
- core_framework/domains/post/exceptions.py +21 -0
- core_framework/domains/post/models.py +53 -0
- core_framework/domains/post/repository.py +791 -0
- core_framework/domains/post/service.py +204 -0
- core_framework/domains/user/README.md +74 -0
- core_framework/domains/user/__init__.py +39 -0
- core_framework/domains/user/constants.py +8 -0
- core_framework/domains/user/dependencies.py +29 -0
- core_framework/domains/user/enums.py +19 -0
- core_framework/domains/user/exceptions.py +31 -0
- core_framework/domains/user/models.py +124 -0
- core_framework/domains/user/repository.py +612 -0
- core_framework/domains/user/service.py +257 -0
- core_framework/domains/user/utils.py +182 -0
- core_framework/main.py +104 -0
- core_framework/worker/__init__.py +0 -0
- core_framework/worker/main.py +56 -0
- core_framework/worker/schedules/__init__.py +35 -0
- core_framework/worker/schedules/schedule_aggregate_comment_stats.py +32 -0
- core_framework/worker/schedules/schedule_aggregate_post_view_counts.py +28 -0
- core_framework/worker/schedules/schedule_expired_account_deletions.py +24 -0
- core_framework/worker/schedules/schedule_expired_mute_lifts.py +24 -0
- core_framework/worker/tasks/__init__.py +11 -0
- core_framework/worker/tasks/process_account_deletion.py +13 -0
- core_framework/worker/tasks/process_aggregate_comment_stats.py +19 -0
- core_framework/worker/tasks/process_aggregate_post_stats.py +12 -0
- core_framework/worker/tasks/process_mute_lift.py +13 -0
- core_framework-0.3.0.dist-info/METADATA +22 -0
- core_framework-0.3.0.dist-info/RECORD +222 -0
- core_framework-0.3.0.dist-info/WHEEL +4 -0
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Generic single-database configuration with an async dbapi.
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
if config.config_file_name is not None:
|
|
17
|
+
fileConfig(config.config_file_name)
|
|
18
|
+
|
|
19
|
+
target_metadata = None
|
|
20
|
+
|
|
21
|
+
config.set_main_option("sqlalchemy.url", settings.write_postgres.alembic_postgres_url)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def run_migrations_offline() -> None:
|
|
25
|
+
"""Run migrations in 'offline' mode."""
|
|
26
|
+
url = config.get_main_option("sqlalchemy.url")
|
|
27
|
+
context.configure(
|
|
28
|
+
url=url,
|
|
29
|
+
target_metadata=target_metadata,
|
|
30
|
+
literal_binds=True,
|
|
31
|
+
dialect_opts={"paramstyle": "named"},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
with context.begin_transaction():
|
|
35
|
+
context.run_migrations()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def do_run_migrations(connection: Connection) -> None:
|
|
39
|
+
quoted_schema_name = f'"{settings.postgres_schemas.schema_comment.replace('"', '""')}"'
|
|
40
|
+
|
|
41
|
+
connection.execute(text(f"create schema if not exists {quoted_schema_name}"))
|
|
42
|
+
connection.execute(text(f"set search_path to {quoted_schema_name}"))
|
|
43
|
+
connection.commit()
|
|
44
|
+
|
|
45
|
+
context.configure(connection=connection, target_metadata=target_metadata)
|
|
46
|
+
|
|
47
|
+
with context.begin_transaction():
|
|
48
|
+
context.run_migrations()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
async def run_async_migrations() -> None:
|
|
52
|
+
"""Run migrations in 'online' mode."""
|
|
53
|
+
connectable = async_engine_from_config(
|
|
54
|
+
config.get_section(config.config_ini_section, {}),
|
|
55
|
+
prefix="sqlalchemy.",
|
|
56
|
+
poolclass=pool.NullPool,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
async with connectable.connect() as connection:
|
|
60
|
+
await connection.run_sync(do_run_migrations)
|
|
61
|
+
|
|
62
|
+
await connectable.dispose()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def run_migrations_online() -> None:
|
|
66
|
+
asyncio.run(run_async_migrations())
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if context.is_offline_mode():
|
|
70
|
+
run_migrations_offline()
|
|
71
|
+
else:
|
|
72
|
+
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,59 @@
|
|
|
1
|
+
"""init
|
|
2
|
+
|
|
3
|
+
Revision ID: 30334fd1347b
|
|
4
|
+
Revises:
|
|
5
|
+
Create Date: 2026-03-10 06:25:01.802249
|
|
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 = "30334fd1347b"
|
|
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 comment_subject_type as enum (
|
|
23
|
+
'post',
|
|
24
|
+
'user_wall'
|
|
25
|
+
);
|
|
26
|
+
""")
|
|
27
|
+
op.execute("""
|
|
28
|
+
create type comment_status as enum (
|
|
29
|
+
'active',
|
|
30
|
+
'deleted'
|
|
31
|
+
);
|
|
32
|
+
""")
|
|
33
|
+
op.execute("""
|
|
34
|
+
create table comments (
|
|
35
|
+
id varchar(26) primary key,
|
|
36
|
+
author_id varchar(128) not null,
|
|
37
|
+
content text not null,
|
|
38
|
+
subject_type comment_subject_type not null,
|
|
39
|
+
subject_id varchar(128) not null,
|
|
40
|
+
parent_comment_id varchar(26) null references comments(id),
|
|
41
|
+
path text not null,
|
|
42
|
+
level int not null,
|
|
43
|
+
status comment_status not null default 'active',
|
|
44
|
+
edited_at timestamptz null,
|
|
45
|
+
edited_count int not null default 0,
|
|
46
|
+
created_at timestamptz not null default now(),
|
|
47
|
+
updated_at timestamptz not null default now(),
|
|
48
|
+
constraint comments_edited_count_non_negative check (edited_count >= 0),
|
|
49
|
+
constraint comments_level_non_negative check (level >= 0),
|
|
50
|
+
constraint comments_content_not_blank check (length(trim(content)) > 0),
|
|
51
|
+
constraint comments_subject_type_subject_id_path_unique unique (subject_type, subject_id, path)
|
|
52
|
+
);
|
|
53
|
+
""")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def downgrade() -> None:
|
|
57
|
+
op.execute("drop table if exists comments;")
|
|
58
|
+
op.execute("drop type if exists comment_status;")
|
|
59
|
+
op.execute("drop type if exists comment_subject_type;")
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""improve comment indexes
|
|
2
|
+
|
|
3
|
+
Revision ID: a2b3c4d5e6f7
|
|
4
|
+
Revises: f7e6d5c4b3a2
|
|
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 = "a2b3c4d5e6f7"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "f7e6d5c4b3a2"
|
|
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_comments_subject_created
|
|
23
|
+
on comments (subject_type, subject_id, created_at desc)
|
|
24
|
+
where status = 'active'
|
|
25
|
+
""")
|
|
26
|
+
|
|
27
|
+
op.execute("""
|
|
28
|
+
create index idx_comments_author_created
|
|
29
|
+
on comments (author_id, created_at desc)
|
|
30
|
+
where status = 'active'
|
|
31
|
+
""")
|
|
32
|
+
|
|
33
|
+
op.execute("drop index if exists idx_comments_parent_comment_id")
|
|
34
|
+
op.execute("""
|
|
35
|
+
create index idx_comments_parent_created
|
|
36
|
+
on comments (parent_comment_id, created_at desc)
|
|
37
|
+
where status = 'active'
|
|
38
|
+
""")
|
|
39
|
+
|
|
40
|
+
op.execute("""
|
|
41
|
+
create index idx_comment_likes_liker_id
|
|
42
|
+
on comment_likes (liker_id)
|
|
43
|
+
""")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def downgrade() -> None:
|
|
47
|
+
op.execute("drop index if exists idx_comment_likes_liker_id")
|
|
48
|
+
op.execute("drop index if exists idx_comments_parent_created")
|
|
49
|
+
op.execute("""
|
|
50
|
+
create index idx_comments_parent_comment_id
|
|
51
|
+
on comments (parent_comment_id)
|
|
52
|
+
""")
|
|
53
|
+
op.execute("drop index if exists idx_comments_author_created")
|
|
54
|
+
op.execute("drop index if exists idx_comments_subject_created")
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""add extra tables
|
|
2
|
+
|
|
3
|
+
Revision ID: bcc8e00cfc8b
|
|
4
|
+
Revises: 30334fd1347b
|
|
5
|
+
Create Date: 2026-03-12 06:08:09.681774
|
|
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 = "bcc8e00cfc8b"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "30334fd1347b"
|
|
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_likes (
|
|
23
|
+
comment_id varchar(26) not null references comments(id) on delete cascade,
|
|
24
|
+
liker_id varchar(128) not null,
|
|
25
|
+
created_at timestamptz not null default now(),
|
|
26
|
+
primary key (comment_id, liker_id)
|
|
27
|
+
);
|
|
28
|
+
""")
|
|
29
|
+
op.execute("""
|
|
30
|
+
create table comment_stats (
|
|
31
|
+
comment_id varchar(26) primary key references comments(id) on delete cascade,
|
|
32
|
+
like_count bigint not null default 0,
|
|
33
|
+
reply_count bigint not null default 0,
|
|
34
|
+
report_count bigint not null default 0,
|
|
35
|
+
created_at timestamptz not null default now(),
|
|
36
|
+
updated_at timestamptz not null default now(),
|
|
37
|
+
constraint comment_stats_like_count_non_negative check (like_count >= 0),
|
|
38
|
+
constraint comment_stats_reply_count_non_negative check (reply_count >= 0),
|
|
39
|
+
constraint comment_stats_report_count_non_negative check (report_count >= 0)
|
|
40
|
+
);
|
|
41
|
+
""")
|
|
42
|
+
op.execute("""
|
|
43
|
+
create table user_restrictions_lookup (
|
|
44
|
+
user_id varchar(128) primary key,
|
|
45
|
+
restriction_type varchar(16) not null,
|
|
46
|
+
constraint user_restrictions_lookup_restriction_type_valid
|
|
47
|
+
check (restriction_type in ('muted', 'banned'))
|
|
48
|
+
);
|
|
49
|
+
""")
|
|
50
|
+
op.execute("""
|
|
51
|
+
create table user_blocks_lookup (
|
|
52
|
+
blocker_id varchar(128) not null,
|
|
53
|
+
blocked_id varchar(128) not null,
|
|
54
|
+
primary key (blocker_id, blocked_id),
|
|
55
|
+
constraint user_blocks_lookup_no_self_block check (blocker_id != blocked_id)
|
|
56
|
+
);
|
|
57
|
+
""")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def downgrade() -> None:
|
|
61
|
+
op.execute("drop table if exists user_blocks_lookup;")
|
|
62
|
+
op.execute("drop table if exists user_restrictions_lookup;")
|
|
63
|
+
op.execute("drop table if exists comment_stats;")
|
|
64
|
+
op.execute("drop table if exists comment_likes;")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""add comment_stats_dirty table
|
|
2
|
+
|
|
3
|
+
Revision ID: d1e2f3a4b5c6
|
|
4
|
+
Revises: bcc8e00cfc8b
|
|
5
|
+
Create Date: 2026-03-14
|
|
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 = "d1e2f3a4b5c6"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "bcc8e00cfc8b"
|
|
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_stats_dirty (
|
|
23
|
+
comment_id varchar(26) primary key references comments(id) on delete cascade
|
|
24
|
+
);
|
|
25
|
+
""")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def downgrade() -> None:
|
|
29
|
+
op.execute("drop table if exists comment_stats_dirty;")
|
core_framework/alembic/comment/alembic/versions/e3f4a5b6c7d8_cascade_delete_comment_descendants.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""cascade delete comment descendants
|
|
2
|
+
|
|
3
|
+
Revision ID: e3f4a5b6c7d8
|
|
4
|
+
Revises: d1e2f3a4b5c6
|
|
5
|
+
Create Date: 2026-03-17 18:40: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 = "e3f4a5b6c7d8"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "d1e2f3a4b5c6"
|
|
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 if not exists idx_comments_parent_comment_id
|
|
23
|
+
on comments (parent_comment_id);
|
|
24
|
+
""")
|
|
25
|
+
op.execute("""
|
|
26
|
+
alter table comments
|
|
27
|
+
drop constraint if exists comments_parent_comment_id_fkey;
|
|
28
|
+
""")
|
|
29
|
+
op.execute("""
|
|
30
|
+
alter table comments
|
|
31
|
+
add constraint comments_parent_comment_id_fkey
|
|
32
|
+
foreign key (parent_comment_id)
|
|
33
|
+
references comments(id)
|
|
34
|
+
on delete cascade;
|
|
35
|
+
""")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def downgrade() -> None:
|
|
39
|
+
op.execute("""
|
|
40
|
+
alter table comments
|
|
41
|
+
drop constraint if exists comments_parent_comment_id_fkey;
|
|
42
|
+
""")
|
|
43
|
+
op.execute("""
|
|
44
|
+
alter table comments
|
|
45
|
+
add constraint comments_parent_comment_id_fkey
|
|
46
|
+
foreign key (parent_comment_id)
|
|
47
|
+
references comments(id);
|
|
48
|
+
""")
|
|
49
|
+
op.execute("drop index if exists idx_comments_parent_comment_id;")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""comments path to ltree
|
|
2
|
+
|
|
3
|
+
Revision ID: f7e6d5c4b3a2
|
|
4
|
+
Revises: e3f4a5b6c7d8
|
|
5
|
+
Create Date: 2026-03-19 12:00:00.000000
|
|
6
|
+
|
|
7
|
+
Requires: ltree extension installed in the extension schema (see
|
|
8
|
+
alembic/extension migration c9d0e1f2a3b4). Apply extension migrations
|
|
9
|
+
before this revision.
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
|
|
15
|
+
from alembic import op
|
|
16
|
+
|
|
17
|
+
# revision identifiers, used by Alembic.
|
|
18
|
+
revision: str = "f7e6d5c4b3a2"
|
|
19
|
+
down_revision: str | Sequence[str] | None = "e3f4a5b6c7d8"
|
|
20
|
+
branch_labels: str | Sequence[str] | None = None
|
|
21
|
+
depends_on: str | Sequence[str] | None = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def upgrade() -> None:
|
|
25
|
+
op.execute("""
|
|
26
|
+
alter table comments
|
|
27
|
+
drop constraint if exists comments_subject_type_subject_id_path_unique;
|
|
28
|
+
""")
|
|
29
|
+
op.execute("""
|
|
30
|
+
alter table comments
|
|
31
|
+
alter column path type extension.ltree
|
|
32
|
+
using extension.text2ltree(path);
|
|
33
|
+
""")
|
|
34
|
+
op.execute("""
|
|
35
|
+
alter table comments
|
|
36
|
+
add constraint comments_subject_type_subject_id_path_unique
|
|
37
|
+
unique (subject_type, subject_id, path);
|
|
38
|
+
""")
|
|
39
|
+
op.execute("""
|
|
40
|
+
create index idx_comments_path_gist
|
|
41
|
+
on comments using gist (path);
|
|
42
|
+
""")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def downgrade() -> None:
|
|
46
|
+
op.execute("drop index if exists idx_comments_path_gist;")
|
|
47
|
+
op.execute("""
|
|
48
|
+
alter table comments
|
|
49
|
+
drop constraint if exists comments_subject_type_subject_id_path_unique;
|
|
50
|
+
""")
|
|
51
|
+
op.execute("""
|
|
52
|
+
alter table comments
|
|
53
|
+
alter column path type text
|
|
54
|
+
using path::text;
|
|
55
|
+
""")
|
|
56
|
+
op.execute("""
|
|
57
|
+
alter table comments
|
|
58
|
+
add constraint comments_subject_type_subject_id_path_unique
|
|
59
|
+
unique (subject_type, subject_id, path);
|
|
60
|
+
""")
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
# sys.path path, will be prepended to sys.path if present.
|
|
11
|
+
prepend_sys_path = .
|
|
12
|
+
|
|
13
|
+
path_separator = os
|
|
14
|
+
|
|
15
|
+
sqlalchemy.url = driver://user:pass@localhost/dbname
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
[post_write_hooks]
|
|
19
|
+
|
|
20
|
+
[loggers]
|
|
21
|
+
keys = root,sqlalchemy,alembic
|
|
22
|
+
|
|
23
|
+
[handlers]
|
|
24
|
+
keys = console
|
|
25
|
+
|
|
26
|
+
[formatters]
|
|
27
|
+
keys = generic
|
|
28
|
+
|
|
29
|
+
[logger_root]
|
|
30
|
+
level = WARNING
|
|
31
|
+
handlers = console
|
|
32
|
+
qualname =
|
|
33
|
+
|
|
34
|
+
[logger_sqlalchemy]
|
|
35
|
+
level = WARNING
|
|
36
|
+
handlers =
|
|
37
|
+
qualname = sqlalchemy.engine
|
|
38
|
+
|
|
39
|
+
[logger_alembic]
|
|
40
|
+
level = INFO
|
|
41
|
+
handlers =
|
|
42
|
+
qualname = alembic
|
|
43
|
+
|
|
44
|
+
[handler_console]
|
|
45
|
+
class = StreamHandler
|
|
46
|
+
args = (sys.stderr,)
|
|
47
|
+
level = NOTSET
|
|
48
|
+
formatter = generic
|
|
49
|
+
|
|
50
|
+
[formatter_generic]
|
|
51
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
52
|
+
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_extension.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()
|
|
@@ -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,25 @@
|
|
|
1
|
+
"""add pg_trgm extension
|
|
2
|
+
|
|
3
|
+
Revision ID: 0389226049cb
|
|
4
|
+
Revises: b0ba0d8a284e
|
|
5
|
+
Create Date: 2026-02-08 13:38:47.721189
|
|
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 = "0389226049cb"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "b0ba0d8a284e"
|
|
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("create extension pg_trgm")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def downgrade() -> None:
|
|
25
|
+
op.execute("drop extension if exists pg_trgm")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""add citext extension
|
|
2
|
+
|
|
3
|
+
Revision ID: 5dc58b016cf5
|
|
4
|
+
Revises:
|
|
5
|
+
Create Date: 2025-12-26 08:31:16.109190
|
|
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 = "5dc58b016cf5"
|
|
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("create extension citext")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def downgrade() -> None:
|
|
25
|
+
op.execute("drop extension if exists citext")
|
core_framework/alembic/extension/alembic/versions/b0ba0d8a284e_add_pg_stat_statements_extension.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""add pg_stat_statements extension
|
|
2
|
+
|
|
3
|
+
Revision ID: b0ba0d8a284e
|
|
4
|
+
Revises: 5dc58b016cf5
|
|
5
|
+
Create Date: 2026-01-06 06:34:34.095569
|
|
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 = "b0ba0d8a284e"
|
|
15
|
+
down_revision: str | Sequence[str] | None = "5dc58b016cf5"
|
|
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("create extension pg_stat_statements")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def downgrade() -> None:
|
|
25
|
+
op.execute("drop extension if exists pg_stat_statements")
|