clickhouse-sqlalchemy icon indicating copy to clipboard operation
clickhouse-sqlalchemy copied to clipboard

Clickhouse alembic array nullable field

Open tvorogme opened this issue 1 year ago • 5 comments

Describe the bug image

Auto-generated migration field on array field:

    op.alter_column('accounts', 'account_state_state_init_code_methods',
               existing_type=clickhouse_sqlalchemy.types.common.Array(Nullable(<class 'clickhouse_sqlalchemy.types.common.Int64'>)),
               nullable=True)

To Reproduce

Add array field to models.py:

account_state_state_init_code_methods = Column(types.Array(types.Nullable(types.Int64)), default=None, nullable=True)

Expected behavior

    op.alter_column('accounts', 'account_state_state_init_code_methods',
               existing_type=clickhouse_sqlalchemy.types.common.Array(Nullable(clickhouse_sqlalchemy.types.common.Int64)),
               nullable=True)

tvorogme avatar Aug 24 '22 13:08 tvorogme

Try Column(types.Array(types.Nullable(types.Int64())) in model definition.

xzkostyan avatar Aug 24 '22 14:08 xzkostyan

WOW! Thanks! this did a trick!!!

Your work is awesome :heart:

tvorogme avatar Aug 24 '22 19:08 tvorogme

Nah, after second migration it fails one more time in existing_type= field:

op.alter_column('accounts', 'account_state_state_init_code_methods',
               existing_type=clickhouse_sqlalchemy.types.common.Array(Nullable(<class 'clickhouse_sqlalchemy.types.common.Int64'>)),
               nullable=True)

(first migration works)

tvorogme avatar Aug 24 '22 19:08 tvorogme

BTW I got strange stuff after running alembic revision --autogenerate right after first migration without any changes:

INFO  [alembic.autogenerate.compare] Detected NULL on column 'transactions.out_msg_value_grams'
INFO  [alembic.autogenerate.compare] Detected NULL on column 'transactions.out_msg_body'
...

I see Nullable(T) columns generation via Column(..., nullable=True) is not supported. in Limitations, but I don't use nullable=True, just Nullable(T). This isn't supported too?

tvorogme avatar Aug 24 '22 20:08 tvorogme

This is complicated. Currently Nullable(T) and nullable=True duplicate each other and produce a big mess. I suppose they both not supported. :)

xzkostyan avatar Aug 24 '22 21:08 xzkostyan