示例#1
0
        private static void ExecuteApp(CommandOption applyMigrate, CommandOption verifyMigrate, CommandOption appSettingsDirectory, IOperations operations)
        {
            if (verifyMigrate.HasValue() && applyMigrate.HasValue())
            {
                Console.WriteLine("ef-migrate and ef-migrate-check are mutually exclusive, select one, and try again");
                Environment.Exit(2);
            }

            if (verifyMigrate.HasValue())
            {
                Console.WriteLine("Validating status of Entity Framework migrations");

                var migrations = operations.GetEfMigrations(GetConfiguration(appSettingsDirectory)).ToList();

                if (!migrations.Any())
                {
                    Console.WriteLine("No pending migrations");
                    Environment.Exit(0);
                }

                Console.WriteLine("Pending migrations {0}", migrations.Count);
                foreach (var migration in migrations)
                {
                    Console.WriteLine($"\t{migration}");
                }

                Environment.Exit(3);
            }

            if (applyMigrate.HasValue())
            {
                Console.WriteLine("Applying Entity Framework migrations...");

                operations.ApplyEfMigrations(GetConfiguration(appSettingsDirectory));

                Environment.Exit(0);
            }

            Environment.Exit(operations.Apply(GetConfiguration(appSettingsDirectory)));
        }