예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public SqlUpdateApplyer(TableDiffGeneratorContext context)
        {
            if (string.IsNullOrWhiteSpace(context.ProjectName))
            {
                throw new Exception("Require ProjectName to be set in context");
            }
            if (context.SqlScripts.Count == 0)
            {
                throw new Exception("Require SqlScript to be set in context");
            }
            if (string.IsNullOrWhiteSpace(context.ResolvedUpdateRevision))
            {
                throw new Exception("Require ResolvedUpdateRevision to be set in context");
            }

            if (string.IsNullOrWhiteSpace(context.MetadataTable))
            {
                context.MetadataTable = "qptmds.MDFile";
            }
            if (string.IsNullOrWhiteSpace(context.SqlConnectionString))
            {
                context.SqlConnectionString =
                    "Data Source=(local);Initial Catalog=z3;Integrated Security=True;Application Name=z3test";
            }

            this._context = context;
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 public DataTableDiffGenerator(TableDiffGeneratorContext context)
 {
     _context = context;
     if (null == _context.DiffPairs)
     {
         throw new Exception("DataTableDiffGenerator: diffpairs was not set");
     }
     _diffs = _context.DiffPairs.ToArray();
 }
예제 #3
0
        /// <summary>
        /// Формирует полный контекст сравнения обновления данных
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        public static TableDiffGeneratorContext GenerateContext(DiffPair[] update)
        {
            var tdc = new TableDiffGeneratorContext();

            tdc.DiffPairs = update;
            var dtdg = new DataTableDiffGenerator(tdc);

            dtdg.Generate();
            var sqlg = new SqlDiffGenerator(tdc);

            sqlg.Generate();
            if (tdc.Tables.All(_ => _.Definitions.Count == 0))
            {
                tdc.SqlScripts.Clear();
            }
            return(tdc);
        }
예제 #4
0
        /// <summary>
        /// Выполняет обновление данных с указанными настройками
        /// </summary>
        /// <param name="parameters"></param>
        public void Execute(DataDiffConsoleParameters parameters)
        {
            var ctx = new TableDiffGeneratorContext {
                RootDirectory       = parameters.CheckoutDirectory,
                GitUrl              = parameters.RepositoryDirectory,
                ProjectDirectory    = parameters.ProjectDirectory,
                OutputDirectory     = parameters.ProjectDirectory + ".output",
                GitBranch           = parameters.Branch,
                ProjectName         = parameters.ProjectName,
                SqlConnectionString = parameters.Connection,
                NoApply             = !parameters.RegisterInMetaTable && !parameters.ApplyToDatabase,
                FullUpdate          = parameters.FullUpdate,
                OnlyRegister        = !parameters.ApplyToDatabase && parameters.RegisterInMetaTable,
                Log             = parameters.Log,
                BSharpPrototype = parameters.Prototype
            };

            ctx.Log.Info("Start updater");
            new DiffExecutor(ctx).Execute();
            File.WriteAllText(Path.Combine(parameters.CheckoutDirectory, "diff-script.sql"), string.Join("\r\nGO\r\n", ctx.SqlScripts));
            ctx.Log.Info("End updater");
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public DiffPairGenerator(TableDiffGeneratorContext context)
 {
     this._context = context;
     if (null == _context.Log)
     {
         _context.Log = ConsoleLogWriter.CreateLog("main", customFormat: "${Message}", level: LogLevel.Trace);
     }
     if (null != _context.PreparedContext)
     {
         if (string.IsNullOrWhiteSpace(_context.ProjectDirectory))
         {
             throw new Exception("ProjectDirectory is required");
         }
         if (string.IsNullOrWhiteSpace(_context.GitBranch))
         {
             _context.GitBranch = "master";
         }
         if (string.IsNullOrWhiteSpace(_context.RootDirectory))
         {
             _context.RootDirectory = Path.GetTempFileName();
         }
         if (string.IsNullOrWhiteSpace(_context.GitUrl))
         {
             if (!Directory.Exists(Path.Combine(_context.RootDirectory, ".git")))
             {
                 throw new Exception("no valid repo directory, nor git URL was given");
             }
         }
         if (string.IsNullOrWhiteSpace(_context.GitUpdateRevision))
         {
             _context.GitUpdateRevision = "HEAD";
         }
     }
     if (string.IsNullOrWhiteSpace(_context.BSharpPrototype))
     {
         _context.BSharpPrototype = "db-meta";
     }
 }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public SqlDiffGenerator(TableDiffGeneratorContext context)
        {
            this._context = context;
            if (null == _context.Tables)
            {
                throw new Exception("SqlDiffGenerator: tables are not defined");
            }
            if (null == _context.SqlOutput)
            {
                _context.SqlOutput = sw;
            }
            this._tables = _context.Tables.OrderBy(_ => _.TableName).ToArray();
            var cnt = _tables.SelectMany(_ => _.Definitions).Count();

            if (cnt >= 10000)
            {
                this._filegroups = _tables.GroupBy(_ => _.ScriptFile).ToArray();
            }
            else
            {
                this._filegroups = _tables.GroupBy(_ => "MAIN").ToArray();
            }
            this._output = _context.SqlOutput;
        }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public DiffExecutor(TableDiffGeneratorContext context)
 {
     _context = context;
 }