示例#1
0
        public void GetAlterSql(ISqlDumper dmp)
        {
            DumpSubFolder(dmp, "before");
            VersionDef current = this;
            VersionDef prev    = current.GetVersion(-1);
            VersionDb  vdb     = current.Db;

            DatabaseStructure curstruct  = DatabaseStructure.Load(current.GetFile());
            DatabaseStructure prevstruct = null;

            if (prev != null)
            {
                prevstruct = DatabaseStructure.Load(prev.GetFile());
            }

            ISqlDialect dialect = vdb.Dialect;

            DbDiffOptions opts = new DbDiffOptions();

            //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag);
            opts.AllowRecreateTable = true;
            if (prevstruct == null)
            {
                dmp.CreateDatabaseObjects(curstruct);
            }
            else
            {
                dmp.AlterDatabase(prevstruct, curstruct, opts, new Plugin.dbmodel.DbDefSource(prevstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), AddSubFoldersToPlan);
            }

            DumpSubFolder(dmp, "after");

            current.SetVersionSql(dmp);
        }
示例#2
0
        public void GetAlterSql(ISqlDumper dmp)
        {
            VersionDef current = Version;
            VersionDef prev    = Version.GetVersion(-1);

            var vardef = new VariantDef(VariantFile);
            DatabaseStructure curstruct  = current.LoadStructure(vardef);
            DatabaseStructure prevstruct = prev.LoadStructure(vardef);
            ISqlDialect       dialect    = curstruct.Dialect ?? Version.Db.Dialect;

            DbDiffOptions opts = new DbDiffOptions();

            //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag);
            opts.AllowRecreateTable = true;
            if (prevstruct == null)
            {
                dmp.CreateDatabaseObjects(curstruct);
            }
            else
            {
                dmp.AlterDatabase(prevstruct, curstruct, opts, new Plugin.dbmodel.DbDefSource(prevstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), null);
            }

            current.SetVersionSql(dmp);
        }
示例#3
0
            public override void RunCommand()
            {
                IDatabaseSource srcDb = m_source.GetConnection();
                IDatabaseSource dstDb = m_target.GetConnection();

                Async.SafeOpen(srcDb.Connection); Async.SafeOpen(dstDb.Connection);
                var src  = srcDb.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null);
                var dst  = dstDb.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null);
                var opts = new DbDiffOptions();

                opts.IgnoreColumnOrder = true;
                //var diff = new DatabaseDiff(src, dst, opts);
                ISqlDialect dial;

                if (Dialect != null)
                {
                    dial = (ISqlDialect)DialectAddonType.Instance.FindHolder(Dialect).CreateInstance();
                }
                else
                {
                    dial = new GenericDialect();
                }
                using (TextWriter fw = GetOutputStream())
                {
                    SqlOutputStream so  = new SqlOutputStream(dial, fw, new SqlFormatProperties());
                    ISqlDumper      dmp = dial.CreateDumper(so, new SqlFormatProperties());
                    dmp.AlterDatabase(src, dst, opts, new DbDefSource(src, DbDefSource.ReadOnly.Flag));
                    //dmp.TargetDb = new DbDefSource(dst, DbDefSource.ReadOnly.Flag);
                    //diff.Actions.GenerateScript(dmp);
                }
                Async.SafeClose(srcDb.Connection); Async.SafeClose(dstDb.Connection);
            }
示例#4
0
        public override void GenerateSql(AppObject appobj, ISqlDumper dmp, ISqlDialect dialect)
        {
            var vdb = (VersionDbAppObject)appobj;

            var fromv = vdb.GetVdb().FindVersion(FromVersion);
            var tov   = vdb.GetVdb().FindVersion(ToVersion);

            DatabaseStructure fromstruct = null;

            if (fromv != null)
            {
                fromstruct = DatabaseStructure.Load(fromv.GetFile());
            }
            DatabaseStructure tostruct = null;

            if (tov != null)
            {
                tostruct = DatabaseStructure.Load(tov.GetFile());
            }
            if (tostruct == null)
            {
                return;
            }

            DbDiffOptions opts = new DbDiffOptions();

            //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag);
            opts.AllowRecreateTable = true;
            if (fromstruct == null)
            {
                dmp.CreateDatabaseObjects(tostruct);
            }
            else
            {
                dmp.AlterDatabase(fromstruct, tostruct, opts, new Plugin.dbmodel.DbDefSource(fromstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), null);
            }

            tov.SetVersionSql(dmp);
        }