This commit is contained in:
parent
c34fad3502
commit
e16f02ce12
@ -0,0 +1,39 @@
|
|||||||
|
import {Inject, Injectable} from '../di'
|
||||||
|
import {ConstraintType, DatabaseService, FieldType, Migration, Schema} from '../orm'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration that creates the sessions table used by the ORMSession backend.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export default class CreateSessionsTableMigration extends Migration {
|
||||||
|
@Inject()
|
||||||
|
protected readonly db!: DatabaseService
|
||||||
|
|
||||||
|
async up(): Promise<void> {
|
||||||
|
const schema: Schema = this.db.get().schema()
|
||||||
|
const table = await schema.table('sessions')
|
||||||
|
|
||||||
|
table.primaryKey('session_uuid', FieldType.varchar)
|
||||||
|
.required()
|
||||||
|
|
||||||
|
table.column('session_data')
|
||||||
|
.type(FieldType.json)
|
||||||
|
.required()
|
||||||
|
.default('{}')
|
||||||
|
|
||||||
|
table.constraint('session_uuid_ck')
|
||||||
|
.type(ConstraintType.Check)
|
||||||
|
.expression('LENGTH(session_uuid) > 0')
|
||||||
|
|
||||||
|
await schema.commit(table)
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(): Promise<void> {
|
||||||
|
const schema: Schema = this.db.get().schema()
|
||||||
|
const table = await schema.table('sessions')
|
||||||
|
|
||||||
|
table.dropIfExists()
|
||||||
|
|
||||||
|
await schema.commit(table)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user