Beispiel #1
0
        private IEnumerable <MigrationOperation> DiffAnnotations(
            IModel source,
            IModel target)
        {
            var sourceMigrationsAnnotations = source == null ? null : MigrationsAnnotations.For(source).ToList();
            var targetMigrationsAnnotations = target == null ? null : MigrationsAnnotations.For(target).ToList();

            if (source == null)
            {
                if (targetMigrationsAnnotations?.Count > 0)
                {
                    var alterDatabaseOperation = new AlterDatabaseOperation();
                    alterDatabaseOperation.AddAnnotations(targetMigrationsAnnotations);
                    yield return(alterDatabaseOperation);
                }

                yield break;
            }

            if (target == null)
            {
                sourceMigrationsAnnotations = MigrationsAnnotations.ForRemove(source).ToList();
                if (sourceMigrationsAnnotations.Count > 0)
                {
                    var alterDatabaseOperation = new AlterDatabaseOperation();
                    alterDatabaseOperation.OldDatabase.AddAnnotations(MigrationsAnnotations.ForRemove(source));
                    yield return(alterDatabaseOperation);
                }

                yield break;
            }

            if (HasDifferences(sourceMigrationsAnnotations, targetMigrationsAnnotations))
            {
                var alterDatabaseOperation = new AlterDatabaseOperation();
                alterDatabaseOperation.AddAnnotations(targetMigrationsAnnotations);
                alterDatabaseOperation.OldDatabase.AddAnnotations(sourceMigrationsAnnotations);
                yield return(alterDatabaseOperation);
            }
        }
        protected override IEnumerable <MigrationOperation> Remove(TableMapping source, DiffContext diffContext)
        {
            var type = source.GetRootType();
            MigrationOperation operation;

            if (!type.IsUserDefinedType())
            {
                var dropOperation = new DropTableOperation {
                    Schema = source.Schema, Name = source.Name
                };
                diffContext.AddDrop(source, dropOperation);
                operation = dropOperation;
            }
            else
            {
                operation = new DropUserDefinedTypeOperation {
                    Schema = source.Schema, Name = source.Name
                };
            }

            operation.AddAnnotations(MigrationsAnnotations.ForRemove(source.EntityTypes[0]));
            yield return(operation);
        }
        protected override IEnumerable <MigrationOperation> Add(IColumn target, DiffContext diffContext, bool inline = false)
        {
            var _property = target.PropertyMappings.ToArray().FirstOrDefault().Property;

            if (_property.FindTypeMapping() is RelationalTypeMapping storeType)
            {
                var valueGenerationStrategy = MySQLValueGenerationStrategyCompatibility.GetValueGenerationStrategy(MigrationsAnnotations.ForRemove(target).ToArray());
                // Ensure that null will be set for the columns default value, if CURRENT_TIMESTAMP has been required,
                // or when the store type of the column does not support default values at all.
                inline = inline ||
                         (storeType.StoreTypeNameBase == "datetime" ||
                          storeType.StoreTypeNameBase == "timestamp") &&
                         (valueGenerationStrategy == MySQLValueGenerationStrategy.IdentityColumn ||
                          valueGenerationStrategy == MySQLValueGenerationStrategy.ComputedColumn) ||
                         storeType.StoreTypeNameBase.Contains("text") ||
                         storeType.StoreTypeNameBase.Contains("blob") ||
                         storeType.StoreTypeNameBase == "geometry" ||
                         storeType.StoreTypeNameBase == "json";
            }
            return(base.Add(target, diffContext, inline));
        }