Exemplo n.º 1
0
        public static void Run(NpgsqlConnection connection)
        {
            ConnectionName = (Settings.Value.Connection ?? $"{connection.Host}_{connection.Port}_{connection.Database}").SanitazePath();

            if (Settings.Value.Execute != null)
            {
                DumpTitle("** EXECUTION **");
                ExecuteFromSetting(connection);
                return;
            }

            if (Settings.Value.Psql)
            {
                DumpTitle("** PSQL TERMINAL **");
                new PsqlRunner(Settings.Value, connection).TryRunFromTerminal();
                return;
            }

            if (Settings.Value.CommitMd)
            {
                DumpTitle("** COMMIT MARKDOWN (MD) EDITS **");
                BuildMdDiff(connection);
                return;
            }

            if (Settings.Value.SchemaDumpFile != null)
            {
                SchemaFile = string.Format(Path.GetFullPath(Path.Combine(Program.CurrentDir, Settings.Value.SchemaDumpFile)), ConnectionName);
            }

            if (Settings.Value.DataDumpFile != null)
            {
                DataFile = string.Format(Path.GetFullPath(Path.Combine(Program.CurrentDir, Settings.Value.DataDumpFile)), ConnectionName);
            }

            if (Settings.Value.DbObjects || Settings.Value.SchemaDump || Settings.Value.DataDump)
            {
                var builder = new PgDumpBuilder(Settings.Value, connection);
                if (Settings.CheckPgDumpVersion(builder))
                {
                    if (Settings.Value.SchemaDump)
                    {
                        DumpTitle("** SCHEMA DUMP SCRIPT GENERATION **");
                        BuildDump(
                            dumpFile: Settings.Value.SchemaDumpFile,
                            file: SchemaFile,
                            overwrite: Settings.Value.SchemaDumpOverwrite,
                            askOverwrite: Settings.Value.SchemaDumpAskOverwrite,
                            contentFunc: () => builder.GetSchemaContent());
                    }
                    if (Settings.Value.DataDump)
                    {
                        DumpTitle("** DATA DUMP SCRIPT GENERATION **");
                        BuildDump(
                            dumpFile: Settings.Value.DataDumpFile,
                            file: DataFile,
                            overwrite: Settings.Value.DataDumpOverwrite,
                            askOverwrite: Settings.Value.DataDumpAskOverwrite,
                            contentFunc: () => builder.GetDataContent());
                    }
                    if (Settings.Value.DbObjects)
                    {
                        DumpTitle("** DATA OBJECTS SCRIPTS TREE GENERATION **");
                        BuildObjectDumps(builder);
                    }
                }
            }

            if (Settings.Value.Diff)
            {
                DumpTitle("** DIFF  SCRIPT GENERATION **");
                BuildDiffScript(connection);
            }

            if (Settings.Value.Routines)
            {
                DumpTitle("** ROUTINE SOURCE CODE GENERATION **");
                new CodeRoutinesBuilder(connection, Settings.Value, CodeSettings.ToRoutineSettings(Settings.Value)).Build();
            }

            if (Settings.Value.Crud)
            {
                DumpTitle("** CRUD SOURCE CODE GENERATION **");
                new CodeCrudBuilder(connection, Settings.Value, CodeSettings.ToCrudSettings(Settings.Value)).Build();
            }

            if (Settings.Value.UnitTests)
            {
                DumpTitle("** UNIT TEST PROJECT TEMPLATE CODE GENERATION **");
                BuildUnitTests(connection);
            }

            if (Settings.Value.Markdown)
            {
                DumpTitle("** MARKDOWN (MD) GENERATION **");
                BuilMd(connection);
            }

            DumpTitle("", "", "**** FINISHED ****");
        }