Skip to content

Limit trigger names to 64 characters. #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions partitionmanager/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,13 @@ def test_migrate_cmd_in(self):
+ "`p_20210521` VALUES LESS THAN (300), PARTITION "
+ "`p_20210620` VALUES LESS THAN MAXVALUE);",
"CREATE OR REPLACE TRIGGER copy_inserts_from_"
+ "partitioned_yesterday_to_partitioned_yesterday_new_20210421",
+ "partitioned_yesterday_to_partitioned_yesterday",
"\tAFTER INSERT ON partitioned_yesterday FOR EACH ROW",
"\t\tINSERT INTO partitioned_yesterday_new_20210421 SET",
"\t\t\t`id` = NEW.`id`,",
"\t\t\t`serial` = NEW.`serial`;",
"CREATE OR REPLACE TRIGGER copy_updates_from_"
+ "partitioned_yesterday_to_partitioned_yesterday_new_20210421",
+ "partitioned_yesterday_to_partitioned_yesterday",
"\tAFTER UPDATE ON partitioned_yesterday FOR EACH ROW",
"\t\tUPDATE partitioned_yesterday_new_20210421 SET",
"\t\t\t`serial` = NEW.`serial`",
Expand Down
17 changes: 15 additions & 2 deletions partitionmanager/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def _trigger_column_copies(cols):
yield f"`{c}` = NEW.`{c}`"


def _make_trigger_name(name):
""" Helper that enforces the trigger must be <= 64 chars """
return name[:64]


def _generate_sql_copy_commands(
existing_table, map_data, columns, new_table, alter_commands_iter
):
Expand Down Expand Up @@ -175,7 +180,11 @@ def _generate_sql_copy_commands(

cols = set(columns)

yield f"CREATE OR REPLACE TRIGGER copy_inserts_from_{existing_table.name}_to_{new_table.name}"
inserts_trigger_name = _make_trigger_name(
f"copy_inserts_from_{existing_table.name}_to_{new_table.name}"
)

yield f"CREATE OR REPLACE TRIGGER {inserts_trigger_name}"
yield f"\tAFTER INSERT ON {existing_table.name} FOR EACH ROW"
yield f"\t\tINSERT INTO {new_table.name} SET"

Expand All @@ -192,7 +201,11 @@ def _generate_sql_copy_commands(
log.info("No columns to copy, so no UPDATE trigger being constructed.")
return

yield f"CREATE OR REPLACE TRIGGER copy_updates_from_{existing_table.name}_to_{new_table.name}"
updates_trigger_name = _make_trigger_name(
f"copy_updates_from_{existing_table.name}_to_{new_table.name}"
)

yield f"CREATE OR REPLACE TRIGGER {updates_trigger_name}"
yield f"\tAFTER UPDATE ON {existing_table.name} FOR EACH ROW"
yield f"\t\tUPDATE {new_table.name} SET"

Expand Down