]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/application/application.ts
Fix createdAt/updatedAt issues
[github/Chocobozzz/PeerTube.git] / server / models / application / application.ts
index f3c0f1052735c2749110a0c7bf2296086763fa84..81320b9afeafae058c72947b2c3b1accca5b06b0 100644 (file)
@@ -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<ApplicationModel> {
 
@@ -12,24 +21,19 @@ 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()
   }
 }