"use strict";

module.exports = {
  up: (queryInterface, Sequelize) => {
    const tableFields = {
      id: {
        type: Sequelize.BIGINT,
        autoIncrement: true,
        allowNull: false,
        primaryKey: true
      },
      realEstateId: {
        type: Sequelize.BIGINT,
        allowNull: false,
        unique: "uniquePriceRealEstate",
        references: {
          model: "RealEstates",
          key: "id"
        },
        onUpdate: "CASCADE",
        onDelete: "SET NULL"
      },
      price: {
        type: Sequelize.REAL,
        unique: "uniquePriceRealEstate"
      },
      createdAt: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("NOW()")
      },
      updatedAt: {
        type: Sequelize.DATE,
        defaultValue: Sequelize.literal("NOW()")
      }
    };
    return queryInterface.createTable("PriceHistory", tableFields);
  },

  down: queryInterface => {
    return queryInterface.dropTable("PriceHistory", {});
  }
};
