예제 #1
0
        public Migrator(
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDataStoreCreator dataStoreCreator,
            [NotNull] IMigrationSqlGenerator migrationSqlGenerator,
            [NotNull] SqlStatementExecutor executor,
            [NotNull] IRelationalConnection connection,
            [NotNull] IModelDiffer modelDiffer,
            [NotNull] IModel model,
            [NotNull] MigrationIdGenerator idGenerator,
            [NotNull] ISqlGenerator sqlGenerator)
        {
            Check.NotNull(migrationAssembly, nameof(migrationAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(dataStoreCreator, nameof(dataStoreCreator));
            Check.NotNull(migrationSqlGenerator, nameof(migrationSqlGenerator));
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(model, nameof(model));
            Check.NotNull(idGenerator, nameof(idGenerator));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));

            _migrationAssembly = migrationAssembly;
            _historyRepository = historyRepository;
            _dataStoreCreator = (IRelationalDataStoreCreator)dataStoreCreator;
            _migrationSqlGenerator = migrationSqlGenerator;
            _executor = executor;
            _connection = connection;
            _modelDiffer = modelDiffer;
            _model = model;
            _idGenerator = idGenerator;
            _sqlGenerator = sqlGenerator;
        }
예제 #2
0
        public Migrator(
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDataStoreCreator dataStoreCreator,
            [NotNull] IMigrationSqlGenerator migrationSqlGenerator,
            [NotNull] SqlStatementExecutor executor,
            [NotNull] IRelationalConnection connection,
            [NotNull] IModelDiffer modelDiffer,
            [NotNull] IModel model,
            [NotNull] MigrationIdGenerator idGenerator,
            [NotNull] ISqlGenerator sqlGenerator)
        {
            Check.NotNull(migrationAssembly, nameof(migrationAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(dataStoreCreator, nameof(dataStoreCreator));
            Check.NotNull(migrationSqlGenerator, nameof(migrationSqlGenerator));
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(model, nameof(model));
            Check.NotNull(idGenerator, nameof(idGenerator));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));

            _migrationAssembly     = migrationAssembly;
            _historyRepository     = historyRepository;
            _dataStoreCreator      = (IRelationalDataStoreCreator)dataStoreCreator;
            _migrationSqlGenerator = migrationSqlGenerator;
            _executor     = executor;
            _connection   = connection;
            _modelDiffer  = modelDiffer;
            _model        = model;
            _idGenerator  = idGenerator;
            _sqlGenerator = sqlGenerator;
        }
예제 #3
0
        public Migrator(
            [NotNull] DbContextConfiguration contextConfiguration,
            [NotNull] HistoryRepository historyRepository,
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] ModelDiffer modelDiffer,
            [NotNull] IMigrationOperationSqlGeneratorFactory ddlSqlGeneratorFactory,
            [NotNull] SqlGenerator dmlSqlGenerator,
            [NotNull] SqlStatementExecutor sqlExecutor)
        {
            Check.NotNull(contextConfiguration, "contextConfiguration");
            Check.NotNull(historyRepository, "historyRepository");
            Check.NotNull(migrationAssembly, "migrationAssembly");
            Check.NotNull(modelDiffer, "modelDiffer");
            Check.NotNull(ddlSqlGeneratorFactory, "ddlSqlGeneratorFactory");
            Check.NotNull(dmlSqlGenerator, "dmlSqlGenerator");
            Check.NotNull(sqlExecutor, "sqlExecutor");

            _contextConfiguration = contextConfiguration;
            _historyRepository = historyRepository;
            _migrationAssembly = migrationAssembly;
            _modelDiffer = modelDiffer;
            _ddlSqlGeneratorFactory = ddlSqlGeneratorFactory;
            _dmlSqlGenerator = dmlSqlGenerator;
            _sqlExecutor = sqlExecutor;
        }
예제 #4
0
        public Migrator(
            [NotNull] HistoryRepository historyRepository,
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] ModelDiffer modelDiffer,
            [NotNull] IMigrationOperationSqlGeneratorFactory ddlSqlGeneratorFactory,
            [NotNull] SqlGenerator dmlSqlGenerator,
            [NotNull] SqlStatementExecutor sqlExecutor,
            [NotNull] RelationalDataStoreCreator storeCreator,
            [NotNull] RelationalConnection connection,
            [NotNull] ILoggerFactory loggerFactory)
        {
            Check.NotNull(historyRepository, "historyRepository");
            Check.NotNull(migrationAssembly, "migrationAssembly");
            Check.NotNull(modelDiffer, "modelDiffer");
            Check.NotNull(ddlSqlGeneratorFactory, "ddlSqlGeneratorFactory");
            Check.NotNull(dmlSqlGenerator, "dmlSqlGenerator");
            Check.NotNull(sqlExecutor, "sqlExecutor");
            Check.NotNull(storeCreator, "storeCreator");
            Check.NotNull(connection, "connection");
            Check.NotNull(loggerFactory, "loggerFactory");

            _historyRepository      = historyRepository;
            _migrationAssembly      = migrationAssembly;
            _modelDiffer            = modelDiffer;
            _ddlSqlGeneratorFactory = ddlSqlGeneratorFactory;
            _dmlSqlGenerator        = dmlSqlGenerator;
            _sqlExecutor            = sqlExecutor;
            _storeCreator           = storeCreator;
            _connection             = connection;
            _logger = new DbContextService <ILogger>(loggerFactory.Create <Migrator>);
        }
예제 #5
0
        public Migrator(
            [NotNull] DbContextConfiguration contextConfiguration,
            [NotNull] HistoryRepository historyRepository,
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] ModelDiffer modelDiffer,
            [NotNull] IMigrationOperationSqlGeneratorFactory ddlSqlGeneratorFactory,
            [NotNull] SqlGenerator dmlSqlGenerator,
            [NotNull] SqlStatementExecutor sqlExecutor)
        {
            Check.NotNull(contextConfiguration, "contextConfiguration");
            Check.NotNull(historyRepository, "historyRepository");
            Check.NotNull(migrationAssembly, "migrationAssembly");
            Check.NotNull(modelDiffer, "modelDiffer");
            Check.NotNull(ddlSqlGeneratorFactory, "ddlSqlGeneratorFactory");
            Check.NotNull(dmlSqlGenerator, "dmlSqlGenerator");
            Check.NotNull(sqlExecutor, "sqlExecutor");

            _contextConfiguration   = contextConfiguration;
            _historyRepository      = historyRepository;
            _migrationAssembly      = migrationAssembly;
            _modelDiffer            = modelDiffer;
            _ddlSqlGeneratorFactory = ddlSqlGeneratorFactory;
            _dmlSqlGenerator        = dmlSqlGenerator;
            _sqlExecutor            = sqlExecutor;
        }
예제 #6
0
        protected override bool HasTables()
        {
            var count = (long)SqlStatementExecutor.ExecuteScalar(
                Connection,
                "SELECT COUNT(*) FROM \"sqlite_master\" WHERE \"type\" = 'table' AND \"rootpage\" IS NOT NULL;");

            return(count != 0);
        }
예제 #7
0
        public override async Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            ClearAllPools();

            using (var masterConnection = _connection.CreateMasterConnection())
            {
                await SqlStatementExecutor.ExecuteNonQueryAsync(masterConnection, CreateDropCommands(), cancellationToken);
            }
        }
예제 #8
0
        public override void Create()
        {
            using (var masterConnection = _connection.CreateMasterConnection())
            {
                SqlStatementExecutor.ExecuteNonQuery(masterConnection, CreateCreateOperations());
                ClearPool();
            }

            Exists(retryOnNotExists: true);
        }
예제 #9
0
        public override void Delete()
        {
            ClearAllPools();

            using (var masterConnection = _connection.CreateMasterConnection())
            {
                SqlStatementExecutor
                .ExecuteNonQuery(masterConnection, CreateDropCommands());
            }
        }
        public SqlServerSequenceValueGenerator(
            [NotNull] SqlStatementExecutor executor,
            [NotNull] string sequenceName,
            int blockSize)
            : base(sequenceName, blockSize)
        {
            Check.NotNull(executor, "executor");

            _executor = executor;
        }
        public SqlServerSequenceValueGenerator(
            [NotNull] SqlStatementExecutor executor,
            [NotNull] string sequenceName,
            int blockSize)
        {
            Check.NotNull(executor, "executor");
            Check.NotEmpty(sequenceName, "sequenceName");

            _executor = executor;
            _sequenceName = sequenceName;
            _blockSize = blockSize;
        }
예제 #12
0
        public SqlServerSequenceValueGenerator(
            [NotNull] SqlStatementExecutor executor,
            [NotNull] string sequenceName,
            int blockSize)
        {
            Check.NotNull(executor, "executor");
            Check.NotEmpty(sequenceName, "sequenceName");

            _executor     = executor;
            _sequenceName = sequenceName;
            _blockSize    = blockSize;
        }
예제 #13
0
        public override async Task CreateAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var masterConnection = _connection.CreateMasterConnection())
            {
                await SqlStatementExecutor
                .ExecuteNonQueryAsync(masterConnection, CreateCreateOperations(), cancellationToken);

                ClearPool();
            }

            await ExistsAsync(retryOnNotExists : true, cancellationToken : cancellationToken);
        }
        public NpgsqlSequenceValueGenerator(
            [NotNull] SqlStatementExecutor executor,
            [NotNull] NpgsqlSequenceValueGeneratorState generatorState,
            [NotNull] INpgsqlConnection connection)
            : base(generatorState)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(generatorState, nameof(generatorState));
            Check.NotNull(connection, nameof(connection));

            _sequenceName = generatorState.SequenceName;
            _executor     = executor;
            _connection   = connection;
        }
        private static void CreateDatabaseSequence(BronieContext context, DataStoreConnection storeConnection)
        {
            var executor = new SqlStatementExecutor();

            var operations = new SqlServerSequenceValueGeneratorFactory(executor)
                             .GetUpMigrationOperations(context.Model.GetEntityType(typeof(Pegasus))
                                                       .GetProperty("Identifier"));

            var sql = new SqlServerMigrationOperationSqlGenerator(new SqlServerTypeMapper())
                      .Generate(operations, generateIdempotentSql: false);

            // TODO: Should be able to get relational connection without cast
            var connection = ((RelationalConnection)storeConnection).DbConnection;

            executor.ExecuteNonQuery(connection, sql);
        }
예제 #16
0
        public SqlServerDataStoreCreator(
            [NotNull] SqlServerConnection connection,
            [NotNull] ModelDiffer modelDiffer,
            [NotNull] SqlServerMigrationOperationSqlGenerator sqlGenerator,
            [NotNull] SqlStatementExecutor statementExecutor)
        {
            Check.NotNull(connection, "connection");
            Check.NotNull(modelDiffer, "modelDiffer");
            Check.NotNull(sqlGenerator, "sqlGenerator");
            Check.NotNull(statementExecutor, "statementExecutor");

            _connection        = connection;
            _modelDiffer       = modelDiffer;
            _sqlGenerator      = sqlGenerator;
            _statementExecutor = statementExecutor;
        }
예제 #17
0
        public NpgsqlDataStoreCreator(
            [NotNull] NpgsqlEntityFrameworkConnection connection,
            [NotNull] NpgsqlModelDiffer modelDiffer,
            [NotNull] NpgsqlMigrationSqlGenerator sqlGenerator,
            [NotNull] SqlStatementExecutor statementExecutor)
        {
            Check.NotNull(connection, "connection");
            Check.NotNull(modelDiffer, "modelDiffer");
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));
            Check.NotNull(statementExecutor, "statementExecutor");

            _connection        = connection;
            _modelDiffer       = modelDiffer;
            _sqlGenerator      = sqlGenerator;
            _statementExecutor = statementExecutor;
        }
예제 #18
0
        public SQLiteDataStoreCreator(
            [NotNull] SQLiteConnection connection,
            [NotNull] SqlStatementExecutor executor,
            [NotNull] SQLiteMigrationOperationSqlGeneratorFactory generatorFactory,
            [NotNull] SQLiteModelDiffer modelDiffer)
        {
            Check.NotNull(connection, "connection");
            Check.NotNull(executor, "executor");
            Check.NotNull(generatorFactory, "generatorFactory");
            Check.NotNull(modelDiffer, "modelDiffer");

            _connection       = connection;
            _executor         = executor;
            _generatorFactory = generatorFactory;
            _modelDiffer      = modelDiffer;
        }
예제 #19
0
        public SqlServerDataStoreCreator(
            [NotNull] ISqlServerConnection connection,
            [NotNull] ISqlServerModelDiffer modelDiffer,
            [NotNull] ISqlServerMigrationSqlGenerator sqlGenerator,
            [NotNull] SqlStatementExecutor statementExecutor)
        {
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));
            Check.NotNull(statementExecutor, nameof(statementExecutor));

            _connection        = connection;
            _modelDiffer       = modelDiffer;
            _sqlGenerator      = sqlGenerator;
            _statementExecutor = statementExecutor;
        }
예제 #20
0
 public SQLiteMigrator(
     [NotNull] DbContextConfiguration contextConfiguration,
     [NotNull] HistoryRepository historyRepository,
     [NotNull] MigrationAssembly migrationAssembly,
     [NotNull] ModelDiffer modelDiffer,
     [NotNull] SQLiteMigrationOperationSqlGeneratorFactory ddlSqlGeneratorFactory,
     [NotNull] SQLiteSqlGenerator dmlSqlGenerator,
     [NotNull] SqlStatementExecutor sqlExecutor)
     : base(
         contextConfiguration,
         historyRepository,
         migrationAssembly,
         modelDiffer,
         ddlSqlGeneratorFactory,
         dmlSqlGenerator,
         sqlExecutor)
 {
 }
예제 #21
0
 public SqlServerMigrator(
     [NotNull] DbContextConfiguration contextConfiguration,
     [NotNull] HistoryRepository historyRepository,
     [NotNull] MigrationAssembly migrationAssembly,
     [NotNull] SqlServerModelDiffer modelDiffer,
     [NotNull] SqlServerMigrationOperationSqlGeneratorFactory sqlGeneratorFactory,
     [NotNull] SqlServerSqlGenerator sqlGenerator,
     [NotNull] SqlStatementExecutor sqlStatementExecutor)
     : base(
         contextConfiguration,
         historyRepository,
         migrationAssembly,
         modelDiffer,
         sqlGeneratorFactory,
         sqlGenerator,
         sqlStatementExecutor)
 {
 }
예제 #22
0
 public TestMigrator(
     HistoryRepository historyRepository,
     MigrationAssembly migrationAssembly,
     FakeModelDiffer modelDiffer,
     FakeMigrationOperationSqlGeneratorFactory ddlSqlGeneratorFactory,
     FakeSqlGenerator dmlSqlGenerator,
     SqlStatementExecutor sqlExecutor,
     RecordingDataStoreCreator storeCreator,
     FakeRelationalConnection connection,
     ILoggerFactory loggerFactory)
     : base(
         historyRepository,
         migrationAssembly,
         modelDiffer,
         ddlSqlGeneratorFactory,
         dmlSqlGenerator,
         sqlExecutor,
         storeCreator,
         connection,
         loggerFactory)
 {
 }
 public SqlServerMigrator(
     [NotNull] HistoryRepository historyRepository,
     [NotNull] MigrationAssembly migrationAssembly,
     [NotNull] SqlServerModelDiffer modelDiffer,
     [NotNull] SqlServerMigrationOperationSqlGeneratorFactory sqlGeneratorFactory,
     [NotNull] SqlServerSqlGenerator sqlGenerator,
     [NotNull] SqlStatementExecutor sqlStatementExecutor,
     [NotNull] SqlServerDataStoreCreator storeCreator,
     [NotNull] SqlServerConnection connection,
     [NotNull] ILoggerFactory loggerFactory)
     : base(
         historyRepository,
         migrationAssembly,
         modelDiffer,
         sqlGeneratorFactory,
         sqlGenerator,
         sqlStatementExecutor,
         storeCreator,
         connection,
         loggerFactory)
 {
 }
예제 #24
0
 protected override bool HasTables()
 => (int)SqlStatementExecutor.ExecuteScalar(_connection, CreateHasTablesCommand()) != 0;
예제 #25
0
        public NpgsqlSequenceValueGeneratorFactory([NotNull] SqlStatementExecutor executor)
        {
            Check.NotNull(executor, nameof(executor));

            _executor = executor;
        }
예제 #26
0
 protected override async Task <bool> HasTablesAsync(CancellationToken cancellationToken = default(CancellationToken))
 => (int)(await SqlStatementExecutor
          .ExecuteScalarAsync(_connection, CreateHasTablesCommand(), cancellationToken)) != 0;
예제 #27
0
        public SqlServerSequenceValueGeneratorFactory([NotNull] SqlStatementExecutor executor)
        {
            Check.NotNull(executor, "executor");

            _executor = executor;
        }