mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import BaseSchema from '@ioc:Adonis/Lucid/Schema';
|
|
|
|
/**
|
|
* Datatypes
|
|
*/
|
|
import CourseStatusEnum from 'App/Datatypes/Enums/CourseStatusEnum';
|
|
|
|
export default class Courses extends BaseSchema {
|
|
protected tableName = 'courses';
|
|
|
|
public async up() {
|
|
this.schema.createTable(this.tableName, table => {
|
|
table.string('id', 21).primary();
|
|
table.json('image');
|
|
table.string('title').notNullable();
|
|
table.string('description').notNullable();
|
|
table.string('teacher_id', 21).unsigned().references('users.id').notNullable().onDelete('CASCADE');
|
|
table.string('category_id', 21).unsigned().references('categories.id').notNullable().onDelete('CASCADE');
|
|
table
|
|
.enu('status', Object.values(CourseStatusEnum), {
|
|
useNative: true,
|
|
enumName: 'course_status_enum',
|
|
existingType: false,
|
|
schemaName: 'public',
|
|
})
|
|
.notNullable();
|
|
table.timestamp('created_at', { useTz: true });
|
|
table.timestamp('updated_at', { useTz: true });
|
|
});
|
|
}
|
|
|
|
public async down() {
|
|
await this.schema.raw('DROP TYPE IF EXISTS "course_status" CASCADE');
|
|
this.schema.dropTable(this.tableName);
|
|
}
|
|
}
|