Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void BuildAddColumn(DatabaseColumn column)
 {
     try
     {
         var txt = _migrationGenerator.AddColumn(column.Table, column);
         Clipboard.SetText(txt, TextDataFormat.UnicodeText);
     }
     catch (Exception exception)
     {
         Debug.WriteLine(exception.Message);
     }
 }
Exemplo n.º 3
0
        public string BuildAddColumn(DatabaseColumn column)
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                sb.Append(m_migrationGenerator.AddColumn(column.Table, column));
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
            }
            return(sb.ToString());
        }
Exemplo n.º 4
0
 public string AddColumn(DatabaseTable databaseTable, DatabaseColumn databaseColumn)
 {
     return(_migration.AddColumn(databaseTable, databaseColumn));
 }
Exemplo n.º 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);
                    }
                }
            }
        }