public static void ExecuteScripts(string providerName, string connectionString, string tableName, IMigrationGenerator migrationGenerator) { var table = CreateTestTable(tableName); var newColumn = CreateNewColumn(); var uniqueConstraint = CreateUniqueConstraint(newColumn); var fk = CreateForeignKey(table); var index = CreateUniqueIndex(newColumn, tableName); var createTable = migrationGenerator.AddTable(table); var addColumn = migrationGenerator.AddColumn(table, newColumn); var addUniqueConstraint = migrationGenerator.AddConstraint(table, uniqueConstraint); var addForeignKey = migrationGenerator.AddConstraint(table, fk); var addUniqueIndex = migrationGenerator.AddIndex(table, index); var dropUniqueIndex = migrationGenerator.DropIndex(table, index); var dropForeignKey = migrationGenerator.DropConstraint(table, fk); var dropUniqueConstraint = migrationGenerator.DropConstraint(table, uniqueConstraint); var dropColumn = migrationGenerator.DropColumn(table, newColumn); var dropTable = migrationGenerator.DropTable(table); var factory = DbProviderFactories.GetFactory(providerName); using (var con = factory.CreateConnection()) { con.ConnectionString = connectionString; using (var cmd = con.CreateCommand()) { con.Open(); using (var tx = con.BeginTransaction()) { cmd.Transaction = tx; Execute(cmd, createTable); Execute(cmd, addColumn); Execute(cmd, addUniqueConstraint); Execute(cmd, addForeignKey); Execute(cmd, dropForeignKey); Execute(cmd, dropUniqueConstraint); //now we've dropped the unique constraint, add a unique index Execute(cmd, addUniqueIndex); Execute(cmd, dropUniqueIndex); Execute(cmd, dropColumn); Execute(cmd, dropTable); } } } }
public void BuildDropIndex(DatabaseTable databaseTable, DatabaseIndex index) { try { var txt = _migrationGenerator.DropIndex(databaseTable, index); Clipboard.SetText(txt, TextDataFormat.UnicodeText); } catch (Exception exception) { Debug.WriteLine(exception.Message); } }
public string BuildDropIndex(DatabaseTable databaseTable, DatabaseIndex index) { StringBuilder sb = new StringBuilder(); try { sb.Append(m_migrationGenerator.DropIndex(databaseTable, index)); } catch (Exception exception) { Debug.WriteLine(exception.Message); } return(sb.ToString()); }
public string DropIndex(DatabaseTable databaseTable, DatabaseIndex index) { return(_migration.DropIndex(databaseTable, index)); }
public static void ExecuteScripts(string providerName, string connectionString, string tableName, IMigrationGenerator migrationGenerator) { var table = CreateTestTable(tableName); var newColumn = CreateNewColumn(); var uniqueConstraint = CreateUniqueConstraint(newColumn); var fk = CreateForeignKey(table); var index = CreateUniqueIndex(newColumn, tableName); var createTable = migrationGenerator.AddTable(table); var addColumn = migrationGenerator.AddColumn(table, newColumn); var addUniqueConstraint = migrationGenerator.AddConstraint(table, uniqueConstraint); var addForeignKey = migrationGenerator.AddConstraint(table, fk); var addUniqueIndex = migrationGenerator.AddIndex(table, index); var dropUniqueIndex = migrationGenerator.DropIndex(table, index); var dropForeignKey = migrationGenerator.DropConstraint(table, fk); var dropUniqueConstraint = migrationGenerator.DropConstraint(table, uniqueConstraint); var dropColumn = migrationGenerator.DropColumn(table, newColumn); var dropTable = migrationGenerator.DropTable(table); var factory = DbProviderFactories.GetFactory(providerName); using (var con = factory.CreateConnection()) { con.ConnectionString = connectionString; using (var cmd = con.CreateCommand()) { con.Open(); using (var tx = con.BeginTransaction()) { cmd.Transaction = tx; Execute(cmd, createTable); Execute(cmd, addColumn); Execute(cmd, addUniqueConstraint); Execute(cmd, addForeignKey); Execute(cmd, dropForeignKey); Execute(cmd, dropUniqueConstraint); //now we've dropped the unique constraint, add a unique index Execute(cmd, addUniqueIndex); Execute(cmd, dropUniqueIndex); Execute(cmd, dropColumn); Execute(cmd, dropTable); } } } }