예제 #1
0
        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);
                    }
                }
            }
        }
예제 #2
0
 public void BuildAddConstraint(DatabaseTable databaseTable, DatabaseConstraint constraint)
 {
     try
     {
         var txt = _migrationGenerator.AddConstraint(databaseTable, constraint);
         Clipboard.SetText(txt, TextDataFormat.UnicodeText);
     }
     catch (Exception exception)
     {
         Debug.WriteLine(exception.Message);
     }
 }
예제 #3
0
        public string BuildAddConstraint(DatabaseTable databaseTable, DatabaseConstraint constraint)
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                sb.Append(m_migrationGenerator.AddConstraint(databaseTable, constraint));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
            return(sb.ToString());
        }
예제 #4
0
 public string AddConstraint(DatabaseTable databaseTable, DatabaseConstraint databaseConstraint)
 {
     return(_migration.AddConstraint(databaseTable, databaseConstraint));
 }
예제 #5
0
        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);
                    }
                }
            }
        }