Edit Migration

We will look at how to write a migration script where we create a table

Edit migration#

Continuing with the migration file we created previously, we can now start editing it. Assuming our database is empty, we will add a table to contain an ID, some text, and the date. Think of it as an anonymous and minimalistic Twitter (we can call ours Quacker) 🦆

We have a couple of options here. We can either write the query manually or we can use a query builder (search for query builder inX). As we want to keep the usage of third-party tools to a minimum in this tutorial, I will go for writing the queries in by hand. In theup method in the migration file we created in the last lesson, add this piece of code:

This will create the table called entry when you run the migration, but in the case you need to roll back any changes for testing or other reasons, we also need to populate the down method. Add this piece of code:

 

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

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