Add pivot table

This commit is contained in:
2021-08-16 23:24:39 +02:00
parent 9a438587e0
commit 5c3dd37758
5 changed files with 64 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
export default class PostTags extends BaseSchema {
protected tableName = 'post_tag'
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table
.integer('post_id')
.unsigned()
.references('posts.id')
.onDelete('CASCADE')
table
.integer('tag_id')
.unsigned()
.references('tags.id')
.onDelete('CASCADE')
table.unique(['post_id', 'tag_id'])
table.timestamps(true, true)
})
}
public async down () {
this.schema.dropTable(this.tableName)
}
}

View File

@@ -0,0 +1,27 @@
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
export default class ProjectTags extends BaseSchema {
protected tableName = 'project_tag'
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table
.integer('project_id')
.unsigned()
.references('projects.id')
.onDelete('CASCADE')
table
.integer('tag_id')
.unsigned()
.references('tags.id')
.onDelete('CASCADE')
table.unique(['project_id', 'tag_id'])
table.timestamps(true, true)
})
}
public async down () {
this.schema.dropTable(this.tableName)
}
}