Skip to content

[BUG] Replicator crashes with DUPLICATE_COLUMN when MySQL migration re-adds existing column #154

@Hussam3bd

Description

@Hussam3bd

Hi team,

I’m using mysql_ch_replicator to replicate data from MySQL to ClickHouse.

When I apply a migration to MySQL that includes ALTER TABLE ADD COLUMN enable_deadline, the replicator crashes with the following error from ClickHouse:

clickhouse_connect.driver.exceptions.DatabaseError: HTTPDriver for http://clickhouse:8123 received ClickHouse error code 15
Code: 15. DB::Exception: Cannot add column `enable_deadline`: column with this name already exists. (DUPLICATE_COLUMN)

Steps to Reproduce

  1. Run the replicator with a MySQL table already replicated to ClickHouse.
  2. Apply a MySQL migration:

ALTER TABLE your_table ADD COLUMN enable_deadline TINYINT(1) DEFAULT 0;

  1. Replicator crashes with the error above.

What I’ve Tried

  • I manually deleted the enable_deadline column from ClickHouse.
  • After re-running the migration and restarting the replicator, the column gets re-added, but the replicator still crashes with the same error.
  • It seems the replicator does not check if a column already exists before generating and executing the ALTER TABLE ADD COLUMN statement in ClickHouse.

Expected Behavior:

The replicator should check if the column already exists in ClickHouse and skip the ADD COLUMN statement if it does, or use a safe mechanism to avoid duplicate column errors.

Suggested Fix:

Before issuing an ALTER TABLE ADD COLUMN in ClickHouse, the replicator should:

  • Query the system.columns table to verify whether the column exists.
  • Skip or log a warning instead of throwing a fatal exception.

Thanks for the great work on the project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions