const config = require('../../config'); const providers = config.providers; const crypto = require('crypto'); const bcrypt = require('bcrypt'); const moment = require('moment'); module.exports = function(sequelize, DataTypes) { const station_stream_monitors = sequelize.define( 'station_stream_monitors', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, is_enabled: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, poll_interval_seconds: { type: DataTypes.INTEGER, }, stream_meta_format: { type: DataTypes.TEXT, }, monitor_region: { type: DataTypes.ENUM, values: [ "vancouver", "seattle", "other" ], }, last_polled_at: { type: DataTypes.DATE, }, last_stream_title_raw: { type: DataTypes.TEXT, }, last_error: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); station_stream_monitors.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity //end loop db.station_stream_monitors.belongsTo(db.stations, { as: 'station', foreignKey: { name: 'stationId', }, constraints: false, }); db.station_stream_monitors.belongsTo(db.users, { as: 'createdBy', }); db.station_stream_monitors.belongsTo(db.users, { as: 'updatedBy', }); }; return station_stream_monitors; };