DeserializeMigration() public static méthode

public static DeserializeMigration ( string this_migration_contents ) : dynamic
this_migration_contents string
Résultat dynamic
Exemple #1
0
        private void MigrateTo(int migration)
        {
            var migrations = _migration_provider.GetMigrations();
            int current    = _migration_provider.DatabaseMigrationNumber();

            if (migrations.Count < current)
            {
                current = migrations.Count;
            }
            if (migration > migrations.Max(m => m.Key) || migration < 0)
            {
                Console.WriteLine("Invalid Migration");
                return;
            }
            if (migration == current)
            {
                Console.WriteLine("Nothing to be done.");
                return;
            }

            while (current < migration)
            {
                // go Up
                KeyValuePair <string, string> migration_kvp = _migration_provider.GetMigrationWithContents(++current);
                string  migration_json   = migration_kvp.Value;
                dynamic migration_object = Helpers.DeserializeMigration(migration_json);
                Console.WriteLine("Executing " + current + ". Executing Migration " + migration_kvp.Key);
                _database_provider.ExecuteUpCommand(migration_object);
                _database_provider.UpdateMigrationVersion(current);
            }
            while (current > migration && current > 0)
            {
                // go down
                KeyValuePair <string, string> migration_kvp = _migration_provider.GetMigrationWithContents(current);
                string  migration_json   = migration_kvp.Value;
                dynamic migration_object = Helpers.DeserializeMigration(migration_json);
                Console.WriteLine("Removing " + (current) + ". Executing Migration " + migration_kvp.Key);
                _database_provider.ExecuteDownCommand(migration_object);
                _database_provider.UpdateMigrationVersion(--current);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        public void Execute()
        {
            int  migration_id     = 0;
            bool has_extra        = _configuration.Extra.Any();
            bool extra_is_int     = has_extra && int.TryParse(_configuration.Extra.First(), out migration_id);
            bool migration_exists = extra_is_int && _migration_provider.GetMigrations().ContainsKey(migration_id);

            if (migration_exists)
            {
                var     migration = _migration_provider.GetMigrationWithContents(migration_id);
                var     file      = new FileInfo(migration.Key);
                var     fileName  = file.FullName;
                dynamic up        = Helpers.DeserializeMigration(migration.Value).up;
                if (up.file != null)   // open sql file instead of json for sql file migrations
                {
                    string path = up.file;
                    path = path.Replace("..", "db");
                    if (File.Exists(path))
                    {
                        OpenFileInDefaultEditor(path);
                    }
                    else
                    {
                        Console.WriteLine("Could not find sql file, opening migraion file.");
                        OpenFileInDefaultEditor(fileName);
                    }
                }
                else
                {
                    OpenFileInDefaultEditor(fileName);
                }
            }
            else
            {
                Console.WriteLine("Please specify the number of a valid migration.");
                _configuration.Extra = new List <string>();
                list_viewer.Execute();
            }
        }