import {Injectable, Migration, Inject, DatabaseService, FieldType} from '@extollo/lib'

/**
 * AddCoreidColumnsToUsersTableMigration
 * ----------------------------------
 * Put some description here.
 */
@Injectable()
export default class AddCoreidColumnsToUsersTableMigration extends Migration {
    @Inject()
    protected readonly db!: DatabaseService

    /**
     * Apply the migration.
     */
    async up(): Promise<void> {
        const schema = this.db.get().schema()
        const table = await schema.table('users')

        table.column('tagline')
            .type(FieldType.varchar)
            .nullable()

        table.column('photo_url')
            .type(FieldType.varchar)
            .nullable()

        await schema.commit(table)
    }

    /**
     * Undo the migration.
     */
    async down(): Promise<void> {
        const schema = this.db.get().schema()
        const table = await schema.table('users')

        table.dropColumn('tagline')
        table.dropColumn('photo_url')

        await schema.commit(table)
    }
}
