We will run our migration and learn how to roll back the 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#
If you now open your database and inspect it, you will see two new tables. One
entry table we made in the last lesson for our Quacker app, and one is
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
nessie_migrations you will see an entry corresponding to the migration you
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.