예제 #1
0
        protected virtual MigrationInfo CreateMigration([NotNull] string migrationName)
        {
            Check.NotEmpty(migrationName, "migrationName");

            var sourceModel = MigrationAssembly.ModelSnapshot?.Model;
            var targetModel = _model;

            IReadOnlyList <MigrationOperation> upgradeOperations, downgradeOperations;

            if (sourceModel != null)
            {
                upgradeOperations   = ModelDiffer.Diff(sourceModel, targetModel);
                downgradeOperations = ModelDiffer.Diff(targetModel, sourceModel);
            }
            else
            {
                upgradeOperations   = ModelDiffer.CreateSchema(targetModel);
                downgradeOperations = ModelDiffer.DropSchema(targetModel);
            }

            return
                (new MigrationInfo(CreateMigrationId(migrationName))
            {
                TargetModel = targetModel,
                UpgradeOperations = upgradeOperations,
                DowngradeOperations = downgradeOperations
            });
        }
        protected virtual IMigrationMetadata CreateMigration([NotNull] string migrationName)
        {
            Check.NotEmpty(migrationName, "migrationName");

            var sourceModel = MigrationAssembly.Model;
            var targetModel = ContextConfiguration.Model;

            IReadOnlyList <MigrationOperation> upgradeOperations, downgradeOperations;

            if (sourceModel != null)
            {
                upgradeOperations   = ModelDiffer.Diff(sourceModel, targetModel);
                downgradeOperations = ModelDiffer.Diff(targetModel, sourceModel);
            }
            else
            {
                upgradeOperations   = ModelDiffer.CreateSchema(targetModel);
                downgradeOperations = ModelDiffer.DropSchema(targetModel);
            }

            return
                (new MigrationMetadata(CreateMigrationId(migrationName), ContextConfiguration.Context.GetType())
            {
                TargetModel = targetModel,
                UpgradeOperations = upgradeOperations,
                DowngradeOperations = downgradeOperations
            });
        }