-import * as Sequelize from 'sequelize'
-import { isHostValid, logger } from '../../helpers'
-import { SERVERS_SCORE } from '../../initializers'
-import { addMethodsToModel } from '../utils'
-import { ServerAttributes, ServerInstance, ServerMethods } from './server-interface'
-
-let Server: Sequelize.Model<ServerInstance, ServerAttributes>
-let updateServersScoreAndRemoveBadOnes: ServerMethods.UpdateServersScoreAndRemoveBadOnes
-
-export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
- Server = sequelize.define<ServerInstance, ServerAttributes>('Server',
- {
- host: {
- type: DataTypes.STRING,
- allowNull: false,
- validate: {
- isHost: value => {
- const res = isHostValid(value)
- if (res === false) throw new Error('Host not valid.')
- }
- }
- },
- score: {
- type: DataTypes.INTEGER,
- defaultValue: SERVERS_SCORE.BASE,
- allowNull: false,
- validate: {
- isInt: true,
- max: SERVERS_SCORE.MAX
- }
- }
- },
+import { Transaction } from 'sequelize'
+import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
+import { MServer, MServerFormattable } from '@server/types/models/server'
+import { AttributesOnly } from '@shared/typescript-utils'
+import { isHostValid } from '../../helpers/custom-validators/servers'
+import { ActorModel } from '../actor/actor'
+import { buildSQLAttributes, throwIfNotValid } from '../shared'
+import { ServerBlocklistModel } from './server-blocklist'
+
+@Table({
+ tableName: 'server',
+ indexes: [