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

Alembic couldn't create table alembic_version

Open Xastur opened this issue 5 months ago • 12 comments

Describe the bug When you run migration alembic couldn't create table alembic_version

To Reproduce No migrations files in versions folder of alembic.

Docker-file

clickhouse-db:
  image: clickhouse/clickhouse-server:23.8.9-alpine
  container_name: cp-clickhouse-db
  environment:
    CLICKHOUSE_USER: clickhouse
    CLICKHOUSE_PASSWORD: clickhouse
    CLICKHOUSE_DB: operations
    CLICKHOUSE_HTTP_PORT: 8123
    CLICKHOUSE_TCP_PORT: 9000
    CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
  ports:
    - 9000:9000
    - 8123:8123
  volumes:
    - cp-clickhouse-db:/var/lib/clickhouse

python. part of env.py of alembic `

def run_migrations_online() -> None:
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    configuration = config.get_section(config.config_ini_section)
    configuration["sqlalchemy.url"] = gl_config.clickhouse_operations_db_dsn
    connectable = engine_from_config(
        configuration,
        prefix="sqlalchemy.",
        poolclass=pool.NullPool,
    )

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            include_object=include_object,
            compare_type=True,
        )

        with context.begin_transaction():
            patch_alembic_version(context)
            context.run_migrations()

if context.is_offline_mode():
    run_migrations_offline()
else:
    run_migrations_online()

`

when I run application using commands alembic_cfg = Config("database/migrations/alembic.ini") command.upgrade(alembic_cfg, "schema@head")

it shows error sqlalchemy.exc.DuplicateColumnError: A column with name 'version_num' is already present in table 'alembic_version'. Specify replace_existing=True to Table.append_column() to replace an existing column.

Expected behavior table alembic_version has to be created in db.

version clickhouse-sqlalchemy 0.1.9 does not have the problem

Versions

  • Version of package with the problem: 0.3.0
  • Python version: 3.10.8

Xastur avatar Jan 24 '24 06:01 Xastur