готово

This commit is contained in:
2026-11-12 19:38:03 +03:00
parent ec540a1a72
commit f3ba37f736
142 changed files with 10257 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
"""Сохранение допустимого Unicode имён и названий, включая U+0000."""
import sqlalchemy as sa
from alembic import op
revision = "006"
down_revision = "005"
branch_labels = None
depends_on = None
def upgrade():
for table, column in [("users", "display_name"), ("chats", "title")]:
op.drop_constraint(f"{table}_{column}_check", table, type_="check")
op.alter_column(
table,
column,
existing_type=sa.String(100),
type_=sa.LargeBinary(),
existing_nullable=False,
postgresql_using=f"convert_to({column}, 'UTF8')",
)
op.create_check_constraint(
f"{table}_{column}_bytes_check", table, f"octet_length({column}) BETWEEN 1 AND 400"
)
def downgrade():
# PostgreSQL откажет при U+0000 и откатит транзакцию вместо потери символов.
for table, column in [("users", "display_name"), ("chats", "title")]:
op.drop_constraint(f"{table}_{column}_bytes_check", table, type_="check")
op.alter_column(
table,
column,
existing_type=sa.LargeBinary(),
type_=sa.String(100),
existing_nullable=False,
postgresql_using=f"convert_from({column}, 'UTF8')",
)
op.create_check_constraint(f"{table}_{column}_check", table, f"length(trim({column})) > 0")