module.exports = {
  /**
   * @param {QueryInterface} queryInterface
   * @param {Sequelize} Sequelize
   * @returns {Promise<void>}
   */
  async up(queryInterface, Sequelize) {
    /**
     * @type {Transaction}
     */
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.createTable(
        'users',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'access_roles',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'ai_agents',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'alerts',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'automation_jobs',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'campaigns',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'compliance_audits',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'compliance_issues',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'expansion_plans',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'infrastructure_statuses',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'invoices',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'market_signals',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'onboarding_cases',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'patient_messages',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'patient_profiles',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'platform_metrics',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'pricing_strategies',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'revenue_summaries',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'subscriber_activities',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'subscriber_roles',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'subscribers',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'support_tickets',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'roles',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'permissions',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.createTable(
        'organizations',
        {
          id: {
            type: Sequelize.DataTypes.UUID,
            defaultValue: Sequelize.DataTypes.UUIDV4,
            primaryKey: true,
          },
          createdById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          updatedById: {
            type: Sequelize.DataTypes.UUID,
            references: {
              key: 'id',
              model: 'users',
            },
          },
          createdAt: { type: Sequelize.DataTypes.DATE },
          updatedAt: { type: Sequelize.DataTypes.DATE },
          deletedAt: { type: Sequelize.DataTypes.DATE },
          importHash: {
            type: Sequelize.DataTypes.STRING(255),
            allowNull: true,
            unique: true,
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'firstName',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'lastName',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'phoneNumber',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'email',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'disabled',
        {
          type: Sequelize.DataTypes.BOOLEAN,

          defaultValue: false,
          allowNull: false,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'password',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'emailVerified',
        {
          type: Sequelize.DataTypes.BOOLEAN,

          defaultValue: false,
          allowNull: false,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'emailVerificationToken',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'emailVerificationTokenExpiresAt',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'passwordResetToken',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'passwordResetTokenExpiresAt',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'provider',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'access_roles',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'access_roles',
        'user_count',
        {
          type: Sequelize.DataTypes.INTEGER,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'access_roles',
        'last_suspicious_login',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'version',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'accuracy_pct',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'latency_ms',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['active', 'inactive'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'last_updated',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'alerts',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'alerts',
        'type',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['system', 'security', 'billing'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'alerts',
        'severity',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['low', 'medium', 'high', 'critical'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'alerts',
        'message',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'alerts',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['open', 'resolved'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'alerts',
        'resolved_at',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'workflow_name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['pending', 'running', 'completed', 'failed'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'runtime_ms',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'error_msg',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'started_at',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'finished_at',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'spend',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'impressions',
        {
          type: Sequelize.DataTypes.INTEGER,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'clicks',
        {
          type: Sequelize.DataTypes.INTEGER,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'conversions',
        {
          type: Sequelize.DataTypes.INTEGER,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'cpa',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'ctr_pct',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['active', 'paused', 'completed'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'start_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'end_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_audits',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_audits',
        'date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_audits',
        'result',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['pass', 'fail'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_audits',
        'issues_found',
        {
          type: Sequelize.DataTypes.INTEGER,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_audits',
        'ownerId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'users',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_audits',
        'report_url',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_issues',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_issues',
        'category',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['security', 'privacy', 'billing'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_issues',
        'description',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_issues',
        'severity',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['low', 'medium', 'high', 'critical'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_issues',
        'ownerId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'users',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_issues',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['open', 'in_progress', 'resolved'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'expansion_plans',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'expansion_plans',
        'territory',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'expansion_plans',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['proposed', 'active', 'completed'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'expansion_plans',
        'projected_roi_pct',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'expansion_plans',
        'start_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'expansion_plans',
        'approval_status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['pending', 'approved', 'rejected'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'service',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'uptime_pct',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'latency_ms',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'error_rate',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['operational', 'degraded', 'down'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'last_updated',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'invoices',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'invoices',
        'doctorId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'users',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'invoices',
        'payer',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['Medicare', 'Medicaid', 'Private', 'Self-pay'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'invoices',
        'amount',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'invoices',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['paid', 'pending', 'overdue', 'disputed'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'invoices',
        'due_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'market_signals',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'market_signals',
        'competitor',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'market_signals',
        'type',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['launch', 'price_change', 'territory_entry'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'market_signals',
        'description',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'market_signals',
        'date_detected',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'market_signals',
        'impact_score',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'userId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'users',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'role',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['finance_admin', 'provider', 'support'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['pending', 'active', 'completed'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'start_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'completion_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'assigned_staffId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'users',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_messages',
        'sender',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_messages',
        'message',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_messages',
        'read_status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['unread', 'read'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_profiles',
        'subscriberId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'subscribers',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_profiles',
        'health_metrics',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_profiles',
        'prescriptions',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_profiles',
        'appointments',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_profiles',
        'billing',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'platform_metrics',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'platform_metrics',
        'region',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'platform_metrics',
        'api_latency_ms',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'platform_metrics',
        'uptime_pct',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'platform_metrics',
        'page_load_ms',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'platform_metrics',
        'timestamp',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'product',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'price',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['active', 'inactive'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'start_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'end_date',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'metrics',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'revenue_summaries',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'revenue_summaries',
        'month',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'revenue_summaries',
        'total_amount',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'revenue_summaries',
        'payer_breakdown',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'revenue_summaries',
        'growth_pct',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_activities',
        'subscriberId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'subscribers',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_activities',
        'action',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_activities',
        'object',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_activities',
        'timestamp',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_roles',
        'subscriberId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'subscribers',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_roles',
        'role_name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'org',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'email',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'role',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['admin', 'user'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['active', 'pending', 'suspended'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'last_login',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'organizationId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'subject',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'category',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['billing', 'technical', 'general'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'priority',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['low', 'medium', 'high', 'urgent'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'status',
        {
          type: Sequelize.DataTypes.ENUM,

          values: ['open', 'in_progress', 'resolved', 'escalated'],
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'assigned_toId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'users',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'resolved_at',
        {
          type: Sequelize.DataTypes.DATE,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'permissions',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'roles',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'roles',
        'role_customization',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'app_roleId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'roles',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'organizations',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'roles',
        'globalAccess',
        {
          type: Sequelize.DataTypes.BOOLEAN,

          defaultValue: false,
          allowNull: false,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'users',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'access_roles',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'ai_agents',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'alerts',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'automation_jobs',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'campaigns',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_audits',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'compliance_issues',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'expansion_plans',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'infrastructure_statuses',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'invoices',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'market_signals',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'onboarding_cases',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_messages',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'patient_profiles',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'platform_metrics',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'pricing_strategies',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'revenue_summaries',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_activities',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscriber_roles',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'subscribers',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'support_tickets',
        'organizationsId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'organizations',
            key: 'id',
          },
        },
        { transaction },
      );

      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  },
  /**
   * @param {QueryInterface} queryInterface
   * @param {Sequelize} Sequelize
   * @returns {Promise<void>}
   */
  async down(queryInterface, Sequelize) {
    /**
     * @type {Transaction}
     */
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.removeColumn('support_tickets', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('subscribers', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('subscriber_roles', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn(
        'subscriber_activities',
        'organizationsId',
        { transaction },
      );

      await queryInterface.removeColumn(
        'revenue_summaries',
        'organizationsId',
        { transaction },
      );

      await queryInterface.removeColumn(
        'pricing_strategies',
        'organizationsId',
        { transaction },
      );

      await queryInterface.removeColumn('platform_metrics', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('patient_profiles', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('patient_messages', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('onboarding_cases', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('market_signals', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('invoices', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn(
        'infrastructure_statuses',
        'organizationsId',
        { transaction },
      );

      await queryInterface.removeColumn('expansion_plans', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn(
        'compliance_issues',
        'organizationsId',
        { transaction },
      );

      await queryInterface.removeColumn(
        'compliance_audits',
        'organizationsId',
        { transaction },
      );

      await queryInterface.removeColumn('campaigns', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('alerts', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('ai_agents', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('access_roles', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('users', 'organizationsId', {
        transaction,
      });

      await queryInterface.removeColumn('roles', 'globalAccess', {
        transaction,
      });

      await queryInterface.removeColumn('organizations', 'name', {
        transaction,
      });

      await queryInterface.removeColumn('users', 'app_roleId', { transaction });

      await queryInterface.removeColumn('roles', 'role_customization', {
        transaction,
      });

      await queryInterface.removeColumn('roles', 'name', { transaction });

      await queryInterface.removeColumn('permissions', 'name', { transaction });

      await queryInterface.removeColumn('support_tickets', 'resolved_at', {
        transaction,
      });

      await queryInterface.removeColumn('support_tickets', 'assigned_toId', {
        transaction,
      });

      await queryInterface.removeColumn('support_tickets', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('support_tickets', 'priority', {
        transaction,
      });

      await queryInterface.removeColumn('support_tickets', 'category', {
        transaction,
      });

      await queryInterface.removeColumn('support_tickets', 'subject', {
        transaction,
      });

      await queryInterface.removeColumn('support_tickets', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('subscribers', 'last_login', {
        transaction,
      });

      await queryInterface.removeColumn('subscribers', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('subscribers', 'role', { transaction });

      await queryInterface.removeColumn('subscribers', 'email', {
        transaction,
      });

      await queryInterface.removeColumn('subscribers', 'org', { transaction });

      await queryInterface.removeColumn('subscribers', 'name', { transaction });

      await queryInterface.removeColumn('subscribers', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('subscriber_roles', 'role_name', {
        transaction,
      });

      await queryInterface.removeColumn('subscriber_roles', 'subscriberId', {
        transaction,
      });

      await queryInterface.removeColumn('subscriber_activities', 'timestamp', {
        transaction,
      });

      await queryInterface.removeColumn('subscriber_activities', 'object', {
        transaction,
      });

      await queryInterface.removeColumn('subscriber_activities', 'action', {
        transaction,
      });

      await queryInterface.removeColumn(
        'subscriber_activities',
        'subscriberId',
        { transaction },
      );

      await queryInterface.removeColumn('revenue_summaries', 'growth_pct', {
        transaction,
      });

      await queryInterface.removeColumn(
        'revenue_summaries',
        'payer_breakdown',
        { transaction },
      );

      await queryInterface.removeColumn('revenue_summaries', 'total_amount', {
        transaction,
      });

      await queryInterface.removeColumn('revenue_summaries', 'month', {
        transaction,
      });

      await queryInterface.removeColumn('revenue_summaries', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('pricing_strategies', 'metrics', {
        transaction,
      });

      await queryInterface.removeColumn('pricing_strategies', 'end_date', {
        transaction,
      });

      await queryInterface.removeColumn('pricing_strategies', 'start_date', {
        transaction,
      });

      await queryInterface.removeColumn('pricing_strategies', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('pricing_strategies', 'price', {
        transaction,
      });

      await queryInterface.removeColumn('pricing_strategies', 'product', {
        transaction,
      });

      await queryInterface.removeColumn('pricing_strategies', 'name', {
        transaction,
      });

      await queryInterface.removeColumn(
        'pricing_strategies',
        'organizationId',
        { transaction },
      );

      await queryInterface.removeColumn('platform_metrics', 'timestamp', {
        transaction,
      });

      await queryInterface.removeColumn('platform_metrics', 'page_load_ms', {
        transaction,
      });

      await queryInterface.removeColumn('platform_metrics', 'uptime_pct', {
        transaction,
      });

      await queryInterface.removeColumn('platform_metrics', 'api_latency_ms', {
        transaction,
      });

      await queryInterface.removeColumn('platform_metrics', 'region', {
        transaction,
      });

      await queryInterface.removeColumn('platform_metrics', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('patient_profiles', 'billing', {
        transaction,
      });

      await queryInterface.removeColumn('patient_profiles', 'appointments', {
        transaction,
      });

      await queryInterface.removeColumn('patient_profiles', 'prescriptions', {
        transaction,
      });

      await queryInterface.removeColumn('patient_profiles', 'health_metrics', {
        transaction,
      });

      await queryInterface.removeColumn('patient_profiles', 'subscriberId', {
        transaction,
      });

      await queryInterface.removeColumn('patient_messages', 'read_status', {
        transaction,
      });

      await queryInterface.removeColumn('patient_messages', 'message', {
        transaction,
      });

      await queryInterface.removeColumn('patient_messages', 'sender', {
        transaction,
      });

      await queryInterface.removeColumn(
        'onboarding_cases',
        'assigned_staffId',
        { transaction },
      );

      await queryInterface.removeColumn('onboarding_cases', 'completion_date', {
        transaction,
      });

      await queryInterface.removeColumn('onboarding_cases', 'start_date', {
        transaction,
      });

      await queryInterface.removeColumn('onboarding_cases', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('onboarding_cases', 'role', {
        transaction,
      });

      await queryInterface.removeColumn('onboarding_cases', 'userId', {
        transaction,
      });

      await queryInterface.removeColumn('onboarding_cases', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('market_signals', 'impact_score', {
        transaction,
      });

      await queryInterface.removeColumn('market_signals', 'date_detected', {
        transaction,
      });

      await queryInterface.removeColumn('market_signals', 'description', {
        transaction,
      });

      await queryInterface.removeColumn('market_signals', 'type', {
        transaction,
      });

      await queryInterface.removeColumn('market_signals', 'competitor', {
        transaction,
      });

      await queryInterface.removeColumn('market_signals', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('invoices', 'due_date', {
        transaction,
      });

      await queryInterface.removeColumn('invoices', 'status', { transaction });

      await queryInterface.removeColumn('invoices', 'amount', { transaction });

      await queryInterface.removeColumn('invoices', 'payer', { transaction });

      await queryInterface.removeColumn('invoices', 'doctorId', {
        transaction,
      });

      await queryInterface.removeColumn('invoices', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn(
        'infrastructure_statuses',
        'last_updated',
        { transaction },
      );

      await queryInterface.removeColumn('infrastructure_statuses', 'status', {
        transaction,
      });

      await queryInterface.removeColumn(
        'infrastructure_statuses',
        'error_rate',
        { transaction },
      );

      await queryInterface.removeColumn(
        'infrastructure_statuses',
        'latency_ms',
        { transaction },
      );

      await queryInterface.removeColumn(
        'infrastructure_statuses',
        'uptime_pct',
        { transaction },
      );

      await queryInterface.removeColumn('infrastructure_statuses', 'service', {
        transaction,
      });

      await queryInterface.removeColumn(
        'infrastructure_statuses',
        'organizationId',
        { transaction },
      );

      await queryInterface.removeColumn('expansion_plans', 'approval_status', {
        transaction,
      });

      await queryInterface.removeColumn('expansion_plans', 'start_date', {
        transaction,
      });

      await queryInterface.removeColumn(
        'expansion_plans',
        'projected_roi_pct',
        { transaction },
      );

      await queryInterface.removeColumn('expansion_plans', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('expansion_plans', 'territory', {
        transaction,
      });

      await queryInterface.removeColumn('expansion_plans', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_issues', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_issues', 'ownerId', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_issues', 'severity', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_issues', 'description', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_issues', 'category', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_issues', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_audits', 'report_url', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_audits', 'ownerId', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_audits', 'issues_found', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_audits', 'result', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_audits', 'date', {
        transaction,
      });

      await queryInterface.removeColumn('compliance_audits', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('campaigns', 'end_date', {
        transaction,
      });

      await queryInterface.removeColumn('campaigns', 'start_date', {
        transaction,
      });

      await queryInterface.removeColumn('campaigns', 'status', { transaction });

      await queryInterface.removeColumn('campaigns', 'ctr_pct', {
        transaction,
      });

      await queryInterface.removeColumn('campaigns', 'cpa', { transaction });

      await queryInterface.removeColumn('campaigns', 'conversions', {
        transaction,
      });

      await queryInterface.removeColumn('campaigns', 'clicks', { transaction });

      await queryInterface.removeColumn('campaigns', 'impressions', {
        transaction,
      });

      await queryInterface.removeColumn('campaigns', 'spend', { transaction });

      await queryInterface.removeColumn('campaigns', 'name', { transaction });

      await queryInterface.removeColumn('campaigns', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'finished_at', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'started_at', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'error_msg', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'runtime_ms', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'workflow_name', {
        transaction,
      });

      await queryInterface.removeColumn('automation_jobs', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('alerts', 'resolved_at', {
        transaction,
      });

      await queryInterface.removeColumn('alerts', 'status', { transaction });

      await queryInterface.removeColumn('alerts', 'message', { transaction });

      await queryInterface.removeColumn('alerts', 'severity', { transaction });

      await queryInterface.removeColumn('alerts', 'type', { transaction });

      await queryInterface.removeColumn('alerts', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn('ai_agents', 'last_updated', {
        transaction,
      });

      await queryInterface.removeColumn('ai_agents', 'status', { transaction });

      await queryInterface.removeColumn('ai_agents', 'latency_ms', {
        transaction,
      });

      await queryInterface.removeColumn('ai_agents', 'accuracy_pct', {
        transaction,
      });

      await queryInterface.removeColumn('ai_agents', 'version', {
        transaction,
      });

      await queryInterface.removeColumn('ai_agents', 'name', { transaction });

      await queryInterface.removeColumn('ai_agents', 'organizationId', {
        transaction,
      });

      await queryInterface.removeColumn(
        'access_roles',
        'last_suspicious_login',
        { transaction },
      );

      await queryInterface.removeColumn('access_roles', 'user_count', {
        transaction,
      });

      await queryInterface.removeColumn('access_roles', 'name', {
        transaction,
      });

      await queryInterface.removeColumn('users', 'provider', { transaction });

      await queryInterface.removeColumn(
        'users',
        'passwordResetTokenExpiresAt',
        { transaction },
      );

      await queryInterface.removeColumn('users', 'passwordResetToken', {
        transaction,
      });

      await queryInterface.removeColumn(
        'users',
        'emailVerificationTokenExpiresAt',
        { transaction },
      );

      await queryInterface.removeColumn('users', 'emailVerificationToken', {
        transaction,
      });

      await queryInterface.removeColumn('users', 'emailVerified', {
        transaction,
      });

      await queryInterface.removeColumn('users', 'password', { transaction });

      await queryInterface.removeColumn('users', 'disabled', { transaction });

      await queryInterface.removeColumn('users', 'email', { transaction });

      await queryInterface.removeColumn('users', 'phoneNumber', {
        transaction,
      });

      await queryInterface.removeColumn('users', 'lastName', { transaction });

      await queryInterface.removeColumn('users', 'firstName', { transaction });

      await queryInterface.dropTable('organizations', { transaction });

      await queryInterface.dropTable('permissions', { transaction });

      await queryInterface.dropTable('roles', { transaction });

      await queryInterface.dropTable('support_tickets', { transaction });

      await queryInterface.dropTable('subscribers', { transaction });

      await queryInterface.dropTable('subscriber_roles', { transaction });

      await queryInterface.dropTable('subscriber_activities', { transaction });

      await queryInterface.dropTable('revenue_summaries', { transaction });

      await queryInterface.dropTable('pricing_strategies', { transaction });

      await queryInterface.dropTable('platform_metrics', { transaction });

      await queryInterface.dropTable('patient_profiles', { transaction });

      await queryInterface.dropTable('patient_messages', { transaction });

      await queryInterface.dropTable('onboarding_cases', { transaction });

      await queryInterface.dropTable('market_signals', { transaction });

      await queryInterface.dropTable('invoices', { transaction });

      await queryInterface.dropTable('infrastructure_statuses', {
        transaction,
      });

      await queryInterface.dropTable('expansion_plans', { transaction });

      await queryInterface.dropTable('compliance_issues', { transaction });

      await queryInterface.dropTable('compliance_audits', { transaction });

      await queryInterface.dropTable('campaigns', { transaction });

      await queryInterface.dropTable('automation_jobs', { transaction });

      await queryInterface.dropTable('alerts', { transaction });

      await queryInterface.dropTable('ai_agents', { transaction });

      await queryInterface.dropTable('access_roles', { transaction });

      await queryInterface.dropTable('users', { transaction });

      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  },
};
