How migration files are structured and named
masterPostgrator uses a directory of SQL or JavaScript files to manage database changes. Files must follow a specific naming convention:
[version].[action].[optional-description].[extension]
Components:
- Version: A number (e.g.,
001,202310271200). You can use any incrementing scheme. - Action: Must be either
do(to apply the migration) orundo(to revert it). Writingundoscripts is optional. - Optional-description: A label or tag to describe the script. Do not use periods in the description.
- Extension:
.sql,.js,.mjs, or.cjs.
Supported File Types:
- SQL: Plain SQL scripts.
- JavaScript: Modules that export a
generateSql()function. This is useful for using environment variables or performing asynchronous tasks (e.g., fetching data from an API) to generate the SQL string. Note that JS migrations are not checksum validated.
migrations/
|- 001.do.sql
|- 001.undo.sql
|- 002.do.optional-description.sql
|- 002.undo.optional-description.sql
|- 004.do.js
|- 004.undo.js