38075-vm/backend/src/db/models/music_tracks.js
2026-02-01 23:38:21 +00:00

152 lines
1.9 KiB
JavaScript

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 music_tracks = sequelize.define(
'music_tracks',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
artist: {
type: DataTypes.TEXT,
},
album: {
type: DataTypes.TEXT,
},
duration_seconds: {
type: DataTypes.INTEGER,
},
genre: {
type: DataTypes.ENUM,
values: [
"Cumbia",
"Salsa",
"Vallenato",
"Reggaeton",
"Pop",
"Other"
],
},
release_date: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
music_tracks.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.music_tracks.hasMany(db.file, {
as: 'audio_file',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.music_tracks.getTableName(),
belongsToColumn: 'audio_file',
},
});
db.music_tracks.hasMany(db.file, {
as: 'cover',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.music_tracks.getTableName(),
belongsToColumn: 'cover',
},
});
db.music_tracks.belongsTo(db.users, {
as: 'createdBy',
});
db.music_tracks.belongsTo(db.users, {
as: 'updatedBy',
});
};
return music_tracks;
};