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('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('subscriptions', {
                        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('feature_flags', {
                        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('matters', {
                        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('matter_parties', {
                        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('files', {
                        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('file_extractions', {
                        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('assistant_threads', {
                        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('assistant_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('ai_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('legal_templates', {
                        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('template_fields', {
                        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('generated_documents', {
                        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('document_versions', {
                        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('research_queries', {
                        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('legal_sources', {
                        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('research_results', {
                        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('citator_checks', {
                        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('mock_trials', {
                        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('mock_trial_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('mock_trial_turns', {
                        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('transcription_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('medical_chronology_reports', {
                        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('medical_events', {
                        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('causation_analyses', {
                        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('audit_events', {
                        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(
                      'users',
                      'app_roleId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'roles',
                                key: 'id',
                            },
                          
                      },
                      { 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(
                      'permissions',
                      'name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'userId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['trialing','active','past_due','canceled','expired'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'billing_period',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['yearly'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'price_amount',
                      {
                          type: Sequelize.DataTypes.DECIMAL,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'currency',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'current_period_start',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'current_period_end',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'canceled_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'payment_provider',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'provider_customer_ref',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'subscriptions',
                      'provider_subscription_ref',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'feature_flags',
                      'key',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'feature_flags',
                      'name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'feature_flags',
                      'description',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'feature_flags',
                      'default_plan_access',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['free','premium','disabled'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'feature_flags',
                      'is_enabled',
                      {
                          type: Sequelize.DataTypes.BOOLEAN,
                          
                            defaultValue: false,
                            allowNull: false,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'ownerId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'title',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'matter_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['civil','criminal','family','employment','housing','small_claims','personal_injury','medical_malpractice','contract','administrative','other'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['intake','active','stayed','closed','archived'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'jurisdiction',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'court_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'case_number',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'filed_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'next_hearing_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matters',
                      'notes',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'party_role',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['plaintiff','defendant','petitioner','respondent','witness','judge','attorney','opposing_counsel','expert','provider','other'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'display_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'organization_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'email',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'phone',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'address',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'matter_parties',
                      'notes',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'ownerId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'file_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'content_type',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'file_extension',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'size_bytes',
                      {
                          type: Sequelize.DataTypes.INTEGER,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'storage_provider',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'storage_key',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'checksum_sha256',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'is_ocr_required',
                      {
                          type: Sequelize.DataTypes.BOOLEAN,
                          
                            defaultValue: false,
                            allowNull: false,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'processing_status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['queued','processing','completed','failed'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'uploaded_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'files',
                      'tags',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'extraction_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['text','ocr_text','metadata','clauses','summary','issues','citations'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['queued','running','completed','failed'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'language',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'page_count',
                      {
                          type: Sequelize.DataTypes.INTEGER,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'result_text',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'started_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'finished_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'file_extractions',
                      'error_message',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_threads',
                      'ownerId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_threads',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_threads',
                      'title',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_threads',
                      'thread_scope',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['general','matter'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_threads',
                      'is_pinned',
                      {
                          type: Sequelize.DataTypes.BOOLEAN,
                          
                            defaultValue: false,
                            allowNull: false,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_threads',
                      'last_activity_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_messages',
                      'threadId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'assistant_threads',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_messages',
                      'sender',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['user','assistant','system'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_messages',
                      'content',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_messages',
                      'model_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_messages',
                      'prompt_tokens',
                      {
                          type: Sequelize.DataTypes.INTEGER,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_messages',
                      'completion_tokens',
                      {
                          type: Sequelize.DataTypes.INTEGER,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'assistant_messages',
                      'sent_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'requested_byId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'job_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['drafting','file_analysis','legal_research','citator','transcription','translation','medical_chronology','causation','ocr','export'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['queued','running','completed','failed','canceled'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'input_summary',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'output_summary',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'cost_usd',
                      {
                          type: Sequelize.DataTypes.DECIMAL,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'queued_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'started_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'completed_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'ai_jobs',
                      'error_message',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'ownerId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'template_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'template_category',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['motion','pleading','brief','letter','contract','memo','form','other'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'jurisdiction',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'description',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'template_body',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'is_public',
                      {
                          type: Sequelize.DataTypes.BOOLEAN,
                          
                            defaultValue: false,
                            allowNull: false,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_templates',
                      'source_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'templateId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'legal_templates',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'field_key',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'label',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'value_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['text','number','date','boolean','party','citation','custom'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'is_required',
                      {
                          type: Sequelize.DataTypes.BOOLEAN,
                          
                            defaultValue: false,
                            allowNull: false,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'default_value',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'sort_order',
                      {
                          type: Sequelize.DataTypes.INTEGER,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'template_fields',
                      'help_text',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'ownerId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'templateId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'legal_templates',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'document_title',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'document_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['draft','final','exported'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'format',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['canvas','docx','pdf','txt'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'content',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'export_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'generated_documents',
                      'last_edited_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'document_versions',
                      'documentId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'generated_documents',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'document_versions',
                      'version_number',
                      {
                          type: Sequelize.DataTypes.INTEGER,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'document_versions',
                      'change_source',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['user_edit','ai_regeneration','import'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'document_versions',
                      'content_snapshot',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'document_versions',
                      'saved_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_queries',
                      'requested_byId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_queries',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_queries',
                      'query_text',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_queries',
                      'jurisdiction',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_queries',
                      'source_scope',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['federal','state','both'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_queries',
                      'searched_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_queries',
                      'filters_json',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'source_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['case','statute','rule','regulation'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'jurisdiction',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'title',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'citation',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'decision_date',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'court',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'full_text',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'summary',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'source_url',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'legal_sources',
                      'last_updated_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_results',
                      'research_queryId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'research_queries',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_results',
                      'legal_sourceId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'legal_sources',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_results',
                      'relevance_score',
                      {
                          type: Sequelize.DataTypes.DECIMAL,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_results',
                      'snippet',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'research_results',
                      'rule_statement',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'citator_checks',
                      'requested_byId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'citator_checks',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'citator_checks',
                      'legal_sourceId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'legal_sources',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'citator_checks',
                      'standing',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['good_law','caution','overruled','distinguished','unknown'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'citator_checks',
                      'analysis',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'citator_checks',
                      'conflicts_summary',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'citator_checks',
                      'checked_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'ownerId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'session_title',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'mode',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['scripted','realtime'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'input_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['text','voice','mixed'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['scheduled','in_progress','completed','archived'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'scheduled_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'started_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'ended_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trials',
                      'scenario_brief',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_roles',
                      'mock_trialId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'mock_trials',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_roles',
                      'role_name',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['judge','plaintiff','defendant','petitioner','respondent','opposing_counsel','witness','clerk','bailiff'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_roles',
                      'actor_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['user','ai'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_roles',
                      'display_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_roles',
                      'instructions',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_turns',
                      'mock_trialId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'mock_trials',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_turns',
                      'roleId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'mock_trial_roles',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_turns',
                      'turn_type',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['opening','direct_exam','cross_exam','argument','ruling','objection','sidebar','closing','general'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_turns',
                      'content',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_turns',
                      'audio_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'mock_trial_turns',
                      'spoken_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'requested_byId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'media_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['queued','running','completed','failed'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'source_language',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'target_language',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'speaker_diarization',
                      {
                          type: Sequelize.DataTypes.BOOLEAN,
                          
                            defaultValue: false,
                            allowNull: false,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'confidence_avg',
                      {
                          type: Sequelize.DataTypes.DECIMAL,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'transcript_text',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'summary_text',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'export_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'started_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'finished_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'transcription_jobs',
                      'error_message',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_chronology_reports',
                      'requested_byId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_chronology_reports',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_chronology_reports',
                      'report_title',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_chronology_reports',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['draft','generated','exported'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_chronology_reports',
                      'overview',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_chronology_reports',
                      'export_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_chronology_reports',
                      'generated_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'reportId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'medical_chronology_reports',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'event_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'provider_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'facility_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'diagnoses',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'icd10_codes',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'procedures',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'medications',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'notes',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'medical_events',
                      'linked_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'requested_byId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'analysis_title',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'status',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['draft','generated','exported'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'theory_of_causation',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'supporting_facts',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'weaknesses_and_gaps',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'export_fileId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'files',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'causation_analyses',
                      'generated_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'actorId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'users',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'matterId',
                      {
                          type: Sequelize.DataTypes.UUID,
                          
                          
                          
                            references: {
                                model: 'matters',
                                key: 'id',
                            },
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'event_name',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'event_category',
                      {
                          type: Sequelize.DataTypes.ENUM,
                          
                          
                            values: ['auth','billing','matter','file','assistant','research','template','document','mock_trial','medical','admin'],
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'event_details',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'occurred_at',
                      {
                          type: Sequelize.DataTypes.DATE,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'ip_address',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { transaction }
                    );
                
            
                
                    
                    await queryInterface.addColumn(
                      'audit_events',
                      'user_agent',
                      {
                          type: Sequelize.DataTypes.TEXT,
                          
                          
                          
                      },
                      { 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(
                        'audit_events',
                        'user_agent',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'audit_events',
                        'ip_address',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'audit_events',
                        'occurred_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'audit_events',
                        'event_details',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'audit_events',
                        'event_category',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'audit_events',
                        'event_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'audit_events',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'audit_events',
                        'actorId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'generated_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'export_fileId',
                        { transaction }
                    );
                
            
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'weaknesses_and_gaps',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'supporting_facts',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'theory_of_causation',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'analysis_title',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'causation_analyses',
                        'requested_byId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'linked_fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'notes',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'medications',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'procedures',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'icd10_codes',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'diagnoses',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'facility_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'provider_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'event_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_events',
                        'reportId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_chronology_reports',
                        'generated_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_chronology_reports',
                        'export_fileId',
                        { transaction }
                    );
                
            
                
            
                
                    await queryInterface.removeColumn(
                        'medical_chronology_reports',
                        'overview',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_chronology_reports',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_chronology_reports',
                        'report_title',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_chronology_reports',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'medical_chronology_reports',
                        'requested_byId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'error_message',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'finished_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'started_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'export_fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'summary_text',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'transcript_text',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'confidence_avg',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'speaker_diarization',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'target_language',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'source_language',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'media_fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'transcription_jobs',
                        'requested_byId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_turns',
                        'spoken_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_turns',
                        'audio_fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_turns',
                        'content',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_turns',
                        'turn_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_turns',
                        'roleId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_turns',
                        'mock_trialId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_roles',
                        'instructions',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_roles',
                        'display_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_roles',
                        'actor_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_roles',
                        'role_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trial_roles',
                        'mock_trialId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'scenario_brief',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'ended_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'started_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'scheduled_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'input_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'mode',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'session_title',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'mock_trials',
                        'ownerId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'citator_checks',
                        'checked_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'citator_checks',
                        'conflicts_summary',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'citator_checks',
                        'analysis',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'citator_checks',
                        'standing',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'citator_checks',
                        'legal_sourceId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'citator_checks',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'citator_checks',
                        'requested_byId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_results',
                        'rule_statement',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_results',
                        'snippet',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_results',
                        'relevance_score',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_results',
                        'legal_sourceId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_results',
                        'research_queryId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'last_updated_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'source_url',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'summary',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'full_text',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'court',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'decision_date',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'citation',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'title',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'jurisdiction',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_sources',
                        'source_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_queries',
                        'filters_json',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_queries',
                        'searched_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_queries',
                        'source_scope',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_queries',
                        'jurisdiction',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_queries',
                        'query_text',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_queries',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'research_queries',
                        'requested_byId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'document_versions',
                        'saved_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'document_versions',
                        'content_snapshot',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'document_versions',
                        'change_source',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'document_versions',
                        'version_number',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'document_versions',
                        'documentId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'last_edited_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'export_fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'content',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'format',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'document_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'document_title',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'templateId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'generated_documents',
                        'ownerId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'help_text',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'sort_order',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'default_value',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'is_required',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'value_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'label',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'field_key',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'template_fields',
                        'templateId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'source_fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'is_public',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'template_body',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'description',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'jurisdiction',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'template_category',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'template_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'legal_templates',
                        'ownerId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'error_message',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'completed_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'started_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'queued_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'cost_usd',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'output_summary',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'input_summary',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'job_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'ai_jobs',
                        'requested_byId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_messages',
                        'sent_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_messages',
                        'completion_tokens',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_messages',
                        'prompt_tokens',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_messages',
                        'model_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_messages',
                        'content',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_messages',
                        'sender',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_messages',
                        'threadId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_threads',
                        'last_activity_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_threads',
                        'is_pinned',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_threads',
                        'thread_scope',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_threads',
                        'title',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_threads',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'assistant_threads',
                        'ownerId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'error_message',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'finished_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'started_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'result_text',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'page_count',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'language',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'extraction_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'file_extractions',
                        'fileId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'tags',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'uploaded_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'processing_status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'is_ocr_required',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'checksum_sha256',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'storage_key',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'storage_provider',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'size_bytes',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'file_extension',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'content_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'file_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'files',
                        'ownerId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'notes',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'address',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'phone',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'email',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'organization_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'display_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'party_role',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matter_parties',
                        'matterId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'notes',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'next_hearing_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'filed_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'case_number',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'court_name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'jurisdiction',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'matter_type',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'title',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'matters',
                        'ownerId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'feature_flags',
                        'is_enabled',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'feature_flags',
                        'default_plan_access',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'feature_flags',
                        'description',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'feature_flags',
                        'name',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'feature_flags',
                        'key',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'provider_subscription_ref',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'provider_customer_ref',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'payment_provider',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'canceled_at',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'current_period_end',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'current_period_start',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'currency',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'price_amount',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'billing_period',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'status',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'subscriptions',
                        'userId',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'permissions',
                        'name',
                        { transaction }
                    );
                
            
                
            
                
                    await queryInterface.removeColumn(
                        'roles',
                        'role_customization',
                        { transaction }
                    );
                
            
                
                    await queryInterface.removeColumn(
                        'roles',
                        'name',
                        { transaction }
                    );
                
            
                
            
                
                    await queryInterface.removeColumn(
                        'users',
                        'app_roleId',
                        { 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('audit_events', { transaction });
                
            
                
                    await queryInterface.dropTable('causation_analyses', { transaction });
                
            
                
                    await queryInterface.dropTable('medical_events', { transaction });
                
            
                
                    await queryInterface.dropTable('medical_chronology_reports', { transaction });
                
            
                
                    await queryInterface.dropTable('transcription_jobs', { transaction });
                
            
                
                    await queryInterface.dropTable('mock_trial_turns', { transaction });
                
            
                
                    await queryInterface.dropTable('mock_trial_roles', { transaction });
                
            
                
                    await queryInterface.dropTable('mock_trials', { transaction });
                
            
                
                    await queryInterface.dropTable('citator_checks', { transaction });
                
            
                
                    await queryInterface.dropTable('research_results', { transaction });
                
            
                
                    await queryInterface.dropTable('legal_sources', { transaction });
                
            
                
                    await queryInterface.dropTable('research_queries', { transaction });
                
            
                
                    await queryInterface.dropTable('document_versions', { transaction });
                
            
                
                    await queryInterface.dropTable('generated_documents', { transaction });
                
            
                
                    await queryInterface.dropTable('template_fields', { transaction });
                
            
                
                    await queryInterface.dropTable('legal_templates', { transaction });
                
            
                
                    await queryInterface.dropTable('ai_jobs', { transaction });
                
            
                
                    await queryInterface.dropTable('assistant_messages', { transaction });
                
            
                
                    await queryInterface.dropTable('assistant_threads', { transaction });
                
            
                
                    await queryInterface.dropTable('file_extractions', { transaction });
                
            
                
                    await queryInterface.dropTable('files', { transaction });
                
            
                
                    await queryInterface.dropTable('matter_parties', { transaction });
                
            
                
                    await queryInterface.dropTable('matters', { transaction });
                
            
                
                    await queryInterface.dropTable('feature_flags', { transaction });
                
            
                
                    await queryInterface.dropTable('subscriptions', { transaction });
                
            
                
                    await queryInterface.dropTable('permissions', { transaction });
                
            
                
                    await queryInterface.dropTable('roles', { transaction });
                
            
                
                    await queryInterface.dropTable('users', { transaction });
                
            
            await transaction.commit();
        } catch (err) {
            await transaction.rollback();
            throw err;
        }
    }
};
