Пример #1
0
        public Migrator(
            [NotNull] IMigrationsAssembly migrationsAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper,
            [NotNull] ILogger <Migrator> logger,
            [NotNull] IDatabaseProviderServices providerServices)
        {
            Check.NotNull(migrationsAssembly, nameof(migrationsAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(providerServices, nameof(providerServices));

            _migrationsAssembly     = migrationsAssembly;
            _historyRepository      = historyRepository;
            _databaseCreator        = (IRelationalDatabaseCreator)databaseCreator;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _rawSqlCommandBuilder   = rawSqlCommandBuilder;
            _connection             = connection;
            _sqlGenerationHelper    = sqlGenerationHelper;
            _logger         = logger;
            _activeProvider = providerServices.InvariantName;
        }
Пример #2
0
        public RelationalDatabaseCreatorDependencies(
            [NotNull] IModel model,
            [NotNull] IRelationalConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IMigrationCommandExecutor migrationCommandExecutor,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper,
            [NotNull] IExecutionStrategyFactory executionStrategyFactory,
            [NotNull] IDiagnosticsLogger <DbLoggerCategory.Database.Command> commandLogger)
        {
            Check.NotNull(model, nameof(model));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(migrationCommandExecutor, nameof(migrationCommandExecutor));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));
            Check.NotNull(executionStrategyFactory, nameof(executionStrategyFactory));
            Check.NotNull(commandLogger, nameof(commandLogger));

            Model                    = model;
            Connection               = connection;
            ModelDiffer              = modelDiffer;
            MigrationsSqlGenerator   = migrationsSqlGenerator;
            MigrationCommandExecutor = migrationCommandExecutor;
            SqlGenerationHelper      = sqlGenerationHelper;
            ExecutionStrategyFactory = executionStrategyFactory;
            CommandLogger            = commandLogger;
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginMigrator"/> class.
 /// </summary>
 /// <param name="migrationsSqlGenerator">The migrations SQL generator.</param>
 /// <param name="migrationsAssembly">The migrations assembly.</param>
 /// <param name="pluginHistoryRepository">The plugin history repository.</param>
 /// <param name="rawSqlCommandBuilder">The raw SQL command builder.</param>
 /// <param name="migrationCommandExecutor">The migration command executor.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="sqlGenerationHelper">The SQL generation helper.</param>
 /// <param name="currentContext">The current context.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="commandLogger">The command logger.</param>
 /// <param name="databaseProvider">The database provider.</param>
 public PluginMigrator(
     IMigrationsSqlGenerator migrationsSqlGenerator,
     IMigrationsAssembly migrationsAssembly,
     IPluginHistoryRepository pluginHistoryRepository,
     IRawSqlCommandBuilder rawSqlCommandBuilder,
     IMigrationCommandExecutor migrationCommandExecutor,
     IRelationalConnection connection,
     ISqlGenerationHelper sqlGenerationHelper,
     ICurrentDbContext currentContext,
     ILoggerFactory loggerFactory,
     IDiagnosticsLogger <DbLoggerCategory.Database.Command> commandLogger,
     IDatabaseProvider databaseProvider)
 {
     MigrationsSqlGenerator   = migrationsSqlGenerator;
     MigrationsAssembly       = migrationsAssembly;
     PluginHistoryRepository  = pluginHistoryRepository;
     RawSqlCommandBuilder     = rawSqlCommandBuilder;
     MigrationCommandExecutor = migrationCommandExecutor;
     Connection          = connection;
     SqlGenerationHelper = sqlGenerationHelper;
     CurrentContext      = currentContext;
     Logger           = loggerFactory.CreateLogger("BlueBoxMoon.Data.EntityFramework.Migrations.PluginMigrator");
     CommandLogger    = commandLogger;
     DatabaseProvider = databaseProvider;
 }
Пример #4
0
 public MySqlMigrator(
     [NotNull] IMigrationsAssembly migrationsAssembly,
     [NotNull] IHistoryRepository historyRepository,
     [NotNull] IDatabaseCreator databaseCreator,
     [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
     [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
     [NotNull] IMigrationCommandExecutor migrationCommandExecutor,
     [NotNull] IRelationalConnection connection,
     [NotNull] ISqlGenerationHelper sqlGenerationHelper,
     [NotNull] ICurrentDbContext currentContext,
     [NotNull] IDiagnosticsLogger <DbLoggerCategory.Migrations> logger,
     [NotNull] IDiagnosticsLogger <DbLoggerCategory.Database.Command> commandLogger,
     [NotNull] IDatabaseProvider databaseProvider)
     : base(
         migrationsAssembly,
         historyRepository,
         databaseCreator,
         migrationsSqlGenerator,
         rawSqlCommandBuilder,
         migrationCommandExecutor,
         connection,
         sqlGenerationHelper,
         currentContext,
         logger,
         commandLogger,
         databaseProvider)
 {
     _migrationsAssembly   = migrationsAssembly;
     _rawSqlCommandBuilder = rawSqlCommandBuilder;
     _currentContext       = currentContext;
     _commandLogger        = commandLogger;
 }
        /// <summary>
        ///     <para>
        ///         Creates the service dependencies parameter object for a <see cref="HistoryRepository" />.
        ///     </para>
        ///     <para>
        ///         Do not call this constructor directly from either provider or application code as it may change
        ///         as new dependencies are added. Instead, use this type in your constructor so that an instance
        ///         will be created and injected automatically by the dependency injection container. To create
        ///         an instance with some dependent services replaced, first resolve the object from the dependency
        ///         injection container, then replace selected services using the 'With...' methods. Do not call
        ///         the constructor at any point in this process.
        ///     </para>
        ///     <para>
        ///         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.
        ///     </para>
        /// </summary>
        /// <param name="databaseCreator"> The database creator. </param>
        /// <param name="rawSqlCommandBuilder"> A command builder for building raw SQL commands. </param>
        /// <param name="connection"> The connection to the database. </param>
        /// <param name="options"> Options for the current context instance. </param>
        /// <param name="modelDiffer"> The model differ. </param>
        /// <param name="migrationsSqlGenerator"> The SQL generator for Migrations operations. </param>
        /// <param name="sqlGenerationHelper"> Helpers for generating update SQL. </param>
        /// <param name="coreConventionSetBuilder"> The core convention set to use when creating the model. </param>
        /// <param name="conventionSetBuilders"> The convention sets to use when creating the model. </param>
        public HistoryRepositoryDependencies(
            [NotNull] IRelationalDatabaseCreator databaseCreator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] IDbContextOptions options,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper,
            [NotNull] ICoreConventionSetBuilder coreConventionSetBuilder,
            [NotNull] IEnumerable <IConventionSetBuilder> conventionSetBuilders)
        {
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(options, nameof(options));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));
            Check.NotNull(coreConventionSetBuilder, nameof(coreConventionSetBuilder));
            Check.NotNull(conventionSetBuilders, nameof(conventionSetBuilders));

            DatabaseCreator      = databaseCreator;
            RawSqlCommandBuilder = rawSqlCommandBuilder;
            Connection           = connection;
            Options                  = options;
            ModelDiffer              = modelDiffer;
            MigrationsSqlGenerator   = migrationsSqlGenerator;
            SqlGenerationHelper      = sqlGenerationHelper;
            CoreConventionSetBuilder = coreConventionSetBuilder;
            ConventionSetBuilder     = new CompositeConventionSetBuilder((IReadOnlyList <IConventionSetBuilder>)conventionSetBuilders);
        }
Пример #6
0
        public Migrator(
            [NotNull] IMigrationsAssembly migrationAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IMigrationsSqlGenerator sqlGenerator,
            [NotNull] ISqlStatementExecutor executor,
            [NotNull] IRelationalConnection connection,
            [NotNull] IUpdateSqlGenerator sql,
            [NotNull] ILoggerFactory loggerFactory)
        {
            Check.NotNull(migrationAssembly, nameof(migrationAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(sql, nameof(sql));
            Check.NotNull(loggerFactory, nameof(loggerFactory));

            _migrationAssembly = migrationAssembly;
            _historyRepository = historyRepository;
            _databaseCreator   = (IRelationalDatabaseCreator)databaseCreator;
            _sqlGenerator      = sqlGenerator;
            _executor          = executor;
            _connection        = connection;
            _sql    = sql;
            _logger = new LazyRef <ILogger>(loggerFactory.CreateLogger <Migrator>);
        }
        /// <summary>
        ///     <para>
        ///         Creates the service dependencies parameter object for a <see cref="HistoryRepository" />.
        ///     </para>
        ///     <para>
        ///         Do not call this constructor directly from either provider or application code as it may change
        ///         as new dependencies are added. Instead, use this type in your constructor so that an instance
        ///         will be created and injected automatically by the dependency injection container. To create
        ///         an instance with some dependent services replaced, first resolve the object from the dependency
        ///         injection container, then replace selected services using the 'With...' methods. Do not call
        ///         the constructor at any point in this process.
        ///     </para>
        ///     <para>
        ///         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.
        ///     </para>
        /// </summary>
        /// <param name="databaseCreator"> The database creator. </param>
        /// <param name="rawSqlCommandBuilder"> A command builder for building raw SQL commands. </param>
        /// <param name="connection"> The connection to the database. </param>
        /// <param name="options"> Options for the current context instance. </param>
        /// <param name="modelDiffer"> The model differ. </param>
        /// <param name="migrationsSqlGenerator"> The SQL generator for Migrations operations. </param>
        /// <param name="sqlGenerationHelper"> Helpers for generating update SQL. </param>
        /// <param name="conventionSetBuilder"> The convention set to use when creating the model. </param>
        /// <param name="typeMappingSource"> The type mapper. </param>
        /// <param name="modelLogger"> The logger for model building events. </param>
        public HistoryRepositoryDependencies(
            [NotNull] IRelationalDatabaseCreator databaseCreator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] IDbContextOptions options,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper,
            [NotNull] IConventionSetBuilder conventionSetBuilder,
            [NotNull] IRelationalTypeMappingSource typeMappingSource,
            [NotNull] IDiagnosticsLogger <DbLoggerCategory.Model> modelLogger)
        {
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(options, nameof(options));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));
            Check.NotNull(conventionSetBuilder, nameof(conventionSetBuilder));
            Check.NotNull(typeMappingSource, nameof(typeMappingSource));
            Check.NotNull(modelLogger, nameof(modelLogger));

            DatabaseCreator      = databaseCreator;
            RawSqlCommandBuilder = rawSqlCommandBuilder;
            Connection           = connection;
            Options                = options;
            ModelDiffer            = modelDiffer;
            MigrationsSqlGenerator = migrationsSqlGenerator;
            SqlGenerationHelper    = sqlGenerationHelper;
            ConventionSetBuilder   = conventionSetBuilder;
            TypeMappingSource      = typeMappingSource;
            ModelLogger            = modelLogger;
        }
Пример #8
0
        public Migrator(
            [NotNull] IMigrationsAssembly migrationAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IMigrationsSqlGenerator sqlGenerator,
            [NotNull] ISqlStatementExecutor executor,
            [NotNull] IRelationalConnection connection,
            [NotNull] IUpdateSqlGenerator sql,
            [NotNull] ILoggerFactory loggerFactory)
        {
            Check.NotNull(migrationAssembly, nameof(migrationAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(sql, nameof(sql));
            Check.NotNull(loggerFactory, nameof(loggerFactory));

            _migrationAssembly = migrationAssembly;
            _historyRepository = historyRepository;
            _databaseCreator = (IRelationalDatabaseCreator)databaseCreator;
            _sqlGenerator = sqlGenerator;
            _executor = executor;
            _connection = connection;
            _sql = sql;
            _logger = new LazyRef<ILogger>(loggerFactory.CreateLogger<Migrator>);
        }
Пример #9
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>
        public Migrator(
            [NotNull] IMigrationsAssembly migrationsAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IMigrationCommandExecutor migrationCommandExecutor,
            [NotNull] IRelationalConnection connection,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper,
            [NotNull] ILogger<Migrator> logger,
            [NotNull] IDatabaseProviderServices providerServices)
        {
            Check.NotNull(migrationsAssembly, nameof(migrationsAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(migrationCommandExecutor, nameof(migrationCommandExecutor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(providerServices, nameof(providerServices));

            _migrationsAssembly = migrationsAssembly;
            _historyRepository = historyRepository;
            _databaseCreator = (IRelationalDatabaseCreator)databaseCreator;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _rawSqlCommandBuilder = rawSqlCommandBuilder;
            _migrationCommandExecutor = migrationCommandExecutor;
            _connection = connection;
            _sqlGenerationHelper = sqlGenerationHelper;
            _logger = logger;
            _activeProvider = providerServices.InvariantName;
        }
Пример #10
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>
        public Migrator(
            [NotNull] IMigrationsAssembly migrationsAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IMigrationCommandExecutor migrationCommandExecutor,
            [NotNull] IRelationalConnection connection,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper,
            [NotNull] IInterceptingLogger <LoggerCategory.Migrations> logger,
            [NotNull] IDatabaseProvider databaseProvider)
        {
            Check.NotNull(migrationsAssembly, nameof(migrationsAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(migrationCommandExecutor, nameof(migrationCommandExecutor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(databaseProvider, nameof(databaseProvider));

            _migrationsAssembly       = migrationsAssembly;
            _historyRepository        = historyRepository;
            _databaseCreator          = (IRelationalDatabaseCreator)databaseCreator;
            _migrationsSqlGenerator   = migrationsSqlGenerator;
            _rawSqlCommandBuilder     = rawSqlCommandBuilder;
            _migrationCommandExecutor = migrationCommandExecutor;
            _connection          = connection;
            _sqlGenerationHelper = sqlGenerationHelper;
            _logger         = logger;
            _activeProvider = databaseProvider.InvariantName;
        }
Пример #11
0
        /// <summary>
        ///     <para>
        ///         Creates the service dependencies parameter object for a <see cref="HistoryRepository" />.
        ///     </para>
        ///     <para>
        ///         Do not call this constructor directly from either provider or application code as it may change
        ///         as new dependencies are added. Instead, use this type in your constructor so that an instance
        ///         will be created and injected automatically by the dependency injection container. To create
        ///         an instance with some dependent services replaced, first resolve the object from the dependency
        ///         injection container, then replace selected services using the 'With...' methods. Do not call
        ///         the constructor at any point in this process.
        ///     </para>
        ///     <para>
        ///         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.
        ///     </para>
        /// </summary>
        /// <param name="databaseCreator"> The database creator. </param>
        /// <param name="rawSqlCommandBuilder"> A command builder for building raw SQL commands. </param>
        /// <param name="connection"> The connection to the database. </param>
        /// <param name="options"> Options for the current context instance. </param>
        /// <param name="modelDiffer"> The model differ. </param>
        /// <param name="migrationsSqlGenerator"> The SQL generator for Migrations operations. </param>
        /// <param name="sqlGenerationHelper"> Helpers for generating update SQL. </param>
        public HistoryRepositoryDependencies(
            [NotNull] IRelationalDatabaseCreator databaseCreator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] IDbContextOptions options,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper)
        {
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(options, nameof(options));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));

            DatabaseCreator      = databaseCreator;
            RawSqlCommandBuilder = rawSqlCommandBuilder;
            Connection           = connection;
            Options                = options;
            ModelDiffer            = modelDiffer;
            MigrationsSqlGenerator = migrationsSqlGenerator;
            SqlGenerationHelper    = sqlGenerationHelper;
        }
Пример #12
0
 /// <summary>
 /// 初始化类<see cref="MigrationRepository"/>。
 /// </summary>
 /// <param name="context">数据库操作实例。</param>
 /// <param name="sqlHelper">SQL辅助接口。</param>
 /// <param name="sqlGenerator">SQL迁移脚本生成接口。</param>
 protected MigrationRepository(IDbContext <Migration> context, ISqlHelper sqlHelper, IMigrationsSqlGenerator sqlGenerator)
 {
     SqlHelper    = sqlHelper;
     Table        = typeof(Migration).GetTableName();
     Context      = context;
     SqlGenerator = sqlGenerator;
 }
        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();
            }
        }
Пример #14
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>
 public Migrator(
     IMigrationsAssembly migrationsAssembly,
     IHistoryRepository historyRepository,
     IDatabaseCreator databaseCreator,
     IMigrationsSqlGenerator migrationsSqlGenerator,
     IRawSqlCommandBuilder rawSqlCommandBuilder,
     IMigrationCommandExecutor migrationCommandExecutor,
     IRelationalConnection connection,
     ISqlGenerationHelper sqlGenerationHelper,
     ICurrentDbContext currentContext,
     IModelRuntimeInitializer modelRuntimeInitializer,
     IDiagnosticsLogger <DbLoggerCategory.Migrations> logger,
     IRelationalCommandDiagnosticsLogger commandLogger,
     IDatabaseProvider databaseProvider)
 {
     _migrationsAssembly       = migrationsAssembly;
     _historyRepository        = historyRepository;
     _databaseCreator          = (IRelationalDatabaseCreator)databaseCreator;
     _migrationsSqlGenerator   = migrationsSqlGenerator;
     _rawSqlCommandBuilder     = rawSqlCommandBuilder;
     _migrationCommandExecutor = migrationCommandExecutor;
     _connection              = connection;
     _sqlGenerationHelper     = sqlGenerationHelper;
     _currentContext          = currentContext;
     _modelRuntimeInitializer = modelRuntimeInitializer;
     _logger         = logger;
     _commandLogger  = commandLogger;
     _activeProvider = databaseProvider.Name;
 }
Пример #15
0
 /// <summary>
 /// 初始化类<see cref="MigrationRepository"/>。
 /// </summary>
 /// <param name="db">数据库操作实例。</param>
 /// <param name="model">模型接口。</param>
 /// <param name="sqlHelper">SQL辅助接口。</param>
 /// <param name="sqlGenerator">SQL迁移脚本生成接口。</param>
 protected MigrationRepository(IRepository <Migration> db, IModel model, ISqlHelper sqlHelper, IMigrationsSqlGenerator sqlGenerator)
 {
     Model        = model;
     SqlHelper    = sqlHelper;
     Table        = model.GetTable(typeof(Migration));
     _db          = db;
     SqlGenerator = sqlGenerator;
 }
 /// <summary>
 ///     Clones this dependency parameter object with one service replaced.
 /// </summary>
 /// <param name="migrationsSqlGenerator"> A replacement for the current dependency of this type. </param>
 /// <returns> A new parameter object with the given service replaced. </returns>
 public RelationalDatabaseCreatorDependencies With([NotNull] IMigrationsSqlGenerator migrationsSqlGenerator)
 => new RelationalDatabaseCreatorDependencies(
     Model,
     Connection,
     ModelDiffer,
     migrationsSqlGenerator,
     MigrationCommandExecutor,
     ExecutionStrategyFactory);
Пример #17
0
 /// <summary>
 ///     Clones this dependency parameter object with one service replaced.
 /// </summary>
 /// <param name="migrationsSqlGenerator"> A replacement for the current dependency of this type. </param>
 /// <returns> A new parameter object with the given service replaced. </returns>
 public HistoryRepositoryDependencies With([NotNull] IMigrationsSqlGenerator migrationsSqlGenerator)
 => new HistoryRepositoryDependencies(
     DatabaseCreator,
     RawSqlCommandBuilder,
     Connection,
     Options,
     ModelDiffer,
     migrationsSqlGenerator,
     SqlGenerationHelper);
Пример #18
0
 public SqliteDatabaseCreator(
     [NotNull] IRelationalConnection connection,
     [NotNull] IMigrationsModelDiffer modelDiffer,
     [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
     [NotNull] ISqlStatementExecutor sqlStatementExecutor,
     [NotNull] IModel model)
     : base(model, connection, modelDiffer, migrationsSqlGenerator, sqlStatementExecutor)
 {
 }
 public TestDatabaseCreator(
     ISqlServerConnection connection,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator sqlGenerator,
     ISqlStatementExecutor statementExecutor,
     IModel model)
     : base(connection, modelDiffer, sqlGenerator, statementExecutor, model)
 {
 }
 public TestDatabaseCreator(
     ISqlServerConnection connection,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator sqlGenerator,
     IModel model,
     IRawSqlCommandBuilder rawSqlCommandBuilder)
     : base(connection, modelDiffer, sqlGenerator, model, rawSqlCommandBuilder)
 {
 }
 public MyRelationalDatabaseCreator(
     IModel model,
     IRelationalConnection connection,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator migrationsSqlGenerator,
     IMigrationCommandExecutor migrationCommandExecutor)
     : base(model, connection, modelDiffer, migrationsSqlGenerator, migrationCommandExecutor)
 {
 }
 public MySQLDatabaseCreator(
     [NotNull] RelationalDatabaseCreatorDependencies dependencies,
     [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder)
     : base(dependencies)
 {
     _connection               = (MySQLServerConnection)dependencies.Connection;
     _sqlGenerator             = dependencies.MigrationsSqlGenerator;
     _rawSqlCommandBuilder     = rawSqlCommandBuilder;
     _migrationCommandExecutor = dependencies.MigrationCommandExecutor;
 }
 public SqlServerDatabaseCreator(
     [NotNull] ISqlServerConnection connection,
     [NotNull] IMigrationsModelDiffer modelDiffer,
     [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
     [NotNull] ISqlStatementExecutor statementExecutor,
     [NotNull] IModel model)
     : base(model, connection, modelDiffer, migrationsSqlGenerator, statementExecutor)
 {
     _connection = connection;
     _migrationsSqlGenerator = migrationsSqlGenerator;
 }
 /// <summary>
 ///     Clones this dependency parameter object with one service replaced.
 /// </summary>
 /// <param name="migrationsSqlGenerator"> A replacement for the current dependency of this type. </param>
 /// <returns> A new parameter object with the given service replaced. </returns>
 public RelationalDatabaseCreatorDependencies With([NotNull] IMigrationsSqlGenerator migrationsSqlGenerator)
 => new RelationalDatabaseCreatorDependencies(
     Model,
     Connection,
     ModelDiffer,
     migrationsSqlGenerator,
     MigrationCommandExecutor,
     SqlGenerationHelper,
     ExecutionStrategyFactory,
     CurrentDbContext,
     CommandLogger);
Пример #25
0
 public SqlServerDatabaseCreator(
     [NotNull] ISqlServerConnection connection,
     [NotNull] IMigrationsModelDiffer modelDiffer,
     [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
     [NotNull] ISqlStatementExecutor statementExecutor,
     [NotNull] IModel model)
     : base(model, connection, modelDiffer, migrationsSqlGenerator, statementExecutor)
 {
     _connection             = connection;
     _migrationsSqlGenerator = migrationsSqlGenerator;
 }
 public TestDatabaseCreator(
     NpgsqlRelationalConnection connection,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator sqlGenerator,
     IMigrationCommandExecutor migrationCommandExecutor,
     IModel model,
     IRawSqlCommandBuilder rawSqlCommandBuilder,
     IExecutionStrategyFactory executionStrategyFactory)
     : base(connection, modelDiffer, sqlGenerator, migrationCommandExecutor, model, rawSqlCommandBuilder, executionStrategyFactory)
 {
 }
Пример #27
0
 public IgnoreForeignKeyMySqlMigrator(IMigrationsAssembly migrationsAssembly,
                                      IHistoryRepository historyRepository,
                                      IDatabaseCreator databaseCreator, IMigrationsSqlGenerator migrationsSqlGenerator,
                                      IRawSqlCommandBuilder rawSqlCommandBuilder, IMigrationCommandExecutor migrationCommandExecutor,
                                      IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper,
                                      ICurrentDbContext currentContext, IDiagnosticsLogger <DbLoggerCategory.Migrations> logger,
                                      IDiagnosticsLogger <DbLoggerCategory.Database.Command> commandLogger, IDatabaseProvider databaseProvider) :
     base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder,
          migrationCommandExecutor, connection, sqlGenerationHelper, currentContext, logger, commandLogger,
          databaseProvider)
 {
 }
Пример #28
0
        public SqliteDatabaseCreator(
            [NotNull] IRelationalConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IModel model,
            [NotNull] ISqlCommandBuilder sqlCommandBuilder)
            : base(model, connection, modelDiffer, migrationsSqlGenerator)
        {
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));

            _sqlCommandBuilder = sqlCommandBuilder;
        }
Пример #29
0
        public SqliteDatabaseCreator(
            [NotNull] SqliteRelationalConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IModel model,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder)
            : base(model, connection, modelDiffer, migrationsSqlGenerator)
        {
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));

            _connection           = connection;
            _rawSqlCommandBuilder = rawSqlCommandBuilder;
        }
Пример #30
0
        protected HistoryRepository(
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] IDbContextOptions options,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IRelationalAnnotationProvider annotations,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper)
        {
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(options, nameof(options));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(annotations, nameof(annotations));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));

            _databaseCreator        = (IRelationalDatabaseCreator)databaseCreator;
            _rawSqlCommandBuilder   = rawSqlCommandBuilder;
            _connection             = connection;
            _modelDiffer            = modelDiffer;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            SqlGenerationHelper     = sqlGenerationHelper;

            var relationalOptions = RelationalOptionsExtension.Extract(options);

            TableName   = relationalOptions?.MigrationsHistoryTableName ?? DefaultTableName;
            TableSchema = relationalOptions.MigrationsHistoryTableSchema;
            _model      = new LazyRef <IModel>(
                () =>
            {
                var modelBuilder = new ModelBuilder(new ConventionSet());
                modelBuilder.Entity <HistoryRow>(
                    x =>
                {
                    ConfigureTable(x);
                    x.ToTable(TableName, TableSchema);
                });

                return(modelBuilder.Model);
            });
            var entityType = new LazyRef <IEntityType>(() => _model.Value.FindEntityType(typeof(HistoryRow)));

            _migrationIdColumnName = new LazyRef <string>(
                () => annotations.For(entityType.Value.FindProperty(nameof(HistoryRow.MigrationId))).ColumnName);
            _productVersionColumnName = new LazyRef <string>(
                () => annotations.For(entityType.Value.FindProperty(nameof(HistoryRow.ProductVersion))).ColumnName);
        }
        public SqlServerDatabaseCreator(
            [NotNull] ISqlServerConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IModel model,
            [NotNull] ISqlCommandBuilder sqlCommandBuilder)
            : base(model, connection, modelDiffer, migrationsSqlGenerator)
        {
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));

            _connection = connection;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _sqlCommandBuilder = sqlCommandBuilder;
        }
 /// <summary>
 ///     Clones this dependency parameter object with one service replaced.
 /// </summary>
 /// <param name="migrationsSqlGenerator"> A replacement for the current dependency of this type. </param>
 /// <returns> A new parameter object with the given service replaced. </returns>
 public HistoryRepositoryDependencies With([NotNull] IMigrationsSqlGenerator migrationsSqlGenerator)
 => new HistoryRepositoryDependencies(
     DatabaseCreator,
     RawSqlCommandBuilder,
     Connection,
     Options,
     ModelDiffer,
     migrationsSqlGenerator,
     SqlGenerationHelper,
     ConventionSetBuilder,
     TypeMappingSource,
     CurrentContext,
     ModelLogger,
     CommandLogger);
Пример #33
0
 public TemporalTableMigrator(
     IMigrationsAssembly migrationsAssembly,
     IHistoryRepository historyRepository,
     IDatabaseCreator databaseCreator,
     IMigrationsSqlGenerator migrationsSqlGenerator,
     IRawSqlCommandBuilder rawSqlCommandBuilder,
     IMigrationCommandExecutor migrationCommandExecutor,
     IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper,
     IDiagnosticsLogger <DbLoggerCategory.Migrations> logger,
     IDatabaseProvider databaseProvider,
     ITemporalTableSqlExecutor <TContext> temporalTableSqlExecutor)
     : base(migrationsAssembly, historyRepository, databaseCreator, migrationsSqlGenerator, rawSqlCommandBuilder, migrationCommandExecutor, connection, sqlGenerationHelper, logger, databaseProvider)
 {
     this.temporalTableSqlExecutor = temporalTableSqlExecutor;
 }
        /// <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>
        public SqlServerDatabaseCreator(
            [NotNull] ISqlServerConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IMigrationCommandExecutor migrationCommandExecutor,
            [NotNull] IModel model,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder)
            : base(model, connection, modelDiffer, migrationsSqlGenerator, migrationCommandExecutor)
        {
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));

            _connection             = connection;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _rawSqlCommandBuilder   = rawSqlCommandBuilder;
        }
        /// <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>
        public MyCatDatabaseCreator(
            [NotNull] MyCatRelationalConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IMigrationCommandExecutor migrationCommandExecutor,
            [NotNull] IModel model,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder)
            : base(model, connection, modelDiffer, migrationsSqlGenerator, migrationCommandExecutor)
        {
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));

            _connection = connection;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _rawSqlCommandBuilder = rawSqlCommandBuilder;
        }
Пример #36
0
        public HistoryRepository(
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] ISqlStatementExecutor executor,
            [NotNull] IRelationalConnection connection,
            [NotNull] IDbContextOptions options,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IRelationalAnnotationProvider annotations,
            [NotNull] ISqlGenerator sqlGenerator)
        {
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(options, nameof(options));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(annotations, nameof(annotations));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));

            _databaseCreator = (IRelationalDatabaseCreator)databaseCreator;
            _executor = executor;
            _connection = connection;
            _modelDiffer = modelDiffer;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            SqlGenerator = sqlGenerator;

            var relationalOptions = RelationalOptionsExtension.Extract(options);
            TableName = relationalOptions?.MigrationsHistoryTableName ?? DefaultTableName;
            TableSchema = relationalOptions.MigrationsHistoryTableSchema;
            _model = new LazyRef<IModel>(
                () =>
                {
                    var modelBuilder = new ModelBuilder(new ConventionSet());
                    modelBuilder.Entity<HistoryRow>(
                        x =>
                        {
                            ConfigureTable(x);
                            x.ToTable(TableName, TableSchema);
                        });

                    return modelBuilder.Model;
                });
            var entityType = new LazyRef<IEntityType>(() => _model.Value.GetEntityType(typeof(HistoryRow)));
            _migrationIdColumnName = new LazyRef<string>(
                () => annotations.For(entityType.Value.FindProperty(nameof(HistoryRow.MigrationId))).ColumnName);
            _productVersionColumnName = new LazyRef<string>(
                () => annotations.For(entityType.Value.FindProperty(nameof(HistoryRow.ProductVersion))).ColumnName);
        }
        protected RelationalDatabaseCreator(
            [NotNull] IModel model,
            [NotNull] IRelationalConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator)
        {
            Check.NotNull(model, nameof(model));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));

            Model = model;
            Connection = connection;
            _modelDiffer = modelDiffer;
            _migrationsSqlGenerator = migrationsSqlGenerator;
        }
Пример #38
0
 /// <summary>
 /// Creates a new instance of <see cref="DataMigrator"/>.
 /// </summary>
 public DataMigrator(
     IHistoryRepository historyRepository,
     IDatabaseCreator databaseCreator,
     IMigrationsSqlGenerator migrationsSqlGenerator,
     IRawSqlCommandBuilder rawSqlCommandBuilder,
     IRelationalConnection connection,
     ILoggerFactory loggerFactory,
     IServiceProvider serviceProvider)
 {
     _historyRepository = historyRepository;
     _databaseCreator = (IRelationalDatabaseCreator)databaseCreator;
     _migrationsSqlGenerator = migrationsSqlGenerator;
     _rawSqlCommandBuilder = rawSqlCommandBuilder;
     _connection = connection;
     _serviceProvider = serviceProvider;
     _logger = loggerFactory.CreateLogger<DataMigrator>();
 }
        public SqliteDatabaseCreator(
            [NotNull] IRelationalConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] ISqlStatementExecutor sqlStatementExecutor,
            [NotNull] IModel model)
            : base(model)
        {
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(sqlStatementExecutor, nameof(sqlStatementExecutor));

            _connection = connection;
            _modelDiffer = modelDiffer;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _executor = sqlStatementExecutor;
        }
 public MyHistoryRepository(
     IDatabaseCreator databaseCreator,
     IRawSqlCommandBuilder rawSqlCommandBuilder,
     IRelationalConnection connection,
     IDbContextOptions options,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator migrationsSqlGenerator,
     IRelationalAnnotationProvider annotations,
     ISqlGenerationHelper sqlGenerationHelper)
     : base(databaseCreator,
         rawSqlCommandBuilder,
         connection,
         options,
         modelDiffer,
         migrationsSqlGenerator,
         annotations,
         sqlGenerationHelper
         )
 {
 }
 public TestDatabaseCreator(
     ISqlServerConnection connection,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator sqlGenerator,
     ISqlStatementExecutor statementExecutor,
     IModel model)
     : base(connection, modelDiffer, sqlGenerator, statementExecutor, model)
 {
 }
 public MyRelationalDatabaseCreator(IModel model, IRelationalConnection connection,
     IMigrationsModelDiffer modelDiffer, IMigrationsSqlGenerator migrationsSqlGenerator)
     : base(model, connection, modelDiffer, migrationsSqlGenerator)
 {
 }
 public TestDatabaseCreator(
     ISqlServerConnection connection,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator sqlGenerator,
     IModel model,
     IRawSqlCommandBuilder rawSqlCommandBuilder)
     : base(connection, modelDiffer, sqlGenerator, model, rawSqlCommandBuilder)
 {
 }