Skip to content

Regression: database existence check in HistoryRepository no longer goes through DatabaseCreator #34569

@roji

Description

@roji

As part of #34115, the implementation of HistoryRepository.Exists was changed to no longer use the DatabaseCreator:

Old Exists

public virtual bool Exists()
	=> Dependencies.DatabaseCreator.Exists()
		&& InterpretExistsResult(
			Dependencies.RawSqlCommandBuilder.Build(ExistsSql).ExecuteScalar(
				new RelationalCommandParameterObject(
					Dependencies.Connection,
					null,
					null,
					Dependencies.CurrentContext.Context,
					Dependencies.CommandLogger, CommandSource.Migrations)));

New Exists

public virtual bool Exists()
	=> InterpretExistsResult(
		Dependencies.RawSqlCommandBuilder.Build(ExistsSql).ExecuteScalar(
			new RelationalCommandParameterObject(
				Dependencies.Connection,
				null,
				null,
				Dependencies.CurrentContext.Context,
				Dependencies.CommandLogger, CommandSource.Migrations)));

This breaks PG, and likely other databases as well - it assumes that one can connect/login with the connection string containing the non-existing database, and then find out whether the database exists via the query. But in PG you can't connect to a non-existing database.

As a result, NpgsqlDatabaseCreator implements its Exists by simply trying to connect, and interpreting "database doesn't exist" behavior to return false etc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions