You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
3 years ago
|
import {Inject, Injectable} from '../di'
|
||
|
import {DatabaseService, FieldType, Migration, Schema} from '../orm'
|
||
|
|
||
|
/**
|
||
|
* Migration that creates the users table used by @extollo/lib.auth.
|
||
|
*/
|
||
|
@Injectable()
|
||
|
export default class CreateUsersTableMigration extends Migration {
|
||
|
@Inject()
|
||
|
protected readonly db!: DatabaseService
|
||
|
|
||
|
async up(): Promise<void> {
|
||
|
const schema: Schema = this.db.get().schema()
|
||
|
const table = await schema.table('users')
|
||
|
|
||
|
table.primaryKey('user_id')
|
||
|
.required()
|
||
|
|
||
|
table.column('first_name')
|
||
|
.type(FieldType.varchar)
|
||
|
.nullable()
|
||
|
|
||
|
table.column('last_name')
|
||
|
.type(FieldType.varchar)
|
||
|
.nullable()
|
||
|
|
||
|
table.column('password_hash')
|
||
|
.type(FieldType.text)
|
||
|
.nullable()
|
||
|
|
||
|
table.column('username')
|
||
|
.type(FieldType.varchar)
|
||
|
.required()
|
||
|
.unique()
|
||
|
|
||
|
await schema.commit(table)
|
||
|
}
|
||
|
|
||
|
async down(): Promise<void> {
|
||
|
const schema: Schema = this.db.get().schema()
|
||
|
const table = await schema.table('users')
|
||
|
|
||
|
table.dropIfExists()
|
||
|
|
||
|
await schema.commit(table)
|
||
|
}
|
||
|
}
|