Skip to content

Conversation

@waltaskew
Copy link
Contributor

Include DEFAULT (default_value) stanzas in ALTER COLUMN DDL to avoid removing DEFAULT values when changing a column's type or nullability.

Fixes: #732

Alembic expects `get_column_default_string` to be implemented in order
to use it for  `ALTER TABLE.. ALTER COLUMN .. SET DEFAULT` DDL. In
our case, this means wrapping the default value in parentheses. We
implement `get_column_default_string` and have it add parentheses for
use in both `CREATE TABLE` and `ALTER TABLE` DDL.

Call path for alembic relying on `get_column_default_string` is here:

https://github.com/sqlalchemy/alembic/blob/cd4f404358f101b2b930013c609c074baca61468/alembic/ddl/base.py#L252
https://github.com/sqlalchemy/alembic/blob/cd4f404358f101b2b930013c609c074baca61468/alembic/ddl/base.py#L315
Include `DEFAULT (default_value)` stanzas in `ALTER COLUMN` DDL to
avoid removing `DEFAULT` values when changing a column's type or
nullability.

Fixes: googleapis#732
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API. label Aug 4, 2025
olavloite
olavloite previously approved these changes Aug 18, 2025
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 18, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 18, 2025
@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 18, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 18, 2025
@olavloite olavloite requested a review from bhatt4982 August 18, 2025 13:50
Copy link
Contributor

@bhatt4982 bhatt4982 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM...

@bhatt4982 bhatt4982 merged commit 1f8a25f into googleapis:main Aug 18, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/python-spanner-sqlalchemy API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ALTER COLUMN DDL Removes DEFAULTs

4 participants