Run Migration

We will run our migration and learn how to roll back the migration

Run migration#

In the previous steps, we created and edited the migration file, and now it is time to test it out. Simply execute this line in your terminal, at the root of your project folder, and watch the migration run.

Viewing the database#

To view the database, you can use paid-for tools likeDataGrip,TablePlus, a free VSCode extension of your choice, or the command-line interface.

If you now open your database and inspect it, you will see two new tables. One is the entry table we made in the last lesson for our Quacker app, and one is called nessie_migrations. When Nessie runs (and succeeds at) a migration, it will add an entry to this table to record which migrations have been run. It includes the file name and the execution timestamp. When you run the migrations for the first time, Nessie will check your database for the existence of the migration table, and if it doesn't exist, it will be created. If you look inside of nessie_migrations you will see an entry corresponding to the migration you just ran.

If the table exists, and it has an entry, it will only run the migrations with a timestamp later than the latest entry in the database, hence the timestamp prefix of the migration files. (See the example at the end of this lesson.)

If you don't want to run all of the migrations in your project, you can also choose the number of migrations to run. Add an argument to run a maximum of two migrations.

Rolling back migration#

As you are developing a migration, you might want to test it along the way. Imagine that you now want to add the number of "likes" to the table. We start by rolling back the migration so that we can do the necessary changes.

 

This page is a preview of Build and deploy a REST API with Deno

Start a new discussion. All notification go to the author.