Build a Twitter Clone With Adonis and Vue

Follower Migration

Users will be able to follow one another, and we need to create a database table structure that will cater to this. We don't need a separate model for this as it will make use of the User model. We only need to create just the migration file. For that, we'll make use of the Adonis CLI make:migration command:

 adonis make:migration followers

Then select Create table on the prompt.

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

// database/migrations/TIMESTAMP_followers_schema.js

up () {
    this.create('followers', (table) => {
        table.increments()
        table.integer('user_id').unsigned().notNullable()
        table.integer('follower_id').unsigned().notNullable()
        table.timestamps()
    })
}

This will create a followers table with the following fields:

  • id
  • user_id
  • follower_id
  • created_at
  • updated_at

Next, run the migration:

 adonis migration:run