-
Notifications
You must be signed in to change notification settings - Fork 226
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 can be provided as a map of loaded modules #203
Conversation
Ah, interesting idea. So I want to say first, while I have in the past used a bundler on server code I don't think it is a good practice. So if we add this I don't think we should do so just because of the bundler use case. That said, I think a strategy to define migrations without dynamic filesystem require/imports is good. Technically you can do it already by using the library exports and not the cli, but I don't think that is very ergonomic. I think the main thing that is missing here now is sorting. Because map keys are not sorted, to get the "same behavior" for ordering you need to sort the keys before adding them. And two nit picks:
|
Thanks for the prompt response. I will try to address the points you raised:
|
That makes sense. I have run this tool as my app starts up before, just not in lambda. Are you running them when each lambda instances spins up? Not bad, just interesting for me to learn and understand how folks are using the lib.
Ah, yeah that makes sense. Honestly I would say that is a failure of the design of that part. A long time ago I started a refactor which should have fixed these issues, just never had the time to finish that. Would love to see that as a PR sometime if you were ever interested.
Ah, maybe I missed something there. I can take another look. I guess as long as there are tests for both which meet the same result it should be good.
Yep!
It is not a |
Are you asking when do we run webpack? We use Continuous Deployment pipeline where each new release gets bundled using webpack and packaged by serverless framework into a zip archive before being deployed to production. We also use webpack's "source-maps" options to get proper error stack traces. If you're asking when we run
Technically javascript Objects are Maps where properties are string keys. And we've all been using Objects as maps in javascript before ES6 introduced the actual Map type :) In any case, I renamed the option to How do we proceed further? Can we merge the PR? |
Yeah that is what I was asking. Because bundling this code only makes sense if you need to run it in the lambda. Anyway, not a big deal and I agree this is a good feature.
Yes, but now that there is an actual implementation called map, using that as a suffix typically implies it should be a
Taking a look, but yeah I think it should be good. |
Readme.md
Outdated
@@ -230,6 +230,7 @@ Calls the callback with a `Set` based on the options passed. Options: | |||
|
|||
- `set`: A set instance if you created your own | |||
- `stateStore`: A store instance to load and store migration state, or a string which is a path to the migration state file | |||
- `migrations`: An object where keys are migration file names and values are migration modules loaded with `require()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `migrations`: An object where keys are migration file names and values are migration modules loaded with `require()` | |
- `migrations`: An object where keys are migration names and values are migration objects |
I think they can be loaded however you want, you can define them inline if you want. I don't think we need to specify "with require"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point.
Made a couple of final comments. But yeah, other than those I can merge and release this. |
@wesleytodd I applied you suggestions in my latest commits. Let me know if there is anything else. Thanks again |
Hey, sorry busy day. I probably wont be able to get to this tonight but will try and look in the morning. |
Hey @wesleytodd :) whenever you get a chance to take another look. Thanks 👍 |
hey @wesleytodd just bumping this PR as a friendly reminder :) there are few minor changes really. Thanks |
Sorry looks like I dropped the ball on this. Taking a look now. |
Looks like I still can't change the settings to allow the actions to run on this PR. @tj it would be great if you could make me an administrator on this repo. I almost moved it into my account once before because of this, maybe I should just do that. I will pull it down and manually run the tests and stuff I guess. |
Released as 2.1.0 |
Currently it's not possible to use
node-migrate
with packagers relying on static analysis (e.g. webpack) because they need to know all module and file dependencies during bundling. Unfortunately thenode-migrate
package is dynamically loading migration files inlib/load-migrations.js
usingrequire(filepath)
wherefilepath
is a variable hence webpack cannot infer during compile time what folders and files to include for bundling in the final output.This small PR solves the problem by introducing a new
migrationsMap
property in the options that are provided to themigrate.load(opts, cb)
function like so:This way there is no need to scan the migrations directory to include the migration files dynamically since they are statically included in the migrationsMap so they will be included by the bundlers like webpack.
The
migrationsDirectory
is ignored for loading files when themigrationsMap
option is provded.