'use strict';

/** @type {import('sequelize-cli').Migration} */

module.exports = {
	async up(queryInterface, Sequelize) {
		await queryInterface.createTable('posts', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			content: {
				type: Sequelize.TEXT,
				allowNull: false,
			},
			location: {
				type: Sequelize.STRING,
				allowNull: true,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});

		await queryInterface.createTable('post_images', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			post_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			image: {
				type: Sequelize.STRING,
				allowNull: false,
			},
		});

		await queryInterface.createTable('post_likes', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			post_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
		});

		await queryInterface.createTable('post_comments', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			post_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			comment: {
				type: Sequelize.TEXT,
				allowNull: false,
			},
			createdAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
			updatedAt: {
				type: Sequelize.DATE,
				allowNull: false,
			},
		});

		await queryInterface.createTable('comment_likes', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			comment_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
		});

		await queryInterface.createTable('post_tags', {
			id: {
				type: Sequelize.UUID,
				defaultValue: Sequelize.UUIDV4,
				primaryKey: true,
				allowNull: false,
			},
			post_id: {
				type: Sequelize.UUID,
				allowNull: false,
			},
			member_id: {
				type: Sequelize.UUID,
				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,
			},
		});
	},

	async down(queryInterface, Sequelize) {
		await queryInterface.dropTable('posts');
		await queryInterface.dropTable('post_images');
		await queryInterface.dropTable('post_likes');
		await queryInterface.dropTable('post_comments');
		await queryInterface.dropTable('comment_likes');
		await queryInterface.dropTable('post_tags');
		await queryInterface.dropTable('shared_posts');
	},
};
