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.
61 lines
1.4 KiB
61 lines
1.4 KiB
import {DatabaseService, FieldType, Inject, Injectable, Migration} from '@extollo/lib'
|
|
|
|
/**
|
|
* CreateSnippetsTableMigration
|
|
* ----------------------------------
|
|
* Create table to store code snippets and gists.
|
|
*/
|
|
@Injectable()
|
|
export default class CreateSnippetsTableMigration 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('snippets')
|
|
|
|
table.primaryKey('snippet_id').required()
|
|
|
|
table.column('slug')
|
|
.type(FieldType.varchar)
|
|
.required()
|
|
|
|
table.column('users_only')
|
|
.type(FieldType.bool)
|
|
.default(false)
|
|
|
|
table.column('single_access_only')
|
|
.type(FieldType.bool)
|
|
.default(false)
|
|
|
|
table.column('access_key')
|
|
.type(FieldType.varchar)
|
|
.nullable()
|
|
|
|
table.column('syntax')
|
|
.type(FieldType.varchar)
|
|
.nullable()
|
|
|
|
table.column('body')
|
|
.type(FieldType.text)
|
|
.default('')
|
|
|
|
await schema.commit(table)
|
|
}
|
|
|
|
/**
|
|
* Undo the migration.
|
|
*/
|
|
async down(): Promise<void> {
|
|
const schema = this.db.get().schema()
|
|
const table = await schema.table('snippets')
|
|
|
|
table.dropIfExists()
|
|
|
|
await schema.commit(table)
|
|
}
|
|
}
|