Exemple #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
            });
        }
Exemple #3
0
        public override void CreateTables(IModel model)
        {
            Check.NotNull(model, "model");

            var generator  = _generatorFactory.Create();
            var operations = _modelDiffer.CreateSchema(model);
            var statements = generator.Generate(operations);

            // TODO: Delete database on error
            using (var connection = _connection.CreateConnectionReadWrite())
            {
                _executor.ExecuteNonQuery(connection, null, statements);
            }
        }
Exemple #4
0
        public override void CreateTables(IModel model)
        {
            Check.NotNull(model, "model");

            // TODO: SQLiteMigrationOperationSqlGenerator should get this from DI
            _generator.Database = _modelDiffer.DatabaseBuilder.GetDatabase(model);
            var operations = _modelDiffer.CreateSchema(model);
            var statements = _generator.Generate(operations);

            // TODO: Delete database on error
            using (var connection = _connection.CreateConnectionReadWrite())
            {
                _executor.ExecuteNonQuery(connection, null, statements);
            }
        }
Exemple #5
0
 private IEnumerable <SqlStatement> CreateSchemaCommands(IModel model)
 {
     _sqlGenerator.Database = _modelDiffer.DatabaseBuilder.GetDatabase(model);
     return(_sqlGenerator.Generate(_modelDiffer.CreateSchema(model)));
 }
Exemple #6
0
        private IEnumerable <SqlStatement> CreateSchemaCommands(IModel model)
        {
            var sqlGenerator = _sqlGeneratorFactory.Create();

            return(sqlGenerator.Generate(_modelDiffer.CreateSchema(model)));
        }