Skip to content
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

feat(migrations): add --define flag to apply command #7401

Merged
merged 13 commits into from
Apr 21, 2021

Conversation

jzaralim
Copy link
Contributor

Description

Allow users to define variables using the --define flag when calling apply. For example,

$ ksql-migrations --config-file /my/migrations/project/ksql-migrations.properties apply --next -d foo=bar -d car=3

This commit builds on top of #7366, so you can just review the feat(migrations): add --define flag to apply command commit.

Testing done

Unit test, updated integration test

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@jzaralim jzaralim requested review from JimGalasyn and a team as code owners April 20, 2021 17:19
Copy link
Member

@JimGalasyn JimGalasyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one suggestion.

Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jzaralim ! Only reviewed the last commit -- LGTM besides the comments inline.

for (String pair : definedVars) {
final String[] parts = pair.split("=");
if (parts.length != 2) {
throw new IllegalArgumentException("Variables must be defined using '=' (i.e. var=val).");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your code but let's take this opportunity to improve the error message (the migrations tool displays this error directly so we should make it more informative). Let's include the bad argument in the error message.

Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor suggestion inline. Thanks @jzaralim !

createMigrationFile(2, NAME, migrationsDir, "INSERT INTO FOO VALUES ('${name}2');");
command = PARSER.parse("-a", "-d", "name=tame", "-d", "dame=blame");
createMigrationFile(1, NAME, migrationsDir, "INSERT INTO FOO VALUES ('${name}'); INSERT INTO FOO VALUES ('${dame}');");
createMigrationFile(2, NAME, migrationsDir, "DEFINE name='flame'; INSERT INTO FOO VALUES ('${name}');");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a separate unit test for this piece that verifies the order of precedence between DEFINE statements within migrations files and the command options. (The unit test name does not clarify that this is being tested here, so it's unclear to the reader that this piece of the test is important. Unit tests are meant to be small and quick to run so it doesn't hurt to have more of them, as long as each tests a very targeted piece of functionality.)

@jzaralim jzaralim merged commit 165e972 into confluentinc:master Apr 21, 2021
@jzaralim jzaralim deleted the define-flag branch April 21, 2021 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants