2020-10-21 18:54:18 +00:00
|
|
|
import {Model} from './Model';
|
|
|
|
|
|
|
|
export interface IMigration {
|
|
|
|
id?: number;
|
|
|
|
uuid: string;
|
|
|
|
applied: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-21 18:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Migration extends Model<IMigration> implements IMigration {
|
|
|
|
id?: number;
|
|
|
|
uuid: string;
|
|
|
|
applied: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-21 18:54:18 +00:00
|
|
|
|
|
|
|
public static getTableName() {
|
|
|
|
return 'migrations';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getSchema() {
|
2020-10-31 03:26:42 +00:00
|
|
|
return '++id, uuid, applied, offlineUpdatedAt';
|
2020-10-21 18:54:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 03:26:42 +00:00
|
|
|
constructor(uuid: string, applied: boolean, offlineUpdatedAt?: string, id?: number) {
|
2020-10-21 18:54:18 +00:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.uuid = uuid;
|
|
|
|
this.applied = applied;
|
2020-10-31 03:26:42 +00:00
|
|
|
|
|
|
|
if ( typeof offlineUpdatedAt !== 'undefined' ) {
|
|
|
|
this.offlineUpdatedAt = offlineUpdatedAt;
|
|
|
|
}
|
|
|
|
|
2020-10-21 18:54:18 +00:00
|
|
|
if ( id ) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getSaveRecord(): any {
|
|
|
|
return {
|
|
|
|
...(this.id ? { id: this.id } : {}),
|
|
|
|
uuid: this.uuid,
|
|
|
|
applied: this.applied,
|
2020-10-31 03:26:42 +00:00
|
|
|
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
|
2020-10-21 18:54:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public getDatabase(): Dexie.Table<IMigration, number> {
|
|
|
|
return this.staticClass().dbService.table('migrations') as Dexie.Table<IMigration, number>;
|
|
|
|
}
|
|
|
|
}
|