コード例 #1
0
ファイル: Migrations.cs プロジェクト: rijuntun/vocadb
 public override void Up()
 {
     Delete.DefaultConstraint().OnTable(TableNames.Tags).OnColumn("Description");
     Alter.Column("Description").OnTable(TableNames.Tags).AsString(int.MaxValue).NotNullable().WithDefaultValue(string.Empty);
     Delete.DefaultConstraint().OnTable(TableNames.Tags).OnColumn("DescriptionEng");
     Alter.Column("DescriptionEng").OnTable(TableNames.Tags).AsString(int.MaxValue).NotNullable().WithDefaultValue(string.Empty);
 }
 public override void Down()
 {
     this.DeleteUserForeignKeys("Instrument");
     Delete.DefaultConstraint().OnTable("Instrument").InSchema("dbo").OnColumn("EffectiveTo");
     Delete.ForeignKey("FK_Instrument_InstrumentVersion").OnTable("Instrument");
     Delete.Table("Instrument");
 }
コード例 #3
0
        public override void Up()
        {
            Delete.Column("userDefaultPermissions").FromTable("umbracoUser");

            //"[DF_umbracoUser_defaultToLiveEditing]""
            Delete.DefaultConstraint().OnTable("umbracoUser").OnColumn("defaultToLiveEditing");
            Delete.Column("defaultToLiveEditing").FromTable("umbracoUser");
        }
コード例 #4
0
        public override void Up()
        {
            Delete.DefaultConstraint().OnTable("Turn")
            .OnColumn("StartedAt");

            Alter.Table("Turn")
            .AlterColumn("StartedAt").AsDateTime().Nullable();
        }
コード例 #5
0
        public override void Up()
        {
            Delete.DefaultConstraint().OnTable(Tables.EnvironmentLog).OnColumn(nameof(EnvironmentLog.Timestamp));

            Alter.Table(Tables.EnvironmentLog)
            .AlterColumn(nameof(EnvironmentLog.Timestamp))
            .AsDateTimeOffset().NotNullable();
        }
コード例 #6
0
        public override void Down()
        {
            Delete.Index("IDX_Book_Title").OnTable(Tables.Book).InSchema(Schemas.Library)
            .OnColumn("Name");

            Alter.Column("Title").OnTable(Tables.Book).InSchema(Schemas.Library)
            .AsString(int.MaxValue);
            Delete.DefaultConstraint().OnTable(Tables.Book).InSchema(Schemas.Library)
            .OnColumn(Columns.IsPublic);
            Delete.ForeignKey("FK_Book_Image").OnTable(Tables.Book).InSchema(Schemas.Library);
        }
コード例 #7
0
        private void MigrateVersions()
        {
            // if the table has already been renamed, we're done
            if (TableExists(Cms.Core.Constants.DatabaseSchema.Tables.ContentVersion))
            {
                return;
            }

            // if the table already exists, we're done
            if (TableExists(Cms.Core.Constants.DatabaseSchema.Tables.DocumentVersion))
            {
                return;
            }

            // if the table has already been renamed, we're done
            if (TableExists(Cms.Core.Constants.DatabaseSchema.Tables.Document))
            {
                return;
            }

            // do it all at once

            // add contentVersion columns
            if (!ColumnExists(PreTables.ContentVersion, "text"))
            {
                AddColumn <ContentVersionDto>(PreTables.ContentVersion, "text");
            }
            if (!ColumnExists(PreTables.ContentVersion, "current"))
            {
                AddColumn <ContentVersionDto>(PreTables.ContentVersion, "current", out var sqls);
                Database.Execute($@"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} SET {SqlSyntax.GetQuotedColumnName("current")}=0");
                foreach (var sql in sqls)
                {
                    Database.Execute(sql);
                }
            }
            if (!ColumnExists(PreTables.ContentVersion, "userId"))
            {
                AddColumn <ContentVersionDto>(PreTables.ContentVersion, "userId", out var sqls);
                Database.Execute($@"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} SET userId=0");
                foreach (var sql in sqls)
                {
                    Database.Execute(sql);
                }
            }

            // rename contentVersion contentId column
            if (ColumnExists(PreTables.ContentVersion, "ContentId"))
            {
                ReplaceColumn <ContentVersionDto>(PreTables.ContentVersion, "ContentId", "nodeId");
            }

            // populate contentVersion text, current and userId columns for documents
            Database.Execute($@"UPDATE {PreTables.ContentVersion} SET text=d.text, {SqlSyntax.GetQuotedColumnName("current")}=(d.newest & ~d.published), userId=d.documentUser
FROM {PreTables.ContentVersion} v INNER JOIN {PreTables.Document} d ON d.versionId = v.versionId");


            // populate contentVersion text and current columns for non-documents, userId is default
            Database.Execute($@"UPDATE {PreTables.ContentVersion} SET text=n.text, {SqlSyntax.GetQuotedColumnName("current")}=1, userId=0
FROM {PreTables.ContentVersion} cver
JOIN {SqlSyntax.GetQuotedTableName(Cms.Core.Constants.DatabaseSchema.Tables.Node)} n ON cver.nodeId=n.id
WHERE cver.versionId NOT IN (SELECT versionId FROM {SqlSyntax.GetQuotedTableName(PreTables.Document)})");


            // create table
            Create.Table <DocumentVersionDto>(withoutKeysAndIndexes: true).Do();

            // every document row becomes a document version
            Database.Execute($@"INSERT INTO {SqlSyntax.GetQuotedTableName(Cms.Core.Constants.DatabaseSchema.Tables.DocumentVersion)} (id, templateId, published)
SELECT cver.id, doc.templateId, doc.published
FROM {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cver
JOIN {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc ON doc.nodeId=cver.nodeId AND doc.versionId=cver.versionId");


            // need to add extra rows for where published=newest
            // 'cos INSERT above has inserted the 'published' document version
            // and v8 always has a 'edited' document version too
            Database.Execute($@"
INSERT INTO {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} (nodeId, versionId, versionDate, userId, {SqlSyntax.GetQuotedColumnName("current")}, text)
SELECT doc.nodeId, NEWID(), doc.updateDate, doc.documentUser, 1, doc.text
FROM {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc
JOIN {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cver ON doc.nodeId=cver.nodeId AND doc.versionId=cver.versionId
WHERE doc.newest=1 AND doc.published=1");

            Database.Execute($@"
INSERT INTO {SqlSyntax.GetQuotedTableName(Cms.Core.Constants.DatabaseSchema.Tables.DocumentVersion)} (id, templateId, published)
SELECT cverNew.id, doc.templateId, 0
FROM {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc
JOIN {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cverNew ON doc.nodeId = cverNew.nodeId
WHERE doc.newest=1 AND doc.published=1 AND cverNew.{SqlSyntax.GetQuotedColumnName("current")} = 1");

            Database.Execute($@"
INSERT INTO {SqlSyntax.GetQuotedTableName(PropertyDataDto.TableName)} (propertytypeid,languageId,segment,textValue,varcharValue,decimalValue,intValue,dateValue,versionId)
SELECT propertytypeid,languageId,segment,textValue,varcharValue,decimalValue,intValue,dateValue,cverNew.id
FROM {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc
JOIN {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cver ON doc.nodeId=cver.nodeId AND doc.versionId=cver.versionId
JOIN {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cverNew ON doc.nodeId = cverNew.nodeId
JOIN {SqlSyntax.GetQuotedTableName(PropertyDataDto.TableName)} pd ON pd.versionId=cver.id
WHERE doc.newest=1 AND doc.published=1 AND cverNew.{SqlSyntax.GetQuotedColumnName("current")} = 1");


            // reduce document to 1 row per content
            Database.Execute($@"DELETE FROM {PreTables.Document}
WHERE versionId NOT IN (SELECT (versionId) FROM {PreTables.ContentVersion} WHERE {SqlSyntax.GetQuotedColumnName("current")} = 1) AND (published<>1 OR newest<>1)");

            // ensure that documents with a published version are marked as published
            Database.Execute($@"UPDATE {PreTables.Document} SET published=1 WHERE nodeId IN (
SELECT nodeId FROM {PreTables.ContentVersion} cv INNER JOIN {Cms.Core.Constants.DatabaseSchema.Tables.DocumentVersion} dv ON dv.id = cv.id WHERE dv.published=1)");

            // drop some document columns
            Delete.Column("text").FromTable(PreTables.Document).Do();
            Delete.Column("templateId").FromTable(PreTables.Document).Do();
            Delete.Column("documentUser").FromTable(PreTables.Document).Do();
            Delete.DefaultConstraint().OnTable(PreTables.Document).OnColumn("updateDate").Do();
            Delete.Column("updateDate").FromTable(PreTables.Document).Do();
            Delete.Column("versionId").FromTable(PreTables.Document).Do();
            Delete.DefaultConstraint().OnTable(PreTables.Document).OnColumn("newest").Do();
            Delete.Column("newest").FromTable(PreTables.Document).Do();

            // add and populate edited column
            if (!ColumnExists(PreTables.Document, "edited"))
            {
                AddColumn <DocumentDto>(PreTables.Document, "edited", out var sqls);
                Database.Execute($"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.Document)} SET edited=~published");
                foreach (var sql in sqls)
                {
                    Database.Execute(sql);
                }
            }

            // set 'edited' to true whenever a 'non-published' property data is != a published one
            // cannot compare NTEXT values in TSQL
            // cannot cast NTEXT to NVARCHAR(MAX) in SQLCE
            // ... bah ...
            var temp = Database.Fetch <dynamic>($@"SELECT n.id,
v1.intValue intValue1, v1.decimalValue decimalValue1, v1.dateValue dateValue1, v1.varcharValue varcharValue1, v1.textValue textValue1,
v2.intValue intValue2, v2.decimalValue decimalValue2, v2.dateValue dateValue2, v2.varcharValue varcharValue2, v2.textValue textValue2
FROM {Cms.Core.Constants.DatabaseSchema.Tables.Node} n
JOIN {PreTables.ContentVersion} cv1 ON n.id=cv1.nodeId AND cv1.{SqlSyntax.GetQuotedColumnName("current")}=1
JOIN {Cms.Core.Constants.DatabaseSchema.Tables.PropertyData} v1 ON cv1.id=v1.versionId
JOIN {PreTables.ContentVersion} cv2 ON n.id=cv2.nodeId
JOIN {Cms.Core.Constants.DatabaseSchema.Tables.DocumentVersion} dv ON cv2.id=dv.id AND dv.published=1
JOIN {Cms.Core.Constants.DatabaseSchema.Tables.PropertyData} v2 ON cv2.id=v2.versionId
WHERE v1.propertyTypeId=v2.propertyTypeId
AND (v1.languageId=v2.languageId OR (v1.languageId IS NULL AND v2.languageId IS NULL))
AND (v1.segment=v2.segment OR (v1.segment IS NULL AND v2.segment IS NULL))");

            var updatedIds = new HashSet <int>();

            foreach (var t in temp)
            {
                if (t.intValue1 != t.intValue2 || t.decimalValue1 != t.decimalValue2 || t.dateValue1 != t.dateValue2 || t.varcharValue1 != t.varcharValue2 || t.textValue1 != t.textValue2)
                {
                    if (updatedIds.Add((int)t.id))
                    {
                        Database.Execute($"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.Document)} SET edited=1 WHERE nodeId=@nodeId", new { nodeId = t.id });
                    }
                }
            }

            // drop more columns
            Delete.Column("versionId").FromTable(PreTables.ContentVersion).Do();

            // rename tables
            Rename.Table(PreTables.ContentVersion).To(Cms.Core.Constants.DatabaseSchema.Tables.ContentVersion).Do();
            Rename.Table(PreTables.Document).To(Cms.Core.Constants.DatabaseSchema.Tables.Document).Do();
        }
コード例 #8
0
        public override void Up()
        {
            //now that the controlId column is renamed and now a string we need to convert
            if (Context == null || Context.Database == null)
            {
                return;
            }

            //var cpt = SqlSyntaxContext.SqlSyntaxProvider.GetConstraintsPerTable(Context.Database);
            //var di = SqlSyntaxContext.SqlSyntaxProvider.GetDefinedIndexes(Context.Database);

            if (Context.CurrentDatabaseProvider != DatabaseProviders.SqlServer)
            {
                Delete.DefaultConstraint().OnTable("cmsMacroProperty").OnColumn("macroPropertyHidden");
            }
            else
            {
                //If we are on SQLServer, we need to delete default constraints by name, older versions of umbraco did not name these default constraints
                // consistently so we need to look up the constraint name to delete, this only pertains to SQL Server and this issue:
                // http://issues.umbraco.org/issue/U4-4133
                var sqlServerSyntaxProvider = new SqlServerSyntaxProvider();
                var defaultConstraints      = sqlServerSyntaxProvider.GetDefaultConstraintsPerColumn(Context.Database).Distinct();

                //lookup the constraint we want to delete, normally would be called "DF_cmsMacroProperty_macroPropertyHidden" but
                // we cannot be sure with really old versions
                var constraint = defaultConstraints
                                 .SingleOrDefault(x => x.Item1 == "cmsMacroProperty" && x.Item2 == "macroPropertyHidden");
                if (constraint != null)
                {
                    Execute.Sql(string.Format("ALTER TABLE [{0}] DROP CONSTRAINT [{1}]", "cmsMacroProperty", constraint.Item3));
                }
            }

            Delete.Column("macroPropertyHidden").FromTable("cmsMacroProperty");

            if (Context.CurrentDatabaseProvider == DatabaseProviders.MySql)
            {
                Delete.ForeignKey().FromTable("cmsMacroProperty").ForeignColumn("macroPropertyType").ToTable("cmsMacroPropertyType").PrimaryColumn("id");
            }
            else
            {
                //Before we try to delete this constraint, we'll see if it exists first, some older schemas never had it and some older schema's had this named
                // differently than the default.

                var keyConstraints = SqlSyntax.GetConstraintsPerColumn(Context.Database).Distinct();
                var constraint     = keyConstraints
                                     .SingleOrDefault(x => x.Item1 == "cmsMacroProperty" && x.Item2 == "macroPropertyType" && x.Item3.InvariantStartsWith("PK_") == false);
                if (constraint != null)
                {
                    Delete.ForeignKey(constraint.Item3).OnTable("cmsMacroProperty");
                }
            }

            Alter.Table("cmsMacroProperty").AddColumn("editorAlias").AsString(255).NotNullable().WithDefaultValue("");

            //we need to get the data and create the migration scripts before we change the actual schema bits below!
            var list = Context.Database.Fetch <dynamic>("SELECT * FROM cmsMacroPropertyType");

            foreach (var item in list)
            {
                var alias = item.macroPropertyTypeAlias;
                //check if there's a map created
                var newAlias = (string)LegacyParameterEditorAliasConverter.GetNewAliasFromLegacyAlias(alias);
                if (newAlias.IsNullOrWhiteSpace() == false)
                {
                    alias = newAlias;
                }

                //update the table with the alias, the current macroPropertyType will contain the original id
                Update.Table("cmsMacroProperty").Set(new { editorAlias = alias }).Where(new { macroPropertyType = item.id });
            }

            //drop the column now
            Delete.Column("macroPropertyType").FromTable("cmsMacroProperty");

            //drop the default constraint
            Delete.DefaultConstraint().OnTable("cmsMacroProperty").OnColumn("editorAlias");
        }
コード例 #9
0
 public override void Up()
 {
     Delete.Column("controlId").FromTable("cmsDataType");
     //drop the default contstraint on the new column too
     Delete.DefaultConstraint().OnTable("cmsDataType").OnColumn("propertyEditorAlias");
 }
コード例 #10
0
ファイル: Migrations.cs プロジェクト: rijuntun/vocadb
 public override void Down()
 {
     Delete.DefaultConstraint().OnTable(TableNames.Songs).OnColumn("Notes");
     Alter.Table(TableNames.Songs).AlterColumn("Notes").AsString(800).NotNullable().WithDefaultValue("");
 }
コード例 #11
0
 public override void Down()
 {
     Delete.DefaultConstraint().OnTable("Students").OnColumn("BranchId");
 }
コード例 #12
0
 public override void Up()
 {
     Delete.DefaultConstraint().OnTable("LicenseKeys").InSchema("licensing").OnColumn("IsTr]ial");
 }
コード例 #13
0
 public override void Down()
 {
     Delete.DefaultConstraint().OnTable("StudentLessons").OnColumn("StudentId");
     Delete.DefaultConstraint().OnTable("StudentLessons").OnColumn("LessonId");
 }
コード例 #14
0
        private void MigrateVersions()
        {
            // if the table has already been renamed, we're done
            if (TableExists(Constants.DatabaseSchema.Tables.ContentVersion))
            {
                return;
            }

            // if the table already exists, we're done
            if (TableExists(Constants.DatabaseSchema.Tables.DocumentVersion))
            {
                return;
            }

            // if the table has already been renamed, we're done
            if (TableExists(Constants.DatabaseSchema.Tables.Document))
            {
                return;
            }

            // do it all at once

            // add contentVersion columns
            if (!ColumnExists(PreTables.ContentVersion, "text"))
            {
                AddColumn <ContentVersionDto>(PreTables.ContentVersion, "text");
            }
            if (!ColumnExists(PreTables.ContentVersion, "current"))
            {
                AddColumn <ContentVersionDto>(PreTables.ContentVersion, "current", out var sqls);
                Database.Execute($@"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} SET {SqlSyntax.GetQuotedColumnName("current")}=0");
                foreach (var sql in sqls)
                {
                    Database.Execute(sql);
                }
            }
            if (!ColumnExists(PreTables.ContentVersion, "userId"))
            {
                AddColumn <ContentVersionDto>(PreTables.ContentVersion, "userId", out var sqls);
                Database.Execute($@"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} SET userId=0");
                foreach (var sql in sqls)
                {
                    Database.Execute(sql);
                }
            }

            // rename contentVersion contentId column
            if (ColumnExists(PreTables.ContentVersion, "ContentId"))
            {
                ReplaceColumn <ContentVersionDto>(PreTables.ContentVersion, "ContentId", "nodeId");
            }

            // populate contentVersion text, current and userId columns for documents
            // SQLCE does not support UPDATE...FROM
            var temp1 = Database.Fetch <dynamic>($"SELECT versionId, text, newest, documentUser FROM {PreTables.Document}");

            foreach (var t in temp1)
            {
                Database.Execute($@"UPDATE {PreTables.ContentVersion} SET text=@text, {SqlSyntax.GetQuotedColumnName("current")}=@current, userId=@userId WHERE versionId=@versionId",
                                 new { text = t.text, current = t.newest, userId = t.documentUser, versionId = t.versionId });
            }

            // populate contentVersion text and current columns for non-documents, userId is default
            // SQLCE does not support UPDATE...FROM
            var temp2 = Database.Fetch <dynamic>($@"SELECT cver.versionId, n.text
FROM {PreTables.ContentVersion} cver
JOIN {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.Node)} n ON cver.nodeId=n.id
WHERE cver.versionId NOT IN (SELECT versionId FROM {SqlSyntax.GetQuotedTableName(PreTables.Document)})");

            foreach (var t in temp2)
            {
                Database.Execute($@"UPDATE {PreTables.ContentVersion} SET text=@text, {SqlSyntax.GetQuotedColumnName("current")}=1, userId=0 WHERE versionId=@versionId",
                                 new { text = t.text, versionId = t.versionId });
            }

            // create table
            Create.Table <DocumentVersionDto>(withoutKeysAndIndexes: true).Do();

            // every document row becomes a document version
            Database.Execute($@"INSERT INTO {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.DocumentVersion)} (id, templateId, published)
SELECT cver.id, doc.templateId, doc.published
FROM {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cver
JOIN {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc ON doc.nodeId=cver.nodeId AND doc.versionId=cver.versionId");

            // need to add extra rows for where published=newest
            // 'cos INSERT above has inserted the 'published' document version
            // and v8 always has a 'edited' document version too
            var temp3       = Database.Fetch <dynamic>($@"SELECT doc.nodeId, doc.updateDate, doc.documentUser, doc.text, doc.templateId, cver.id versionId
FROM {SqlSyntax.GetQuotedTableName(PreTables.Document)} doc
JOIN {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} cver ON doc.nodeId=cver.nodeId AND doc.versionId=cver.versionId
WHERE doc.newest=1 AND doc.published=1");
            var getIdentity = "@@@@IDENTITY";

            foreach (var t in temp3)
            {
                Database.Execute($@"INSERT INTO {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} (nodeId, versionId, versionDate, userId, {SqlSyntax.GetQuotedColumnName("current")}, text)
VALUES (@nodeId, @versionId, @versionDate, @userId, 1, @text)", new { nodeId = t.nodeId, versionId = Guid.NewGuid(), versionDate = t.updateDate, userId = t.documentUser, text = t.text });
                var id = Database.ExecuteScalar <int>("SELECT " + getIdentity);
                Database.Execute($"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.ContentVersion)} SET {SqlSyntax.GetQuotedColumnName("current")}=0 WHERE nodeId=@0 AND id<>@1", (int)t.nodeId, id);
                Database.Execute($@"INSERT INTO {SqlSyntax.GetQuotedTableName(Constants.DatabaseSchema.Tables.DocumentVersion)} (id, templateId, published)
VALUES (@id, @templateId, 0)", new { id = id, templateId = t.templateId });

                var versionId = (int)t.versionId;
                var pdatas    = Database.Fetch <PropertyDataDto>(Sql().Select <PropertyDataDto>().From <PropertyDataDto>().Where <PropertyDataDto>(x => x.VersionId == versionId));
                foreach (var pdata in pdatas)
                {
                    pdata.VersionId = id;
                    Database.Insert(pdata);
                }
            }

            // reduce document to 1 row per content
            Database.Execute($@"DELETE FROM {PreTables.Document}
WHERE versionId NOT IN (SELECT (versionId) FROM {PreTables.ContentVersion} WHERE {SqlSyntax.GetQuotedColumnName("current")} = 1) AND (published<>1 OR newest<>1)");

            // drop some document columns
            Delete.Column("text").FromTable(PreTables.Document).Do();
            Delete.Column("templateId").FromTable(PreTables.Document).Do();
            Delete.Column("documentUser").FromTable(PreTables.Document).Do();
            Delete.DefaultConstraint().OnTable(PreTables.Document).OnColumn("updateDate").Do();
            Delete.Column("updateDate").FromTable(PreTables.Document).Do();
            Delete.Column("versionId").FromTable(PreTables.Document).Do();
            Delete.DefaultConstraint().OnTable(PreTables.Document).OnColumn("newest").Do();
            Delete.Column("newest").FromTable(PreTables.Document).Do();

            // add and populate edited column
            if (!ColumnExists(PreTables.Document, "edited"))
            {
                AddColumn <DocumentDto>(PreTables.Document, "edited", out var sqls);
                Database.Execute($"UPDATE {SqlSyntax.GetQuotedTableName(PreTables.Document)} SET edited=0");
                foreach (var sql in sqls)
                {
                    Database.Execute(sql);
                }
            }

            // set 'edited' to true whenever a 'non-published' property data is != a published one
            // cannot compare NTEXT values in TSQL
            // cannot cast NTEXT to NVARCHAR(MAX) in SQLCE
            // ... bah ...
            var temp = Database.Fetch <dynamic>($@"SELECT n.id,
v1.intValue intValue1, v1.decimalValue decimalValue1, v1.dateValue dateValue1, v1.varcharValue varcharValue1, v1.textValue textValue1,
v2.intValue intValue2, v2.decimalValue decimalValue2, v2.dateValue dateValue2, v2.varcharValue varcharValue2, v2.textValue textValue2
FROM {Constants.DatabaseSchema.Tables.Node} n
JOIN {PreTables.ContentVersion} cv1 ON n.id=cv1.nodeId AND cv1.{SqlSyntax.GetQuotedColumnName("current")}=1
JOIN {Constants.DatabaseSchema.Tables.PropertyData} v1 ON cv1.id=v1.versionId
JOIN {PreTables.ContentVersion} cv2 ON n.id=cv2.nodeId
JOIN {Constants.DatabaseSchema.Tables.DocumentVersion} dv ON cv2.id=dv.id AND dv.published=1
JOIN {Constants.DatabaseSchema.Tables.PropertyData} v2 ON cv2.id=v2.versionId
WHERE v1.propertyTypeId=v2.propertyTypeId AND v1.languageId=v2.languageId AND v1.segment=v2.segment");

            foreach (var t in temp)
            {
                if (t.intValue1 != t.intValue2 || t.decimalValue1 != t.decimalValue2 || t.dateValue1 != t.dateValue2 || t.varcharValue1 != t.varcharValue2 || t.textValue1 != t.textValue2)
                {
                    Database.Execute("UPDATE {SqlSyntax.GetQuotedTableName(PreTables.Document)} SET edited=1 WHERE nodeId=@nodeIdd", new { t.id });
                }
            }

            // drop more columns
            Delete.Column("versionId").FromTable(PreTables.ContentVersion).Do();

            // rename tables
            Rename.Table(PreTables.ContentVersion).To(Constants.DatabaseSchema.Tables.ContentVersion).Do();
            Rename.Table(PreTables.Document).To(Constants.DatabaseSchema.Tables.Document).Do();
        }