-
Notifications
You must be signed in to change notification settings - Fork 225
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
Issue with the custom state storage example #151
Comments
@tj if you concur, I'd be happy to create a pull request with the changes |
Also, I was able to successfully run the script programmatically, i.e. Here is my modified code to attempt to run it from the command line...
And this is the stack trace that it errors out with...
|
Hi @johncmunson, I would happily accept more robust example code as a PR. For your second issue, I think this might not have been the best implementation in hindsight, but the |
Oh, and checking out the example I can see that it is broken in exactly the way I described above. That would be a great part of the PR you can open to fix that. |
@wesleytodd thank you for the feedback. I'll try to find some time later this week to clean up the example and submit a PR. |
@johncmunson did you ever have time to take a look at this? |
I ran into same problem of Store is not a constructor, stacktrace below:
What is the solution to this problem? I have used the code from examples directory to change it to mongodb. |
@krishna-atkalikar, the answer is above:
It is just the example which is wrong. I would be happy to accept a PR fixing the example. |
@wesleytodd created PR #162 |
@krishna-atkalikar, it looks like the PR you opened is a new example. Which is great! But just so others who might land here know, the existing example with |
@wesleytodd I'll try to fix the issue with |
@johncmunson @krishna-atkalikar |
Hi @ceciliazcx, the discussion above has your answer. The example is wrong and the object is not a constructor. Feel free to submit a PR which changes it. |
@wesleytodd
|
EDIT: I was going off the previous posts error message and your code. I was wrong in my OP. You need to post more than this for me to be able to help. The code is fine, but also please post the error message and stack trace you have. |
@ceciliazcx if you are using typescript, do this: // my-store.ts
class Store {
// no constructor declaration
...
async load ...
async save ...
}
export = Store // export NOT exports Then you can have a file somewhere to call programmatically // migration-runner.ts
import * as migrate from 'migrate'
import Store = require('./my-store')
migrate.load({
stateStore: new Store(),
}, (err:any, set:any) => {
...
}) If you keep the store and the runner separated you can then also use the store from the |
@msanguineti Thanks for the TS tip, it put me on the right path and saved me some time with that export! I have some TS types for this lib that I'll try to remember to PR into definitely typed at some point if you're interested. |
Hey @rjhilgefort, you might consider PRing them here. I would be happy to put together a release which contained the types if it had some tests around their validity. That way we can own them and not rely on DT updating them as we make changes. |
Sounds good! They're very much still a WIP, but I'll try to formalize them into a PR once I finish implementing the migration work for the project I'm working on. In the mean time, here's what I have so far- I'm building as I go:
declare module 'migrate' {
export type UnixTimestamp = number
export type MigrationFileName = string
export type Migration = {
title: MigrationFileName
description: string
timestamp: UnixTimestamp
}
export type MigrateState = {
lastRun: MigrationFileName
migrations: Array<Migration>
store: {} // This is `{}` in initial testing, not sure what is stored there.
map: Record<MigrationFileName, Migration>
}
export type LoadCb = (options: {} | null, migrateState: MigrateState) => void
export type SaveCb = () => void
export interface CustomStateStore {
init(): Promise<void>
load(fn: LoadCb): Promise<void>
save(set: MigrateState, fn: SaveCb): Promise<void>
}
} |
I needed the ability to store the state of my migrations in the database itself. I noticed that there was an example for doing so. Luckily, I was already using postgres as my database just like in the example, so I realized I could use the example code pretty much as-is.
To get it to work though, I needed to add in some extra error handling to account for the first time migrations ever get run. It appears that there was already an attempt to account for this, but I don't believe it was enough. Please see below for my modifications.
The text was updated successfully, but these errors were encountered: