Build a Twitter Clone With Adonis and Vue

User Model and Migration

With the setup out of the way, let's begin fleshing out the API. We'll start by creating the User model and its corresponding migration file which will be used to build the schema of the users table. Luckily for us, AdonisJS comes with a User model and it migration file by default. All we have to do is modify it to suit the Tweetr app.

Open database/migrations/TIMESTAMP_user.js and update the up method as below:

// database/migrations/TIMESTAMP_user.js

up () {
    this.create('users', table => {
        table.increments()
        table.string('name').notNullable()
        table.string('username', 80).notNullable().unique()
        table.string('email', 254).notNullable().unique()
        table.string('password', 60).notNullable()
        table.string('location').nullable()
        table.string('website_url').nullable()
        table.text('bio').nullable()
        table.timestamps()
    })
}

The schema above will create a users table with the following fields:

  • id
  • name
  • username
  • email
  • password
  • profile_pic
  • created_at
  • updated_at

The increments() will create an id field with Auto Increment and set it as Primary key. The timestamps() will create the created_at and updated_at fields respectively.

Next, run the migration:

adonis migration:run