예제 #1
0
        public void Update_Database_Runs_New_Everytime_Script()
        {
            //arrange
            string scriptsDirectory =  Path.Combine("Scripts",GetType().Name.Replace("Tester", ""));

            string scriptFileMd5 = ChangeScriptExecutor.GetFileMD5Hash(Path.Combine(scriptsDirectory,"Everytime", "TestScript.sql"));
            var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null);
            new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Drop);

            //act
            bool success = new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update);

            //assert
            int records = 0;
            AssertUsdAppliedDatabaseScriptTable(settings, reader =>
            {
                while (reader.Read())
                {
                    records++;
                    reader["ScriptFile"].ShouldEqual("TestScript.sql");
                    reader["hash"].ShouldEqual(scriptFileMd5);
                }
            });

            success.ShouldEqual(true);
            records.ShouldEqual(1);
        }
        public void Update_Database_ShouldRun_Old_RunAlways_Script()
        {
            //arrange
            string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", ""));

            var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null);
            new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Drop);

            //act
            //run once
            new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update).ShouldBeTrue();
            new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(1);
            var dateApplied = DateTime.MinValue;
            QueryUsdAppliedDatabaseScriptTable(settings, reader =>
            {
                while (reader.Read())
                {
                    reader["ScriptFile"].ShouldEqual("TestScript.sql");
                    dateApplied = (DateTime)reader["DateApplied"];
                }
            });
            dateApplied.ShouldBeGreaterThan(DateTime.MinValue);

            //delete TestTable to ensure script doesn't run again
            new QueryExecutor().ExecuteNonQuery(settings, "drop table TestTable", true);

            //run again
            bool success = new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update);

            //assert
            new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(1);

            DateTime dateAppliedUpdated = DateTime.MinValue; ;
            int records = 0;
            QueryUsdAppliedDatabaseScriptTable(settings, reader =>
            {
                while (reader.Read())
                {
                    records++;
                    reader["ScriptFile"].ShouldEqual("TestScript.sql");
                    dateAppliedUpdated = (DateTime) reader["DateApplied"];
                }

            });

            success.ShouldBeTrue();
            records.ShouldEqual(1);
            dateAppliedUpdated.ShouldBeGreaterThan(dateApplied);
        }
예제 #3
0
        private static void Main(string[] args)
        {
            System.Console.Title = "AliaSQL Database Deployment Tool";
            RequestedDatabaseAction requestedDatabaseAction = RequestedDatabaseAction.Default;

            if (args.Length > 0)
            {
                Enum.TryParse(args[0], true, out requestedDatabaseAction);
            }
            if ((args.Length != 4 && args.Length != 6) || requestedDatabaseAction == RequestedDatabaseAction.Default)
            {
                InvalidArguments();
                return;
            }

            ConnectionSettings settings = null;

            var    deployer        = new ConsoleAliaSQL();
            var    action          = requestedDatabaseAction;
            string server          = args[1];
            string database        = args[2];
            string scriptDirectory = args[3];

            if (args.Length == 4)
            {
                settings = new ConnectionSettings(server, database, true, null, null);
            }

            else if (args.Length == 6)
            {
                string username = args[4];
                string password = args[5];

                settings = new ConnectionSettings(server, database, false, username, password);
            }

            if (deployer.UpdateDatabase(settings, scriptDirectory, action))
            {
                if (Debugger.IsAttached)
                {
                    System.Console.ReadLine();
                }

                return;
            }

            Environment.ExitCode = 1;
        }
예제 #4
0
파일: Program.cs 프로젝트: jlbrown/AliaSQL
        private static void Main(string[] args)
        {
            System.Console.Title = "AliaSQL Database Deployment Tool";
            RequestedDatabaseAction requestedDatabaseAction = RequestedDatabaseAction.Default;
            if(args.Length>0) Enum.TryParse(args[0], true, out requestedDatabaseAction);
            if ((args.Length != 4 && args.Length != 6) || requestedDatabaseAction==RequestedDatabaseAction.Default)
            {
                InvalidArguments();
                return;
            }

            ConnectionSettings settings = null;

            var deployer = new ConsoleAliaSQL();
            var action = requestedDatabaseAction;
            string server = args[1];
            string database = args[2];
            string scriptDirectory = args[3];
            
            if (args.Length == 4)
            {
                settings = new ConnectionSettings(server, database, true, null, null);
            }

            else if (args.Length == 6)
            {
                string username = args[4];
                string password = args[5];

                settings = new ConnectionSettings(server, database, false, username, password);
            }

            if (deployer.UpdateDatabase(settings, scriptDirectory, action))
            {
                if (Debugger.IsAttached)
                    System.Console.ReadLine();

                return;
            }    

            Environment.ExitCode = 1;
        }
        public void Update_Database_Skips_Old_Everytime_Script()
        {
            //arrange
            string scriptsDirectory = Path.Combine("Scripts", GetType().Name.Replace("Tester", ""));

            var settings = new ConnectionSettings(".\\sqlexpress", "aliasqltest", true, null, null);
            new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Drop);

            //act
            //run once 
            new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update).ShouldBeTrue();
            new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(1);

            //delete TestTable to ensure script doesn't run again
            new QueryExecutor().ExecuteNonQuery(settings, "drop table TestTable", true);

            //run again
            bool success = new ConsoleAliaSQL().UpdateDatabase(settings, scriptsDirectory, RequestedDatabaseAction.Update);

            //assert
            new QueryExecutor().ExecuteScalarInteger(settings, "select 1 from dbo.sysobjects where name = 'TestTable' and type='U'").ShouldEqual(0);
        }