コード例 #1
0
ファイル: TableDiff.cs プロジェクト: nieve/marten
        public void CreatePatch(DocumentMapping mapping, Action<string> executeSql)
        {
            var fields = Missing.Select(x => mapping.FieldForColumn(x.Name)).ToArray();
            if (fields.Length != Missing.Length)
            {
                throw new InvalidOperationException("The expected columns did not match with the DocumentMapping");
            }

            fields.Each(x => x.WritePatch(mapping, executeSql));
        }
コード例 #2
0
ファイル: TableDiff.cs プロジェクト: danielmarbach/marten
        public void CreatePatch(DocumentMapping mapping, SchemaPatch runner)
        {
            var systemFields = new string[]
            {
                DocumentMapping.LastModifiedColumn,
                DocumentMapping.DotNetTypeColumn,
                DocumentMapping.VersionColumn,
                DocumentMapping.DeletedColumn,
                DocumentMapping.DeletedAtColumn,
                DocumentMapping.DocumentTypeColumn
            };

            var missingNonSystemFields = Missing.Where(x => !systemFields.Contains(x.Name)).ToArray();
            var fields = missingNonSystemFields.Select(x => mapping.FieldForColumn(x.Name)).ToArray();
            if (fields.Length != missingNonSystemFields.Length)
            {
                throw new InvalidOperationException("The expected columns did not match with the DocumentMapping");
            }


            var missingSystemColumns = Missing.Where(x => systemFields.Contains(x.Name)).ToArray();
            if (missingSystemColumns.Any())
            {
                missingSystemColumns.Each(col =>
                {
                    var patch =
                        $"alter table {_tableName.QualifiedName} add column {col.ToDeclaration(col.Name.Length + 1)};";

                    runner.Updates.Apply(this, patch);
                    runner.Rollbacks.RemoveColumn(this, mapping.Table, col.Name);
                });
            }


            fields.Each(x =>
            {
                x.WritePatch(mapping, runner);
                runner.Rollbacks.RemoveColumn(this, mapping.Table, x.ColumnName);
            });
        }