Duck Model

In this step, we will create our first data model and create a corresponding table using a migration

Duck model#

Now that our application has a database connection, and we are ready to create and run our migrations, we can add our duck table so that we can implement our first endpoints.


Start by creating a new migration.

You should now see the migration file in db/migrations.

In the duck table, we need three columns:

Using PostgreSQL's syntax, we need something like this in ourcreate_duck_table migration:

To explain the query above, the id column is our primary key and as it is a CUID, we need to make it 30 char long to follow the cuid specs. The username is a unique string of reasonable size (max length 40), and the password is a string of max length 60 which will make more sense later.

Run the migration, roll back, and migrate again to check that everything works as expected.


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

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