Inheritance: IDisposable
Esempio n. 1
0
        public override void Execute(HortonOptions options)
        {
            using (var schemaInfo = new SchemaInfo(options))
            {
                schemaInfo.InitializeTable();

                Program.PrintLine("=== History ===");
                Program.PrintLine();
                Program.PrintLine("Timestamp (UTC)        | File Name            | User");
                Program.PrintLine("---------------------------------------------------------------------");
                foreach (var item in schemaInfo.AppliedMigrations)
                {
                    Program.PrintLine($"{item.AppliedUTC.ToString("yyyy-MM-dd HH:mm:ss.ff")} | {TrimOrPad(item.FileName, 20)} | {TrimOrPad(item.SystemUser, 20)}");
                }
            }
        }
Esempio n. 2
0
        public override void Execute(HortonOptions options)
        {
            using (var schemaInfo = new SchemaInfo(options))
            {
                schemaInfo.InitializeTable();

                var loader = new FileLoader(options.MigrationsDirectoryPath);
                loader.LoadAllFiles();

                Program.PrintLine("=== Info ===");
                Program.PrintLine();
                Program.PrintLine("The following scripts will execute...");

                bool willExecuteMigrations = true;

                foreach (var file in loader.Files)
                {
                    var existingRecord = schemaInfo.AppliedMigrations.SingleOrDefault(x => x.FileNameMD5Hash == file.FileNameHash);
                    if (existingRecord != null)
                    {
                        if (file.ContentMatches(existingRecord.ContentSHA1Hash))
                        {
                            continue;
                        }
                        if (file.ConflictOnContent)
                        {
                            Program.PrintLine(ConsoleColor.Red, $"\nCONFLICT: The script \"{file.FileName}\" has changed since it was applied on \"{existingRecord.AppliedUTC.ToString("yyyy-MM-dd HH:mm:ss.ff")}\".");
                            willExecuteMigrations = false;
                            continue;
                        }
                    }
                    Program.PrintLine(ConsoleColor.DarkGreen, $"\n\"{file.FileName}\" will execute on UPDATE.");
                }

                if (!willExecuteMigrations)
                {
                    Program.PrintLine(ConsoleColor.Red, $"\nWARNING! Migrations will not execute until conflicts are resolved.");
                    Environment.Exit(1);
                }

                Program.PrintLine();
                Program.PrintLine("Finished.");
            }
        }
Esempio n. 3
0
        public override void Execute(HortonOptions options)
        {
            using (var schemaInfo = new SchemaInfo(options))
            {
                schemaInfo.InitializeTable();

                var loader = new FileLoader(options.MigrationsDirectoryPath);
                loader.LoadAllFiles();

                Program.PrintLine("=== Sync ===");
                Program.PrintLine();
                Program.PrintLine("Synchronizing conflicting scripts...");

                foreach (var file in loader.Files)
                {
                    var existingRecord = schemaInfo.AppliedMigrations.SingleOrDefault(x => x.FileNameMD5Hash == file.FileNameHash);
                    if (existingRecord != null)
                    {
                        if (!file.ContentMatches(existingRecord.ContentSHA1Hash))
                        {
                            Program.Print(ConsoleColor.Red, $"\n\"{file.FileName}\" has changed since it was applied on \"{existingRecord.AppliedUTC.ToString("yyyy-MM-dd HH:mm:ss.ff")}\" and will be updated.");
                            Program.Print(ConsoleColor.Red, " Type 'Y' to Continue.");
                            Program.PrintLine();
                            var c = Console.ReadKey();
                            if (c.KeyChar == 'y' || c.KeyChar == 'Y')
                            {
                                Program.PrintLine($"\nUpdating \"{file.FileName}\" with hash \"{file.ContentSHA1Hash}\"");
                                schemaInfo.ResyncMigration(file);
                            }
                            else
                            {
                                Program.PrintLine("\nAborting...");
                                Environment.Exit(1);
                            }
                        }
                    }
                }

                Program.PrintLine();
                Program.PrintLine("Finished.");
            }
        }