133 lines
1.4 KiB
JavaScript
133 lines
1.4 KiB
JavaScript
module.exports = function(sequelize, DataTypes) {
|
|
const asset_variants = sequelize.define(
|
|
'asset_variants',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
variant_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"thumbnail",
|
|
|
|
|
|
"preview",
|
|
|
|
|
|
"webp",
|
|
|
|
|
|
"mp4_low",
|
|
|
|
|
|
"mp4_high",
|
|
|
|
|
|
"original"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
cdn_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
width_px: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
height_px: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
size_mb: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
asset_variants.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.asset_variants.belongsTo(db.assets, {
|
|
as: 'asset',
|
|
foreignKey: {
|
|
name: 'assetId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.asset_variants.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.asset_variants.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return asset_variants;
|
|
};
|
|
|
|
|