Esempio n. 1
0
        public Factory(CmdLineArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            feedback    = new ConsoleFeedback();
            clock       = new SystemClock();
            scriptStore = new DiskScriptStore(args.ScriptLocation);

            if (!string.Equals(args.DbType, "SqlServer", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception("Don't recognise DB type: " + args.DbType);
            }
            SqlServerDatabase sqlDatabase = new SqlServerDatabase(args.DbConnectionString);

            database      = sqlDatabase;
            schemaHistory = sqlDatabase;

            if (string.Equals("deploy", args.Mode, StringComparison.InvariantCultureIgnoreCase))
            {
                planner  = new DeployPlanner(scriptStore, schemaHistory);
                executor = new DeployExecutor(scriptStore, schemaHistory, database, clock, feedback);
            }
            else if (string.Equals("rollback", args.Mode, StringComparison.InvariantCultureIgnoreCase))
            {
                planner  = new RollbackPlanner(scriptStore, schemaHistory);
                executor = new RollbackExecutor(scriptStore, schemaHistory, database, clock, feedback);
            }
            else
            {
                throw new Exception("Don't recognise mode: " + args.Mode);
            }
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            Planner       planner;
            Executor      executor;
            SchemaHistory schemaHistory;
            string        destination;

            try
            {
                CmdLineArgs cmdLineArgs = CmdLineArgs.Parse(args);
                Factory     factory     = new Factory(cmdLineArgs);
                planner       = factory.GetPlanner();
                executor      = factory.GetExecutor();
                schemaHistory = factory.GetSchemaHistory();
                destination   = cmdLineArgs.Destination;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(CmdLineArgs.Help);
                return(-1);
            }

            try
            {
                schemaHistory.EnsureHistoryDeployed();
                var plan = planner.MakePlan(destination);
                executor.Execute(plan);
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("ERROR!");
                return(-1);
            }
        }