Skip to content

Support either js and ts migrations in the same database #551

Answered by mmkal
MaxLeiter asked this question in Q&A
Discussion options

You must be logged in to vote

My first instinct is to strongly recommend not using the same database for development and production 🙃

But since this isn't stack overflow, here's one way you could do this using a custom resolve function that wraps the default one:

const umzug = new Umzug({
	migrations: {
		glob:
			process.env.NODE_ENV === "production"
				? __dirname + "/migrations/*.js"
				: __dirname + "/migrations/*.ts",
		resolve: params => {
			const defaultResolver = Umzug.defaultResolver(params)
			return {
				...defaultResolver,
				name: defaultResolver.name.replace(/\.(js|ts)$/, ''),
			}
		},
	},
	context: sequelize.getQueryInterface(),
	storage: new SequelizeStorage({ sequelize }),
	logger: console
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mmkal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #550 on March 30, 2022 00:42.