Esempio n. 1
0
        private void CreateSql(SortedDictionary <int, string> migrations, SortedDictionary <int, string> migration_contents, Predicate <KeyValuePair <int, string> > allow_migration_func)
        {
            var sql_commands = new Dictionary <string, string>();
            int min          = migrations.Count;
            int max          = 1;

            foreach (var migration in migrations)
            {
                if (allow_migration_func != null)
                {
                    if (!allow_migration_func(migration))
                    {
                        continue;
                    }
                }
                if (migration.Key < min)
                {
                    min = migration.Key;
                }
                if (migration.Key > max)
                {
                    max = migration.Key;
                }
                var     this_migration_contents = migration_contents[migration.Key];
                dynamic migration_object        = Helpers.DeserializeMigration(this_migration_contents);
                var     commands = _sql_formatter.GenerateSQLUp(migration_object);
                if (commands.Length == 1)
                {
                    sql_commands.Add(_sql_formatter.sql_file_name(migration.Value), commands[0]);
                }
                else
                {
                    for (int i = 0; i < commands.Length; i++)
                    {
                        sql_commands.Add(_sql_formatter.sql_file_name(migration.Value) + "." + (i + 1).ToString("000"), commands[i]);
                    }
                }
            }
            WriteFile(sql_commands, min, max);
        }