Home >Web Front-end >JS Tutorial >Sequelize migrations
Given the following sequelize model for my basic todo project's metadata table, I'd like to make some changes using sequelize's migrations.
Sequelize utilizes migration files that are essentially like database commits. To create a migrations file type in your command line:
This will create a migrations file with a template in /migrations folder and the name you provided in the command above (in this case data-columns-rename.js with the current date/time in front).
Template migrations file created for you:
The async up command is the command it runs to try to make changes to the table, and the async down command runs to remove the changes. When you do your migrations, make sure the down commands are in reverse.
In my case, I'm trying to do some column name changes for some basic todo type table information so my filled in migrations table looks like this:
(These changes are simply me still not being used to snake case as desired by postgres)
Once the migrations table is ready, run it with this command
Among other printouts from running the command, the key text for me to see success is:
And you can see the changes verified in this screenshot from DBeaver:
Let me know if there is interest in a post describing the basics of getting started with sequelize.
The above is the detailed content of Sequelize migrations. For more information, please follow other related articles on the PHP Chinese website!