'use strict'; /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( { schema: 'community', tableName: 'erotic_video_image_visibility' }, { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false, }, erotic_video_id: { type: Sequelize.INTEGER, allowNull: false, references: { model: { schema: 'community', tableName: 'erotic_video' }, key: 'id', }, onUpdate: 'CASCADE', onDelete: 'CASCADE', }, visibility_type_id: { type: Sequelize.INTEGER, allowNull: false, references: { model: { schema: 'type', tableName: 'image_visibility' }, key: 'id', }, onUpdate: 'CASCADE', onDelete: 'CASCADE', }, } ); await queryInterface.createTable( { schema: 'community', tableName: 'erotic_video_visibility_user' }, { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false, }, erotic_video_id: { type: Sequelize.INTEGER, allowNull: false, references: { model: { schema: 'community', tableName: 'erotic_video' }, key: 'id', }, onUpdate: 'CASCADE', onDelete: 'CASCADE', }, user_id: { type: Sequelize.INTEGER, allowNull: false, references: { model: { schema: 'community', tableName: 'user' }, key: 'id', }, onUpdate: 'CASCADE', onDelete: 'CASCADE', }, } ); await queryInterface.sequelize.query(` INSERT INTO community.erotic_video_image_visibility (erotic_video_id, visibility_type_id) SELECT ev.id, iv.id FROM community.erotic_video ev CROSS JOIN type.image_visibility iv WHERE iv.description = 'adults' AND NOT EXISTS ( SELECT 1 FROM community.erotic_video_image_visibility eviv WHERE eviv.erotic_video_id = ev.id AND eviv.visibility_type_id = iv.id ) `); }, async down(queryInterface) { await queryInterface.dropTable({ schema: 'community', tableName: 'erotic_video_visibility_user' }); await queryInterface.dropTable({ schema: 'community', tableName: 'erotic_video_image_visibility' }); }, };