/// <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 void Migrate(string targetMigration = null) { _logger.MigrateUsingConnection(this, _connection); if (!_historyRepository.Exists()) { if (!_databaseCreator.Exists()) { _databaseCreator.Create(); } var command = _rawSqlCommandBuilder.Build( _historyRepository.GetCreateScript()); command.ExecuteNonQuery( new RelationalCommandParameterObject( _connection, null, null, _currentContext.Context, _commandLogger)); } var commandLists = GetMigrationCommandLists(_historyRepository.GetAppliedMigrations(), targetMigration); foreach (var commandList in commandLists) { _migrationCommandExecutor.ExecuteNonQuery(commandList(), _connection); } }
private void Migrate(MyCatDatabaseHost node, string targetMigration = null) { var connection = _connection.CreateNodeConnection(node); _logger.LogDebug(RelationalStrings.UsingConnection(connection.DbConnection.Database, connection.DbConnection.DataSource)); if (!_historyRepository.Exists(connection)) { if (!_databaseCreator.Exists(connection)) { _databaseCreator.Create(node); } var command = _rawSqlCommandBuilder.Build(_historyRepository.GetCreateScript()); command.ExecuteNonQuery(connection); } var commandLists = GetMigrationCommandLists(_historyRepository.GetAppliedMigrations(connection), targetMigration); foreach (var commandList in commandLists) { _migrationCommandExecutor.ExecuteNonQuery(commandList(), connection); } connection.Close(); connection.Dispose(); }
/// <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 void Migrate(string targetMigration = null) { var connection = _connection.DbConnection; _logger.LogDebug( RelationalEventId.MigrateUsingConnection, () => RelationalStrings.UsingConnection(connection.Database, connection.DataSource)); if (!_historyRepository.Exists()) { if (!_databaseCreator.Exists()) { _databaseCreator.Create(); } var command = _rawSqlCommandBuilder.Build(_historyRepository.GetCreateScript()); command.ExecuteNonQuery(_connection); } var commandLists = GetMigrationCommandLists(_historyRepository.GetAppliedMigrations(), targetMigration); foreach (var commandList in commandLists) { _migrationCommandExecutor.ExecuteNonQuery(commandList(), _connection); } }
public virtual void Migrate(string targetMigration = null) { var connection = _connection.DbConnection; _logger.LogDebug(RelationalStrings.UsingConnection(connection.Database, connection.DataSource)); if (!_historyRepository.Exists()) { if (!_databaseCreator.Exists()) { _databaseCreator.Create(); } var command = _rawSqlCommandBuilder.Build(_historyRepository.GetCreateScript()); Execute(new[] { command }); } var commands = GetMigrationCommands(_historyRepository.GetAppliedMigrations(), targetMigration); foreach (var command in commands) { Execute(command()); } }
protected override long GetNewLowValue() => (long)Convert.ChangeType( _rawSqlCommandBuilder .Build(_sqlGenerator.GenerateNextSequenceValueOperation(_sequence.Name, _sequence.Schema)) .ExecuteScalar(_connection), typeof(long), CultureInfo.InvariantCulture);
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build(@" SELECT CASE WHEN COUNT(*) = 0 THEN FALSE ELSE TRUE END FROM information_schema.tables AS t WHERE t.table_catalog = '' and t.table_schema = '' ");
protected override bool HasTables() { string sql = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" + _connection.DbConnection.Database + "'"; long count = (long)_rawSqlCommandBuilder.Build(sql).ExecuteScalar(_connection); return(count != 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 override void Create() { Dependencies.Connection.Open(); _rawSqlCommandBuilder.Build("PRAGMA journal_mode = 'wal';") .ExecuteNonQuery(Dependencies.Connection, null, Dependencies.CommandLogger); Dependencies.Connection.Close(); }
/// <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 override void Create() { Dependencies.Connection.Open(); _rawSqlCommandBuilder .Build($"create database {Dependencies.Connection.DbConnection.Database};") .ExecuteNonQuery(Dependencies.Connection); Dependencies.Connection.Close(); }
private void EnableForeignKeys() { if (_enforceForeignKeys) { _rawSqlCommandBuilder.Build("PRAGMA foreign_keys=ON;").ExecuteNonQuery(this); } else { _rawSqlCommandBuilder.Build("PRAGMA foreign_keys=OFF;").ExecuteNonQuery(this); } }
/// <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 override long GetNewLowValue() => (long)Convert.ChangeType( _rawSqlCommandBuilder .Build(_sqlGenerator.GenerateNextSequenceValueOperation(_sequence.Name, _sequence.Schema)) .ExecuteScalar( new RelationalCommandParameterObject( _connection, parameterValues: null, readerColumns: null, context: null, _commandLogger)), typeof(long), CultureInfo.InvariantCulture) !;
/// <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 override void Create() { Dependencies.Connection.Open(); _rawSqlCommandBuilder.Build("PRAGMA journal_mode = 'wal';") .ExecuteNonQuery( new RelationalCommandParameterObject( Dependencies.Connection, null, null, null, Dependencies.CommandLogger, CommandSource.Migrations)); Dependencies.Connection.Close(); }
/// <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 override void Create() { Dependencies.Connection.Open(); _rawSqlCommandBuilder .Build($"create database {Dependencies.Connection.DbConnection.Database};") .ExecuteNonQuery(new RelationalCommandParameterObject( Dependencies.Connection, null, null, null, Dependencies.CommandLogger)); Dependencies.Connection.Close(); }
IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build(@" SELECT CASE WHEN COUNT(*) = 0 THEN FALSE ELSE TRUE END FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema') ");
/// <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 override bool HasTables() { var count = (long)_rawSqlCommandBuilder .Build("SELECT COUNT(*) FROM \"sqlite_master\" WHERE \"type\" = 'table' AND \"rootpage\" IS NOT NULL;") .ExecuteScalar(Dependencies.Connection); return(count != 0); }
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build(@" select CASE WHEN COUNT(*) = 0 THEN 0 ELSE 1 END from rdb$relations where rdb$view_blr is null and (rdb$system_flag is null or rdb$system_flag = 0)");
IRelationalCommand CreateHasTablesCommand() { var sql = $@" SELECT if(COUNT() = 0, 0, 1) FROM system.tables WHERE database = '{Dependencies.Connection.DbConnection.Database}';"; return(_rawSqlCommandBuilder.Build(sql)); }
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build( @" IF EXISTS (SELECT * FROM [sys].[objects] o WHERE [o].[type] = 'U' AND [o].[is_ms_shipped] = 0 AND NOT EXISTS (SELECT * FROM [sys].[extended_properties] AS [ep] WHERE [ep].[major_id] = [o].[object_id] AND [ep].[minor_id] = 0 AND [ep].[class] = 1 AND [ep].[name] = N'microsoft_database_tools_support' ) ) SELECT 1 ELSE SELECT 0");
private IReadOnlyList <MigrationCommand> WrapWithCustomCommands( IReadOnlyList <MigrationOperation> migrationOperations, List <MigrationCommand> migrationCommands) { var beginCommandTexts = GetMigrationCommandTexts(migrationOperations, true); var endCommandTexts = GetMigrationCommandTexts(migrationOperations, false); migrationCommands.InsertRange(0, beginCommandTexts.Select(t => new MigrationCommand( _rawSqlCommandBuilder.Build(t), _currentContext.Context, _commandLogger))); migrationCommands.AddRange(endCommandTexts.Select(t => new MigrationCommand( _rawSqlCommandBuilder.Build(t), _currentContext.Context, _commandLogger))); return(migrationCommands); }
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build("IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE') SELECT 1 ELSE SELECT 0");
private IRelationalCommand CreateShowUserTablesCommand() { return(_rawSqlCommandBuilder .Build("SHOW TABLES WHERE TYPE='USER'")); }
public virtual bool Exists() => _databaseCreator.Exists() && InterpretExistsResult( _rawSqlCommandBuilder.Build(ExistsSql).ExecuteScalar(_connection));
private void EnableNSLSort() { _rawSqlCommandBuilder.Build("ALTER SESSION SET NLS_SORT='BINARY_CI'").ExecuteNonQuery(this); }
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build(@"SELECT CASE WHEN COUNT(*) = 0 THEN FALSE ELSE TRUE END FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema = '" + _connection.DbConnection.Database + "'");
public override bool HasTables() { var optionsExtensions = CassandraOptionsExtension.Extract(_relationalConnectionDependencies.ContextOptions); var sql = $"SELECT count(*) FROM system_schema.tables WHERE keyspace_name='{optionsExtensions.DefaultKeyspace}'"; var result = Dependencies.ExecutionStrategyFactory.Create().Execute(_relationalConnection, connection => (long)_rawSqlCommandBuilder.Build(sql).ExecuteScalar( new RelationalCommandParameterObject(connection, null, null, null, null) ) > 0); return(result); }
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder.Build("SELECT COUNT(*) FROM user_tables");
public bool Exists(MyCatRelationalConnection conn) { return(_databaseCreator.Exists(conn) && InterpretExistsResult( _rawSqlCommandBuilder.Build(ExistsSql).ExecuteScalar(conn))); }
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE <> N'SYSTEM TABLE';");
IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder.Build("SELECT COUNT(*) FROM rdb$relations WHERE COALESCE(rdb$system_flag, 0) = 0 AND rdb$view_blr IS NULL");
private IRelationalCommand CreateHasTablesCommand() => _rawSqlCommandBuilder .Build(@"select count(*) from rdb$relations where rdb$view_blr is null and (rdb$system_flag is null or rdb$system_flag = 0);");