X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fapplication%2Fapplication.ts;h=81320b9afeafae058c72947b2c3b1accca5b06b0;hb=4f0f2ab228d73dbec303914dd59b52f6cdaddf46;hp=f3c0f1052735c2749110a0c7bf2296086763fa84;hpb=3fd3ab2d34d512b160a5e6084d7609be7b4f4452;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/application/application.ts b/server/models/application/application.ts index f3c0f1052..81320b9af 100644 --- a/server/models/application/application.ts +++ b/server/models/application/application.ts @@ -1,8 +1,17 @@ -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 { @@ -12,24 +21,19 @@ export class ApplicationModel extends Model { @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() } }