Add go links and minor refactoring

This commit is contained in:
2022-04-05 10:47:15 -05:00
parent 22c2b9f665
commit 3142d0a4be
15 changed files with 238 additions and 65 deletions

View File

@@ -0,0 +1,49 @@
import {DatabaseService, FieldType, Inject, Injectable, Migration} from '@extollo/lib'
/**
* CreateGolinksTableMigration
* ----------------------------------
* Create Table to store URL redirections
*/
@Injectable()
export default class CreateGolinksTableMigration 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('go_links')
table.primaryKey('go_link_id').required()
table.column('active')
.type(FieldType.bool)
.default(true)
table.column('short')
.type(FieldType.varchar)
.required()
.unique()
table.column('url')
.type(FieldType.text)
.required()
await schema.commit(table)
}
/**
* Undo the migration.
*/
async down(): Promise<void> {
const schema = this.db.get().schema()
const table = await schema.table('go_links')
table.dropIfExists()
await schema.commit(table)
}
}