From adcccacc587abbffa492e98d71ed5b305a447473 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 18 Jun 2025 21:47:18 -0400 Subject: [PATCH] demo mysql alter for collate/charset Change-Id: I80cf0ccea6023c1e3411eaf6eeec7b2e5acb73e5 --- tests/test_mysql.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_mysql.py b/tests/test_mysql.py index a23c9d73..e155077f 100644 --- a/tests/test_mysql.py +++ b/tests/test_mysql.py @@ -9,9 +9,11 @@ from sqlalchemy import Identity from sqlalchemy import inspect from sqlalchemy import Integer from sqlalchemy import MetaData +from sqlalchemy import String from sqlalchemy import Table from sqlalchemy import text from sqlalchemy import TIMESTAMP +from sqlalchemy.dialects.mysql import VARCHAR from alembic import op from alembic import util @@ -240,6 +242,22 @@ class MySQLOpTest(TestBase): op.invoke(operation) context.assert_("ALTER TABLE t MODIFY c FLOAT NULL DEFAULT 0") + def test_alter_column_change_collation(self): + context = op_fixture("mysql") + op.alter_column( + "t1", + "c1", + nullable=False, + existing_type=String(50), + type_=VARCHAR( + 50, charset="utf8mb4", collation="utf8mb4/utf8mb4_unicode_ci" + ), + ) + context.assert_( + "ALTER TABLE t1 MODIFY c1 VARCHAR(50) " + "CHARACTER SET utf8mb4 COLLATE utf8mb4/utf8mb4_unicode_ci NOT NULL" + ) + def test_col_not_nullable(self): context = op_fixture("mysql") op.alter_column("t1", "c1", nullable=False, existing_type=Integer) -- 2.47.3