2026-03-02 03:36:33 +00:00

227 lines
2.8 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 songs = sequelize.define(
'songs',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
song_title: {
type: DataTypes.TEXT,
},
generation_mode: {
type: DataTypes.ENUM,
values: [
"manual_lyrics",
"auto_lyrics",
"remix_reference"
],
},
lyrics_text: {
type: DataTypes.TEXT,
},
tempo_bpm: {
type: DataTypes.INTEGER,
},
key_signature: {
type: DataTypes.TEXT,
},
status: {
type: DataTypes.ENUM,
values: [
"draft",
"queued",
"generating",
"ready",
"failed",
"archived"
],
},
requested_at: {
type: DataTypes.DATE,
},
completed_at: {
type: DataTypes.DATE,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
songs.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.songs.hasMany(db.song_voice_tracks, {
as: 'song_voice_tracks_song',
foreignKey: {
name: 'songId',
},
constraints: false,
});
db.songs.hasMany(db.generation_jobs, {
as: 'generation_jobs_song',
foreignKey: {
name: 'songId',
},
constraints: false,
});
db.songs.hasMany(db.media_assets, {
as: 'media_assets_song',
foreignKey: {
name: 'songId',
},
constraints: false,
});
db.songs.hasMany(db.playback_sessions, {
as: 'playback_sessions_song',
foreignKey: {
name: 'songId',
},
constraints: false,
});
//end loop
db.songs.belongsTo(db.languages, {
as: 'language',
foreignKey: {
name: 'languageId',
},
constraints: false,
});
db.songs.belongsTo(db.music_styles, {
as: 'style',
foreignKey: {
name: 'styleId',
},
constraints: false,
});
db.songs.belongsTo(db.eras, {
as: 'era',
foreignKey: {
name: 'eraId',
},
constraints: false,
});
db.songs.belongsTo(db.users, {
as: 'createdBy',
});
db.songs.belongsTo(db.users, {
as: 'updatedBy',
});
};
return songs;
};