'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('files', {
      id: {
        type: Sequelize.DataTypes.UUID,
        defaultValue: Sequelize.DataTypes.UUIDV4,
        primaryKey: true,
      },
      belongsTo: {
        type: Sequelize.DataTypes.STRING(255),
      },
      belongsToId: {
        type: Sequelize.DataTypes.UUID,
      },
      belongsToColumn: {
        type: Sequelize.DataTypes.STRING(255),
      },
      name: {
        type: Sequelize.DataTypes.STRING(2083),
        allowNull: false,
      },
      sizeInBytes: {
        type: Sequelize.DataTypes.INTEGER,
        allowNull: true,
      },
      privateUrl: {
        type: Sequelize.DataTypes.STRING(2083),
        allowNull: true,
      },
      publicUrl: {
        type: Sequelize.DataTypes.STRING(2083),
        allowNull: false,
      },
      createdAt: {
        type: Sequelize.DataTypes.DATE,
      },
      updatedAt: {
        type: Sequelize.DataTypes.DATE,
      },
      deletedAt: {
        type: Sequelize.DataTypes.DATE,
      },
      createdById: {
        type: Sequelize.DataTypes.UUID,
        references: {
          model: 'users',
          key: 'id',
        },
      },
      updatedById: {
        type: Sequelize.DataTypes.UUID,
        references: {
          model: 'users',
          key: 'id',
        },
      },
    });

    await queryInterface.addIndex('files', [
      'belongsTo',
      'belongsToId',
      'belongsToColumn',
    ]);
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('files');
  },
};
