private IReadOnlyList <MigrationCommand> CreateCreateOperations()
        {
            var builder = new SqlConnectionStringBuilder(_connection.DbConnection.ConnectionString);

            return(_migrationsSqlGenerator.Generate(new[] { new SqlServerCreateDatabaseOperation {
                                                                Name = builder.InitialCatalog, FileName = builder.AttachDBFilename
                                                            } }));
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected virtual IReadOnlyList <MigrationCommand> GenerateUpSql(Migration migration)
        {
            var insertCommand = _rawSqlCommandBuilder.Build(
                _historyRepository.GetInsertScript(new HistoryRow(migration.GetId(), ProductInfo.GetVersion())));

            return(_migrationsSqlGenerator
                   .Generate(migration.UpOperations, migration.TargetModel)
                   .Concat(new[] { new MigrationCommand(insertCommand, _currentContext.Context, _commandLogger) })
                   .ToList());
        }
        private IReadOnlyList <MigrationCommand> GetCreateOps()
        {
            var ops = new MigrationOperation[]
            {
                new MySQLCreateDatabaseOperation {
                    Name = _connection.DbConnection.Database
                }
            };

            return(_sqlGenerator.Generate(ops));
        }
예제 #4
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected virtual IReadOnlyList <MigrationCommand> GenerateUpSql([NotNull] Migration migration)
        {
            Check.NotNull(migration, nameof(migration));

            var insertCommand = _rawSqlCommandBuilder.Build(
                _historyRepository.GetInsertScript(new HistoryRow(migration.GetId(), ProductInfo.GetVersion())));

            return(_migrationsSqlGenerator
                   .Generate(migration.UpOperations, migration.TargetModel)
                   .Concat(new[] { new MigrationCommand(insertCommand) })
                   .ToList());
        }
예제 #5
0
        protected virtual IReadOnlyList <IRelationalCommand> GenerateUpSql([NotNull] Migration migration)
        {
            Check.NotNull(migration, nameof(migration));

            var commands = new List <IRelationalCommand>();

            commands.AddRange(_migrationsSqlGenerator.Generate(migration.UpOperations, migration.TargetModel));
            commands.Add(
                _rawSqlCommandBuilder.Build(_historyRepository.GetInsertScript(new HistoryRow(migration.GetId(), ProductInfo.GetVersion()))));

            return(commands);
        }
예제 #6
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        protected virtual IReadOnlyList <MigrationCommand> GenerateUpSql([NotNull] Migration migration,
                                                                         MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default)
        {
            Check.NotNull(migration, nameof(migration));

            var insertCommand = _rawSqlCommandBuilder.Build(
                _historyRepository.GetInsertScript(new HistoryRow(migration.GetId(), ProductInfo.GetVersion())));

            return(_migrationsSqlGenerator
                   .Generate(migration.UpOperations, FinalizeModel(migration.TargetModel), options)
                   .Concat(new[] { new MigrationCommand(insertCommand, _currentContext.Context, _commandLogger) })
                   .ToList());
        }
예제 #7
0
        protected virtual IReadOnlyList <SqlBatch> GenerateUpSql([NotNull] Migration migration)
        {
            Check.NotNull(migration, nameof(migration));

            var operations = new List <MigrationOperation>(migration.UpOperations);

            // TODO: Append to batch instead
            operations.Add(
                new SqlOperation
            {
                Sql = _historyRepository.GetInsertScript(new HistoryRow(migration.Id, ProductInfo.GetVersion()))
            });

            return(_sqlGenerator.Generate(operations, migration.TargetModel));
        }
        public static void DropTables(this DbContext dbContext,
                                      IMigrationsModelDiffer modelDiffer,
                                      IMigrationsSqlGenerator sqlGenerator,
                                      bool failSilently = false)
        {
            var downOperations    = modelDiffer.GetDifferences(dbContext.Model, null);
            var sqlDownOperations = sqlGenerator.Generate(downOperations);

            using (var t = dbContext.Database.BeginTransaction())
            {
                foreach (var operation in sqlDownOperations)
                {
                    try
                    {
                        operation.ExecuteNonQuery(t.Connection);
                    }
                    catch (Exception e)
                    {
                        if (!failSilently)
                        {
                            throw e;
                        }
                    }
                }
                t.Commit();
            }
        }
예제 #9
0
        public virtual string GetCreateScript()
        {
            var operations = _modelDiffer.GetDifferences(null, _model.Value);
            var commands   = _migrationsSqlGenerator.Generate(operations, _model.Value);

            return(string.Concat(commands.Select(c => c.CommandText)));
        }
예제 #10
0
        public override void CreateTables()
        {
            var operations = _modelDiffer.GetDifferences(null, Model);
            var statements = _migrationsSqlGenerator.Generate(operations, Model);

            _executor.ExecuteNonQuery(_connection, null, statements);
        }
예제 #11
0
        public virtual string GetCreateScript()
        {
            var operations = _modelDiffer.GetDifferences(null, _model.Value);
            var batches    = _migrationsSqlGenerator.Generate(operations, _model.Value);

            if (batches.Count != 1 || batches[0].SuppressTransaction)
            {
                throw new InvalidOperationException(Strings.InvalidCreateScript);
            }

            return(batches[0].Sql);
        }
예제 #12
0
        public virtual string GetCreateScript()
        {
            var operations = _modelDiffer.GetDifferences(null, _model.Value);
            var commands   = _migrationsSqlGenerator.Generate(operations, _model.Value);

            if (commands.Count != 1)
            {
                throw new InvalidOperationException(RelationalStrings.InvalidCreateScript);
            }

            return(commands[0].CommandText);
        }
        public static void CreateTablesIfNotExists(this DbContext dbContext,
                                                   IMigrationsModelDiffer modelDiffer,
                                                   IMigrationsSqlGenerator sqlGenerator,
                                                   IEntityFrameworkDataProvider dataProvider)
        {
            var upOperations = modelDiffer.GetDifferences(null, dbContext.Model);

            var tables = upOperations.Where(o => o is CreateTableOperation).Cast <CreateTableOperation>().Select(o => o.Name);

            if (!dataProvider.TablesExist(dbContext.Database, tables))// alguna tabla fue eliminada
            {
                dbContext.DropTables(modelDiffer, sqlGenerator, true);

                //Crear nuevamente las tablas
                var sqlOperations = sqlGenerator.Generate(upOperations);

                using (var t = dbContext.Database.BeginTransaction())
                {
                    sqlOperations.ExecuteNonQuery(t.Connection);
                    t.Commit();
                }
            }
        }
 IEnumerable <IRelationalCommand> CreateCreateOperations()
 => _migrationsSqlGenerator.Generate(new[] { new NpgsqlCreateDatabaseOperation {
                                                 Name = _connection.DbConnection.Database, Template = Model.Npgsql().DatabaseTemplate
                                             } });
 private IReadOnlyList <MigrationCommand> CreateCreateOperations()
 => _migrationsSqlGenerator.Generate(new[] { new SqlServerCreateDatabaseOperation {
                                                 Name = _connection.DbConnection.Database
                                             } });
예제 #16
0
 public IReadOnlyList <MigrationCommand> CreateCreateOperations(MyCatDatabaseHost node)
 => _migrationsSqlGenerator.Generate(new[] { new MyCatCreateDatabaseOperation {
                                                 Name = node.Database
                                             } });
 IReadOnlyList <MigrationCommand> CreateCreateOperations()
 => _migrationsSqlGenerator.Generate(new[] { new NpgsqlCreateDatabaseOperation {
                                                 Name = _connection.DbConnection.Database, Template = Model.Npgsql().DatabaseTemplate
                                             } });
예제 #18
0
 /// <summary>
 ///     Gets the commands that will create all tables from the model.
 /// </summary>
 /// <returns> The generated commands. </returns>
 protected virtual IReadOnlyList <MigrationCommand> GetCreateTablesCommands()
 => _migrationsSqlGenerator.Generate(_modelDiffer.GetDifferences(null, Model), Model);
예제 #19
0
 private IEnumerable <RelationalCommand> CreateCreateOperations()
 => _migrationsSqlGenerator.Generate(new[] { new SqlServerCreateDatabaseOperation {
                                                 Name = _connection.DbConnection.Database
                                             } });
 protected virtual IEnumerable <IRelationalCommand> GetCreateTablesCommands()
 => _migrationsSqlGenerator.Generate(_modelDiffer.GetDifferences(null, Model), Model);
예제 #21
0
 private IEnumerable <SqlBatch> CreateSchemaCommands()
 => _sqlGenerator.Generate(_modelDiffer.GetDifferences(null, Model), Model);