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

Define custom prefixes for creating new migrations #585

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

oetherington
Copy link

This PR allows the user to specify a custom format for the filename prefix used when creating new migrations. This is currently only possible by returning a different filename from the template callback, but this doesn't happen until after ordering is resolved and so can easily lead to "confusing ordering" issues. This is primarily motivated by wanting to avoid dots in the filename timestamp, but could be useful for other reasons too such as using a counter instead of a timestamp.

Copy link
Contributor

@mmkal mmkal left a comment

Choose a reason for hiding this comment

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

Couple of comments

async create(options: {
name: string;
folder?: string;
prefix?: 'TIMESTAMP' | 'DATE' | 'NONE';
prefix?: MigrationPrefix;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit confusing having two places to setup the prefix. Can we deprecate this one with a warning message?

* A function for generating custom prefixes for migration files when using `create`. If this is not specified the default date formats will
* be used ("1970.01.01T00.00.00" for TIMESTAMP, "1970.01.01" for DATE and "" for NONE)
*/
prefix?: (prefix: MigrationPrefix) => string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
prefix?: (prefix: MigrationPrefix) => string;
prefix?: (params: {name: string}) => string;

I like this approach but we can go further. The MigrationPrefix type isn't really useful anymore. Let's deprecate it and just pass the name in and let the user define a function that does whatever they need. The default can still be the dot-separated date format that's currently used.

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.

2 participants