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

Fix cli migrate:make sqlite dependency #5106

Merged
merged 2 commits into from Apr 13, 2022

Conversation

dstarke
Copy link
Contributor

@dstarke dstarke commented Apr 6, 2022

This is a proposed fix for #5102 .

Recent changes to how command line options are prioritized relative to configured options in the CLI exposed a bug in migrate:make. If a command line client option was not supplied, the CLI would use sqlite3 instead of whatever is configured in the configuration file. This causes an error in environments where the optional sqlite3 peer dependency is not installed.

This PR alters the CLI initialization for commands that don't care about the client (migrate:make and seed:make) to skip an early check for the presence of a client option, and supply a default value of sqlite3 later in the initialization process where it won't override a configured value.

bin/cli.js Outdated Show resolved Hide resolved
@kibertoad
Copy link
Collaborator

Is it possible to add CLI test for this?

@dstarke
Copy link
Contributor Author

dstarke commented Apr 7, 2022

Is it possible to add CLI test for this?

I don't think this can be done easily with the current CLI testing framework. The error this is attempting to fix only occurs when sqlite3 is not installed, and I don't see how to make that condition happen in a test.

The configuration parameter that causes the problem has (I think) no observable effect on the output of the affected commands, so the testing methodology used for other tests of the CLI -- running a command then checking its output -- doesn't work here.

In more fine-grained unit tests of the internals of the cli code, it might be possible to intercept and check the derived initialization parameters to knex based on various input and configuration setups. I don't see any existing tests of this type for the CLI currently, so figuring out how to do that that would be something of a project (for me, at least, with no prior experience in this repository).

That test would look something like this:

  • create a configuration file with a client option of pg
  • run the command line migrate:make command with no client option specified (or simulate running that command)
  • intercept the knex initialization and check that the client option it was passed was in fact pg

@dstarke
Copy link
Contributor Author

dstarke commented Apr 11, 2022

This issue should be fixed by #5109 . Thanks!

@dstarke
Copy link
Contributor Author

dstarke commented Apr 12, 2022

Unfortunately, #5109 did not fix the issue, and its implementation has conflicts with this one. Also, this solution addressed a lot of issues that the proposed fix in #5111 does not.

My suggestion would be to roll back the previous change, and apply this one. If someone wants to help with a test case, I would happily include it, but the fact that the test case in the original accepted solution did not catch the error illustrates my earlier notes about how difficult it is to construct a test for this problem.

@dstarke dstarke reopened this Apr 12, 2022
@OlivierCavadenti
Copy link
Collaborator

@dstarke can you rebase ? I am quite sorry about conflicts with my PR by the way.

@dstarke
Copy link
Contributor Author

dstarke commented Apr 12, 2022

@OlivierCavadenti I'll look at it now.

alternate cli initialization for commands that don’t need a client specified

create a default client when needed

code style fixes

code style fix

fix rollback issues
@dstarke dstarke force-pushed the fix-cli-migrate-make-sqlite-dependency branch from 84f58d3 to 176d293 Compare April 12, 2022 19:55
@coveralls
Copy link

coveralls commented Apr 12, 2022

Coverage Status

Coverage increased (+0.004%) to 92.277% when pulling a5055bc on dstarke:fix-cli-migrate-make-sqlite-dependency into f2a7527 on knex:master.

@dstarke
Copy link
Contributor Author

dstarke commented Apr 12, 2022

@OlivierCavadenti Ok, I think I rebased this correctly. This should roll back only your changes to the CLI and CLI utilities, and replace them with the strategy originally proposed in my earlier implementation. The test you added is still present, but as discussed above, I don't think it actually captures this problem, and I'm not sure how to add one that does.

Copy link
Collaborator

@OlivierCavadenti OlivierCavadenti left a comment

Choose a reason for hiding this comment

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

ok for me. Can you check @kibertoad ?

@kibertoad
Copy link
Collaborator

@dstarke For test: shouldn't it be fairly simple to pass some kind of a fake client and expect it to fail because fake client is preserved?

@dstarke
Copy link
Contributor Author

dstarke commented Apr 12, 2022

@kibertoad I added some tests that work as you described. In order to get the error message propagated to output correctly, I had to wrap the commands for migrate:make and seed:make in a try/catch block to catch and exit with the error (as some other commands do).

@kibertoad kibertoad merged commit 8a3aac3 into knex:master Apr 13, 2022
@fuzzysaj
Copy link

Glad this is working again. Any reason why 1.0.7 is marked as "March 13" on https://knexjs.org/#changelog ?

@kibertoad
Copy link
Collaborator

thx, will fix

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

6 participants