application.ts 732 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript'
  2. import { AccountModel } from '../account/account'
  3. @DefaultScope(() => ({
  4. include: [
  5. {
  6. model: AccountModel,
  7. required: true
  8. }
  9. ]
  10. }))
  11. @Table({
  12. tableName: 'application',
  13. timestamps: false
  14. })
  15. export class ApplicationModel extends Model<ApplicationModel> {
  16. @AllowNull(false)
  17. @Default(0)
  18. @IsInt
  19. @Column
  20. migrationVersion: number
  21. @HasOne(() => AccountModel, {
  22. foreignKey: {
  23. allowNull: true
  24. },
  25. onDelete: 'cascade'
  26. })
  27. Account: AccountModel
  28. static countTotal () {
  29. return ApplicationModel.count()
  30. }
  31. static load () {
  32. return ApplicationModel.findOne()
  33. }
  34. }