const Sequelize = require('sequelize');

/**
 * @param {import('sequelize').QueryInterface} queryInterface
 * @param {import('../lib/config')} config
 * @param {import('../lib/logger')} appLog
 * @param {object} nedb - collection of nedb objects created in /lib/db.js
 */
// eslint-disable-next-line no-unused-vars
async function up(queryInterface, config, appLog, nedb) {
  await queryInterface.createTable('query_acl', {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    query_id: {
      type: Sequelize.STRING,
      allowNull: false,
    },
    user_id: {
      type: Sequelize.STRING,
      allowNull: false,
    },
    write: {
      type: Sequelize.BOOLEAN,
      allowNull: false,
      defaultValue: false,
    },
    created_at: {
      type: Sequelize.DATE,
      allowNull: false,
    },
    updated_at: {
      type: Sequelize.DATE,
    },
  });

  await queryInterface.addConstraint('query_acl', {
    type: 'unique',
    name: 'query_acl_query_id_user_id_key',
    fields: ['query_id', 'user_id'],
  });
}

module.exports = {
  up,
};

@@ -261,16 +261,68 @@
 b/db.js%0A
+ * @param %7Bobject%7D sequelizeDb - sequelize instance%0A
  */%0A// e
@@ -418,11 +418,267 @@
 nedb
-) %7B
+, sequelizeDb) %7B%0A  if (config.get('backendDatabaseUri').startsWith('mssql')) %7B%0A    await sequelizeDb.query(%0A      %60%0A        IF TYPE_ID('JSON') IS NULL%0A        BEGIN%0A          CREATE TYPE %5Bdbo%5D.%5BJSON%5D FROM %5BNVARCHAR%5D(MAX) NULL;%0A        END %0A      %60%0A    );%0A  %7D%0A
 %0A  a

create JSON datatype as part of migrations