'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.dropTable('shared_posts');

		await queryInterface.changeColumn('posts', 'content', {
			type: Sequelize.TEXT,
			allowNull: true,
		});
		await queryInterface.addColumn('posts', 'is_shared', {
			type: Sequelize.BOOLEAN,
			allowNull: false,
			defaultValue: false,
		});
		await queryInterface.addColumn('posts', 'original_post_id', {
			type: Sequelize.UUID,
			allowNull: true,
			references: {
				model: 'posts',
				key: 'id',
			},
		});
	},

	async down(queryInterface, Sequelize) {
		await queryInterface.removeColumn('posts', 'is_shared');
		await queryInterface.removeColumn('posts', 'original_post_id');
		await queryInterface.changeColumn('posts', 'content', {
			type: Sequelize.TEXT,
			allowNull: false,
		});
		await queryInterface.createTable('shared_posts', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			post_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			content: {
				type: Sequelize.TEXT,
				allowNull: true,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});
	},
};
