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 BuildDropConstraint(DatabaseTable databaseTable, DatabaseConstraint constraint) { try { var txt = _migrationGenerator.DropConstraint(databaseTable, constraint); Clipboard.SetText(txt, TextDataFormat.UnicodeText); } catch (Exception exception) { Debug.WriteLine(exception.Message); } }
public string BuildDropConstraint(DatabaseTable databaseTable, DatabaseConstraint constraint) { StringBuilder sb = new StringBuilder(); try { sb.Append(m_migrationGenerator.DropConstraint(databaseTable, constraint)); } catch (Exception exception) { Debug.WriteLine(exception.Message); } return(sb.ToString()); }
public string DropConstraint(DatabaseTable databaseTable, DatabaseConstraint databaseConstraint) { return(_migration.DropConstraint(databaseTable, databaseConstraint)); }