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.DiffSource(targetModel);
                downgradeOperations = ModelDiffer.DiffTarget(targetModel);
            }

            return
                (new MigrationMetadata(migrationName, CreateMigrationTimestamp())
            {
                TargetModel = targetModel,
                UpgradeOperations = upgradeOperations,
                DowngradeOperations = downgradeOperations
            });
        }
        public override void CreateTables(IModel model)
        {
            Check.NotNull(model, "model");

            var operations = _modelDiffer.DiffSource(model);
            var statements = _generator.Generate(operations, generateIdempotentSql: false);

            // TODO: Delete database on error
            using (var connection = _connection.CreateConnectionReadWrite())
            {
                _executor.ExecuteNonQuery(connection, statements);
            }
        }
Exemple #3
0
 private IEnumerable <SqlStatement> CreateSchemaCommands(IModel model)
 {
     return(_sqlGenerator.Generate(_modelDiffer.DiffSource(model), generateIdempotentSql: false));
 }