void WhenDatabaseIsUpgraded()
 {
     upgradeEngine = upgradeEngineBuilder.Build();
     upgradeResult = upgradeEngine.PerformUpgrade();
 }
Esempio n. 2
0
 public DatabaseUpgradeResult Upgrade()
 {
     return(_upgradeEngine.PerformUpgrade());
 }
 internal DatabaseUpgradeResult PerformUpgrade()
 {
     return(_upgradeEngine.PerformUpgrade());
 }
Esempio n. 4
0
 public DatabaseUpgradeResult PerformUpgrade() => _upgradeEngine.PerformUpgrade();
Esempio n. 5
0
        private static int Main(string[] args)
        {
            bool debug = (args.Length != 0);

            var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\MeetTracker";

            try
            {
                Directory.CreateDirectory(folderPath);
            }
            catch (IOException e)
            {
                Console.WriteLine("Could not create path : {0}", e.ToString());
                folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            }

            var connectionString = "Data Source=" + folderPath + "\\meet.db; Version=3";

            UpgradeEngine upgrader = null;

            try
            {
                upgrader =
                    DeployChanges.To
                    .SQLiteDatabase(connectionString)
                    .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
                    .LogToConsole()
                    .Build();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(-1);
            }

            if (!upgrader.IsUpgradeRequired())
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Success!");
                Console.ResetColor();
                if (debug)
                {
                    Console.ReadKey();
                }
                return(0);
            }

            DatabaseUpgradeResult result = null;

            try
            {
                result = upgrader.PerformUpgrade();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (!result.Successful)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(result.Error);
                    Console.ResetColor();
                    if (debug)
                    {
                        Console.ReadKey();
                    }
                    return(-1);
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(connectionString);
            Console.WriteLine("Success!");
            Console.ResetColor();
            if (debug)
            {
                Console.ReadKey();
            }
            return(0);
        }
Esempio n. 6
0
File: Program.cs Progetto: FWTL/Auth
        private static int Main(string[] args)
        {
            if (Environment.UserInteractive)
            {
                args = new string[2];

                string catalog  = "FWTL.App";
                string user     = "******";
                string password = "******";
                args[0] = $"Server=localhost;Initial Catalog={catalog};Persist Security Info=False;User ID={user};Password={password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;";
                string currentDictionary = Directory.GetCurrentDirectory();
                string basePath          = currentDictionary.Substring(0, currentDictionary.IndexOf("FWTL.Database.Migrator", StringComparison.Ordinal));
                args[1] = Path.Combine(basePath, "FWTL.Database");
            }

            if (args.Length != 2)
            {
                return(ReturnError(
                           "Invalid args. You have to specify connection string and scripts path"));
            }

            var connectionString = args[0];
            var scriptsPath      = args[1];

            Console.WriteLine("Start executing preDeployment scripts...");
            string        preDeploymentScriptsPath     = Path.Combine(scriptsPath, "PreDeployment");
            UpgradeEngine preDeploymentScriptsExecutor =
                DeployChanges.To
                .SqlDatabase(connectionString)
                .WithScriptsFromFileSystem(preDeploymentScriptsPath, new FileSystemScriptOptions
            {
                IncludeSubDirectories = true
            })
                .LogToConsole()
                .JournalTo(new NullJournal())
                .Build();

            var preDeploymentUpgradeResult = preDeploymentScriptsExecutor.PerformUpgrade();

            if (!preDeploymentUpgradeResult.Successful)
            {
                return(ReturnError(preDeploymentUpgradeResult.Error.ToString()));
            }

            ShowSuccess();

            Console.WriteLine("Start executing migration scripts...");
            var migrationScriptsPath = Path.Combine(scriptsPath, "Migrations");
            var upgrader             =
                DeployChanges.To
                .SqlDatabase(connectionString)
                .WithScriptsFromFileSystem(migrationScriptsPath, new FileSystemScriptOptions
            {
                IncludeSubDirectories = true
            })
                .LogToConsole()
                .JournalToSqlTable("dbo", "MigrationsJournal")
                .Build();

            var result = upgrader.PerformUpgrade();

            if (!result.Successful)
            {
                return(ReturnError(result.Error.ToString()));
            }

            ShowSuccess();

            Console.WriteLine("Start executing postDeployment scripts...");
            string postDeploymentScriptsPath     = Path.Combine(scriptsPath, "PostDeployment");
            var    postDeploymentScriptsExecutor =
                DeployChanges.To
                .SqlDatabase(connectionString)
                .WithScriptsFromFileSystem(postDeploymentScriptsPath, new FileSystemScriptOptions
            {
                IncludeSubDirectories = true
            })
                .LogToConsole()
                .JournalTo(new NullJournal())
                .Build();

            var postDeploymentUpgradeResult = postDeploymentScriptsExecutor.PerformUpgrade();

            if (!postDeploymentUpgradeResult.Successful)
            {
                return(ReturnError(result.Error.ToString()));
            }

            ShowSuccess();

            return(0);
        }