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.
www/src/app/migrations/2022-03-29T17:04:30.346Z_Cr...

59 lines
1.4 KiB

import {DatabaseService, FieldType, Inject, Injectable, Migration, raw} from '@extollo/lib'
/**
* CreateFeedPostsTableMigration
* ----------------------------------
* Create the table to hold posts to the "updates" feed.
*/
@Injectable()
export default class CreateFeedPostsTableMigration 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('feed_posts')
table.primaryKey('feed_post_id', FieldType.varchar)
.required()
// date, tag, text, visible
table.column('posted_at')
.type(FieldType.timestamp)
.default(raw('NOW()'))
.required()
table.column('tag')
.type(FieldType.varchar)
.required()
table.column('visible')
.type(FieldType.bool)
.default(false)
.required()
table.column('body')
.type(FieldType.text)
.default('')
.required()
await schema.commit(table)
}
/**
* Undo the migration.
*/
async down(): Promise<void> {
const schema = this.db.get().schema()
const table = await schema.table('feed_posts')
table.dropIfExists()
await schema.commit(table)
}
}