/// <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 virtual async Task MigrateAsync( string targetMigration = null, CancellationToken cancellationToken = default(CancellationToken)) { var connection = _connection.DbConnection; _logger.LogDebug( RelationalEventId.MigrateUsingConnection, () => RelationalStrings.UsingConnection(connection.Database, connection.DataSource)); if (!await _historyRepository.ExistsAsync(cancellationToken)) { if (!await _databaseCreator.ExistsAsync(cancellationToken)) { await _databaseCreator.CreateAsync(cancellationToken); } var command = _rawSqlCommandBuilder.Build(_historyRepository.GetCreateScript()); await command.ExecuteNonQueryAsync(_connection, cancellationToken : cancellationToken); } var commandLists = GetMigrationCommandLists( await _historyRepository.GetAppliedMigrationsAsync(cancellationToken), targetMigration); foreach (var commandList in commandLists) { await _migrationCommandExecutor.ExecuteNonQueryAsync(commandList(), _connection, cancellationToken); } }
public virtual async Task MigrateAsync( string targetMigration = null, CancellationToken cancellationToken = default(CancellationToken)) { var connection = _connection.DbConnection; _logger.LogDebug(RelationalStrings.UsingConnection(connection.Database, connection.DataSource)); if (!await _historyRepository.ExistsAsync(cancellationToken)) { if (!await _databaseCreator.ExistsAsync(cancellationToken)) { await _databaseCreator.CreateAsync(cancellationToken); } var command = _rawSqlCommandBuilder.Build(_historyRepository.GetCreateScript()); await ExecuteAsync( new[] { command }, cancellationToken); } var commands = GetMigrationCommands( await _historyRepository.GetAppliedMigrationsAsync(cancellationToken), targetMigration); foreach (var command in commands) { await ExecuteAsync(command(), cancellationToken); } }
/// <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 virtual async Task MigrateAsync( string targetMigration = null, CancellationToken cancellationToken = default) { _logger.MigrateUsingConnection(this, _connection); if (!await _historyRepository.ExistsAsync(cancellationToken)) { if (!await _databaseCreator.ExistsAsync(cancellationToken)) { await _databaseCreator.CreateAsync(cancellationToken); } var command = _rawSqlCommandBuilder.Build(_historyRepository.GetCreateScript()); await command.ExecuteNonQueryAsync(_connection, cancellationToken : cancellationToken); } var commandLists = GetMigrationCommandLists( await _historyRepository.GetAppliedMigrationsAsync(cancellationToken), targetMigration); foreach (var commandList in commandLists) { await _migrationCommandExecutor.ExecuteNonQueryAsync(commandList(), _connection, cancellationToken); } }
/// <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 virtual async Task MigrateAsync( string targetMigration = null, CancellationToken cancellationToken = default) { _logger.MigrateUsingConnection(this, _connection); if (!await _historyRepository.ExistsAsync(cancellationToken).ConfigureAwait(false)) { if (!await _databaseCreator.ExistsAsync(cancellationToken).ConfigureAwait(false)) { await _databaseCreator.CreateAsync(cancellationToken).ConfigureAwait(false); } var command = _rawSqlCommandBuilder.Build( _historyRepository.GetCreateScript()); await command.ExecuteNonQueryAsync( new RelationalCommandParameterObject( _connection, null, null, _currentContext.Context, _commandLogger), cancellationToken) .ConfigureAwait(false); } var commandLists = GetMigrationCommandLists( await _historyRepository.GetAppliedMigrationsAsync(cancellationToken).ConfigureAwait(false), targetMigration); foreach (var commandList in commandLists) { await _migrationCommandExecutor.ExecuteNonQueryAsync(commandList(), _connection, cancellationToken) .ConfigureAwait(false); } }
private async Task CreateDataBase(IRelationalDatabaseCreator databaseCreator, DatabaseFacade dataBase) { //创建数据库 await databaseCreator.CreateAsync(); var sqlScript = dataBase.GenerateCreateScript(); //创建数据表 var sqlCommands = GetCommandsFromScript(sqlScript); foreach (var command in sqlCommands) { await dataBase.ExecuteSqlRawAsync(command); } //创建视图 ExecuteSqlScriptFromFile(dataBase, $"{SqlServerScriptPath}\\SqlServer_Views.sql"); //创建存储过程 ExecuteSqlScriptFromFile(dataBase, $"{SqlServerScriptPath}\\SqlServer_StoredProcedures.sql"); //执行存储过程 ExecuteProcedure(dataBase, "Update_DataBase @dataBase = @p0", _dataBaseName); //创建自定义脚本 ExecuteSqlScriptFromFile(dataBase, $"{SqlServerScriptPath}\\SqlServer_Custom.sql"); //初始化数据脚本 ExecuteSqlScriptFromFile(dataBase, $"{SqlServerScriptPath}\\SqlServer_Data.sql"); }