Beispiel #1
0
        private static async Task <int> Preview(PreviewVerb verb)
        {
            Logger.Info("Running command: preview (showing only preview of migrations to be applied)");

            DatabaseMigrator migrator = new DatabaseMigrator(verb);
            await migrator.PreviewAsync(verb);

            return(0);
        }
Beispiel #2
0
        public async Task PreviewAsync(PreviewVerb verb)
        {
            await InitializeAsync();

            var appliedMigrations = await executor.PreviewAsync();

            if (appliedMigrations.Count == 0)
            {
                Logger.Info("There are no pending migrations to be applied.");
            }
            else
            {
                string GetMigrationLines(PendingModuleMigration moduleMigration)
                {
                    return(string.Join('\n',
                                       moduleMigration.Migrations.Select((x, i) =>
                                                                         $"  {i + 1}. {x.ToString(false)}{(x.ModuleName != moduleMigration.Specifier.ModuleName ? " (dependency)" : "")}")));
                }

                var    moduleInfos      = appliedMigrations.Select(x => $"{x.Specifier.ModuleName}{(x.Migrations.Any(y => y.Version != null) ? $" to version {x.Migrations.OrderByDescending(y => y.Version).First().Version}" : "")} ({x.Migrations.Count()} migration(s)):\n{GetMigrationLines(x)}");
                string moduleInfosLines = string.Join("\n\n", moduleInfos);
                Logger.Info($"There are {appliedMigrations.Count} modules to be migrated:\n\n{moduleInfosLines}");
            }
        }