Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd!" -p 1400:1433 -d mcr.microsoft.com/mssql/server:2017-latest
            var baseDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\"));
            var traceService  = new ConsoleTraceService {
                IsDebugEnabled = true
            };
            var configuration = new YuniqlConfiguration
            {
                WorkspacePath      = Path.Combine(baseDirectory, "_db"),
                ConnectionString   = "Server=localhost,1400;Database=yuniqldb;User Id=SA;Password=P@ssw0rd!",
                AutoCreateDatabase = true,
                Tokens             = new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>("VwColumnPrefix1", "Vw1"),
                    new KeyValuePair <string, string>("VwColumnPrefix2", "Vw2"),
                    new KeyValuePair <string, string>("VwColumnPrefix3", "Vw3"),
                    new KeyValuePair <string, string>("VwColumnPrefix4", "Vw4")
                }
            };

            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create();

            migrationService.Initialize(configuration.ConnectionString);
            migrationService.Run(
                configuration.WorkspacePath,
                configuration.TargetVersion,
                configuration.AutoCreateDatabase,
                configuration.Tokens,
                configuration.VerifyOnly,
                configuration.BulkSeparator);

            var requiredDbVersion = "v1.01";
            var currentDbVersion  = migrationService.GetCurrentVersion();

            if (currentDbVersion != requiredDbVersion)
            {
                throw new ApplicationException($"Startup failed. " +
                                               $"Application requires database version {requiredDbVersion} but current version is {currentDbVersion}." +
                                               $"Deploy the latest compatible schema version of database and run again.");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //1. deploy new sql server on docker
            //$ docker run -dit -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd!" -p 1400:1433 -d mcr.microsoft.com/mssql/server:2017-latest

            //2. create custom trace message sinks
            var traceService = new ConsoleTraceService {
                IsDebugEnabled = true
            };

            //3. configure your migration run
            var configuration = new YuniqlConfiguration
            {
                WorkspacePath      = Path.Combine(Environment.CurrentDirectory, "_db"),
                ConnectionString   = "Server=localhost,1400;Database=yuniqldb;User Id=SA;Password=P@ssw0rd!",
                AutoCreateDatabase = true
            };

            //4. run migrations
            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create();

            migrationService.Initialize(configuration.ConnectionString);
            migrationService.Run(
                configuration.WorkspacePath,
                targetVersion: configuration.TargetVersion,
                autoCreateDatabase: configuration.AutoCreateDatabase
                );

            //5. validate for schema version compatibility
            var requiredDbVersion = "v0.00";
            var currentDbVersion  = migrationService.GetCurrentVersion();

            if (currentDbVersion != requiredDbVersion)
            {
                throw new ApplicationException($"Startup failed. " +
                                               $"Application requires database version {requiredDbVersion} but current version is {currentDbVersion}." +
                                               $"Deploy the latest compatible schema version of database and run again.");
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //1. deploy new sql server on docker
            //$ docker run -dit -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd!" -p 1400:1433 -d mcr.microsoft.com/mssql/server:2017-latest

            //2. create custom trace message sinks, this can be your own logger framework
            var traceService = new ConsoleTraceService {
                IsDebugEnabled = true
            };

            //3. configure your migration run
            var configuration = Configuration.Instance;

            configuration.Platform             = SUPPORTED_DATABASES.SQLSERVER;
            configuration.Workspace            = Path.Combine(Environment.CurrentDirectory, "_db");
            configuration.ConnectionString     = "Server=localhost,1400;Database=helloyuniql;User Id=SA;Password=P@ssw0rd!";
            configuration.IsAutoCreateDatabase = true;
            configuration.IsDebug = true;

            //4. run migrations
            var migrationServiceFactory = new MigrationServiceFactory(traceService);
            var migrationService        = migrationServiceFactory.Create();

            migrationService.Run();

            //5. alternatively, you can validate app for schema version compatibility
            var requiredDbVersion = "v0.00";
            var currentDbVersion  = migrationService.GetCurrentVersion();

            if (currentDbVersion != requiredDbVersion)
            {
                throw new ApplicationException($"Startup failed. " +
                                               $"Application requires database version {requiredDbVersion} but current version is {currentDbVersion}." +
                                               $"Deploy the latest compatible schema version of database and run again.");
            }
        }