Exemplo n.º 1
0
        private static void RunDbScriptUpdate(string dbName, string runScriptFileContent)
        {
            IDbUpdateRunner dbUpdateRunner = new DbUpdateRunner(dbName, configuration.DbConnectionString);

            dbUpdateRunner.RunUpdateAsync(runScriptFileContent).Wait();

            Console.WriteLine("{0} updated", dbName);
        }
Exemplo n.º 2
0
        private static bool RunDbUpdate(
            string dbName,
            string versionFieldName,
            string updatesFolderPath,
            string connectionString)
        {
            IDbVersionManager dbVersionManager = new DbVersionManager(dbName, connectionString);

            int?dbVersion = dbVersionManager.GetVersionAsync(versionFieldName).Result;

            if (dbVersion.HasValue)
            {
                dbVersion++;
            }
            else
            {
                dbVersion = 0;
            }

            IUpdateScriptManager updateScriptManager = new UpdateScriptManager(updatesFolderPath);
            IDbUpdateRunner      dbUpdateRunner      = new DbUpdateRunner(dbName, connectionString);

            bool isUpdated = false;

            foreach (string updateContent in updateScriptManager.GetUpdatesContent(dbVersion.Value))
            {
                isUpdated = true;

                dbUpdateRunner.RunUpdateAsync(updateContent).Wait();
                dbVersionManager.SetVersionAsync(dbVersion.Value, versionFieldName).Wait();

                Console.WriteLine("{0} -> {1} updated to version {2}", dbName, versionFieldName, dbVersion);

                dbVersion++;
            }

            if (!isUpdated)
            {
                Console.WriteLine("Database {0} has not been updated because it is up to date.", dbName);
            }

            return(isUpdated);
        }