mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Add pivot table
This commit is contained in:
27
database/migrations/1629148789980_post_tag.ts
Normal file
27
database/migrations/1629148789980_post_tag.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
27
database/migrations/1629149023037_project_tag.ts
Normal file
27
database/migrations/1629149023037_project_tag.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user