namespace Bit.Seeder.Migration.Databases; /// /// Interface for database importers that migrate data from SQL Server to various database systems. /// public interface IDatabaseImporter : IDisposable { /// /// Establishes a connection to the target database. /// /// True if connection was successful, false otherwise. bool Connect(); /// /// Closes the connection to the target database. /// void Disconnect(); /// /// Creates a table in the target database from a schema definition. /// /// Name of the table to create. /// List of column names. /// Dictionary mapping column names to their SQL Server data types. /// Optional list of columns that require special handling (e.g., JSON columns). /// True if table was created successfully, false otherwise. bool CreateTableFromSchema( string tableName, List columns, Dictionary columnTypes, List? specialColumns = null); /// /// Retrieves the list of column names for a table. /// /// Name of the table. /// List of column names. List GetTableColumns(string tableName); /// /// Imports data into a table. /// /// Name of the target table. /// List of column names in the data. /// Data rows to import. /// Number of rows to import per batch. /// True if import was successful, false otherwise. bool ImportData( string tableName, List columns, List data, int batchSize = 1000); /// /// Checks if a table exists in the target database. /// /// Name of the table to check. /// True if table exists, false otherwise. bool TableExists(string tableName); /// /// Gets the number of rows in a table. /// /// Name of the table. /// Number of rows in the table. int GetTableRowCount(string tableName); /// /// Drops a table from the database. /// /// Name of the table to drop. /// True if table was dropped successfully, false otherwise. bool DropTable(string tableName); /// /// Disables foreign key constraints to allow data import without referential integrity checks. /// /// True if foreign keys were disabled successfully, false otherwise. bool DisableForeignKeys(); /// /// Re-enables foreign key constraints after data import. /// /// True if foreign keys were enabled successfully, false otherwise. bool EnableForeignKeys(); /// /// Checks if this importer supports optimized bulk copy operations. /// /// True if bulk copy is supported and should be preferred over row-by-row import. bool SupportsBulkCopy(); /// /// Imports data into a table using database-specific bulk copy operations for optimal performance. /// This method uses native bulk import mechanisms like PostgreSQL COPY, SQL Server SqlBulkCopy, /// or multi-row INSERT statements for databases that support them. /// /// Name of the target table. /// List of column names in the data. /// Data rows to import. /// True if bulk import was successful, false otherwise. /// /// This method is significantly faster than ImportData() for large datasets (10-100x speedup). /// If this method returns false, the caller should fall back to ImportData(). /// bool ImportDataBulk( string tableName, List columns, List data); /// /// Tests the connection to the database. /// /// True if connection test was successful, false otherwise. bool TestConnection(); }