educt-server/database/migrations/1627750162275_users_courses.ts

19 lines
570 B
TypeScript

import BaseSchema from '@ioc:Adonis/Lucid/Schema';
export default class UsersCourses extends BaseSchema {
protected tableName = 'users_courses';
public async up() {
this.schema.createTable(this.tableName, table => {
table.increments('id');
table.string('user_id', 21).unsigned().references('users.id').onDelete('CASCADE');
table.string('course_id', 21).unsigned().references('courses.id').onDelete('CASCADE');
table.unique(['user_id', 'course_id']);
});
}
public async down() {
this.schema.dropTable(this.tableName);
}
}