Skip to content

Commit

Permalink
remove ADD PRIMARY KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
Selfeer committed Oct 8, 2024
1 parent 1eee947 commit 5266c0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
17 changes: 9 additions & 8 deletions sink-connector-lightweight/tests/integration/helpers/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,15 @@ def up(self, timeout=30 * 60):
"IMAGE_DEPENDENCY_PROXY", ""
)
self.environ["COMPOSE_HTTP_TIMEOUT"] = "300"
self.environ[
"CLICKHOUSE_TESTS_SERVER_BIN_PATH"
] = self.clickhouse_binary_path
self.environ[
"CLICKHOUSE_TESTS_ODBC_BRIDGE_BIN_PATH"
] = self.clickhouse_odbc_bridge_binary_path or os.path.join(
os.path.dirname(self.clickhouse_binary_path),
"clickhouse-odbc-bridge",
self.environ["CLICKHOUSE_TESTS_SERVER_BIN_PATH"] = (
self.clickhouse_binary_path
)
self.environ["CLICKHOUSE_TESTS_ODBC_BRIDGE_BIN_PATH"] = (
self.clickhouse_odbc_bridge_binary_path
or os.path.join(
os.path.dirname(self.clickhouse_binary_path),
"clickhouse-odbc-bridge",
)
)
self.environ["CLICKHOUSE_TESTS_DIR"] = self.configs_dir

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
"database.serverTimezone": "UTC",
"clickhouse.datetime.timezone": "UTC",
"auto.create.tables": "true",
"ddl.retry": "true"
"ddl.retry": "true",
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
change_column,
modify_column,
drop_column,
add_primary_key,
drop_primary_key,
)


Expand Down Expand Up @@ -592,26 +590,6 @@ def drop_column_on_a_database(self, database):
check_column(table_name=table_name, database=database, column_name="")


@TestScenario
@Requirements(
RQ_SRS_030_ClickHouse_MySQLToClickHouseReplication_PrimaryKey_Simple("1.0")
)
def add_primary_key_on_a_database(self, database):
"""Check that the primary key is added to the table when we add a primary key on a database."""
table_name = f"table_{getuid()}"
column = "col1"

with Given("I create a table on multiple databases"):
create_table_and_insert_values(table_name=table_name, database_name=database)

with When("I add a primary key on the table"):
drop_primary_key(table_name=table_name, database=database)
add_primary_key(table_name=table_name, database=database, column_name=column)

with Then("I check that the primary key was added to the table"):
check_column(table_name=table_name, database=database, column_name=column)


@TestOutline
def check_different_database_names(self, database_map):
"""Check that the tables are replicated when we have source and destination databases with different names."""
Expand Down Expand Up @@ -755,7 +733,6 @@ def check_alters_on_different_databases(self):
change_column_on_a_database,
modify_column_on_a_database,
drop_column_on_a_database,
add_primary_key_on_a_database,
]

check_alters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ def drop_database(self, database_name=None, node=None):

@TestStep(Then)
def check_column(
self, table_name, column_name, node=None, column_type=None, database=None
self,
table_name,
column_name,
node=None,
column_type=None,
database=None,
is_primary_key=False,
):
"""Check if column exists in ClickHouse table."""
"""Check if column exists in ClickHouse table and optionally verify if it is the primary key."""

if database is None:
database = "test"
Expand Down Expand Up @@ -51,6 +57,14 @@ def check_column(

assert column.output.strip() == expected_output, error()

if is_primary_key:
primary_key = node.query(
f"SELECT is_in_primary_key FROM system.columns WHERE database = '{database}' AND table = '{table_name}' AND name = '{column_name}' LIMIT 1 FORMAT TabSeparated"
)
assert primary_key.output.strip() == 1, error(
f"Column {column_name} is not a primary key"
)


@TestStep(Given)
def create_clickhouse_database(self, name=None, node=None):
Expand Down

0 comments on commit 5266c0b

Please sign in to comment.