sqlalchemy / alembic

A database migrations tool for SQLAlchemy.
MIT License
2.89k stars 247 forks source link

Initial work to support Starrocks DB #1561

Closed maver1ck closed 3 weeks ago

maver1ck commented 3 weeks ago

I want to use Alembic with Starrocks database.

To achieve this I need to patch alembic_version table with following code

def patch_alembic_version(context, **kwargs):
    migration_context = context._proxy._migration_context
    old_version = migration_context._version
    metadata = old_version.metadata
    metadata.remove(old_version)

    version = Table(
        'alembic_version',
        metadata,
        Column('id', types.BIGINT, autoincrement=True, primary_key=True),
        Column('version_num', types.VARCHAR(32), primary_key=False),
        starrocks_primary_key="id"
    )
    migration_context._version = version

This solution works with one exception - select on alembic_version always read version_num from first column.

Description

Fixes: https://github.com/sqlalchemy/alembic/issues/1560

Checklist

This pull request is:

Have a nice day!

zzzeek commented 3 weeks ago

hi -

im not sure what problem you are having but this PR doesn't really make any sense, as it just adds a command to the select() here that would not really change anything since alembic_version already has just that one column.

Please open a discussion with a description of the actual problem you are having including complete error messages / stack trace and we can begin to see where your solution might be.

maver1ck commented 3 weeks ago

Hi @zzzeek I created discussion with explanation of my problem. https://github.com/sqlalchemy/alembic/discussions/1562

Please take a look. TL;DR; this change gives possibility to create alembic_version table with multiple columns.