-import { Transaction } from 'sequelize'
-import { AllowNull, Column, Default, IsInt, Model, Table } from 'sequelize-typescript'
+import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
+import { AccountModel } from '../account/account'
+@DefaultScope(() => ({
+ include: [
+ {
+ model: AccountModel,
+ required: true
+ }
+ ]
+}))
@Table({
- tableName: 'application'
+ tableName: 'application',
+ timestamps: false
})
export class ApplicationModel extends Model<ApplicationModel> {
@Column
migrationVersion: number
+ @HasOne(() => AccountModel, {
+ foreignKey: {
+ allowNull: true
+ },
+ onDelete: 'cascade'
+ })
+ Account: AccountModel
+
static countTotal () {
return ApplicationModel.count()
}
- static loadMigrationVersion () {
- const query = {
- attributes: [ 'migrationVersion' ]
- }
-
- return ApplicationModel.findOne(query).then(data => data ? data.migrationVersion : null)
- }
-
- static updateMigrationVersion (newVersion: number, transaction: Transaction) {
- const options = {
- where: {},
- transaction: transaction
- }
-
- return ApplicationModel.update({ migrationVersion: newVersion }, options)
+ static load () {
+ return ApplicationModel.findOne()
}
}