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.
50 lines
1.2 KiB
50 lines
1.2 KiB
import {Event} from '../../../event/Event'
|
|
import {Migration} from '../Migration'
|
|
import {Inject, Injectable} from '../../../di'
|
|
import {Migrations} from '../../services/Migrations'
|
|
import {ErrorWithContext} from '../../../util'
|
|
|
|
/**
|
|
* Generic base-class for migration-related events.
|
|
*/
|
|
@Injectable()
|
|
export abstract class MigrationEvent extends Event {
|
|
@Inject()
|
|
protected readonly migrations!: Migrations
|
|
|
|
/** The migration relevant to this event. */
|
|
private internalMigration: Migration
|
|
|
|
/**
|
|
* Get the relevant migration.
|
|
*/
|
|
public get migration(): Migration {
|
|
return this.internalMigration
|
|
}
|
|
|
|
constructor(
|
|
migration: Migration,
|
|
) {
|
|
super()
|
|
this.internalMigration = migration
|
|
}
|
|
|
|
dehydrate(): {identifier: string} {
|
|
return {
|
|
identifier: this.migration.identifier,
|
|
}
|
|
}
|
|
|
|
rehydrate(state: {identifier: string}): void {
|
|
const migration = this.migrations.get(state.identifier)
|
|
|
|
if ( !migration ) {
|
|
throw new ErrorWithContext(`Unable to find migration with identifier: ${state.identifier}`, {
|
|
identifier: state.identifier,
|
|
})
|
|
}
|
|
|
|
this.internalMigration = migration
|
|
}
|
|
}
|