Skip to content

Manual extension check to prevent permission issues #3496

@dkottis

Description

@dkottis

Currently, extensions are always checked or installed using CREATE EXTENSION IF NOT EXISTS. However, due to a recent change by Microsoft with PostgreSQL Flexible Servers, only the superuser has permission to create an extension. See here.

In our scenario, the application automatically migrates its database. This process triggers the CREATE EXTENSION IF NOT EXISTS command, which, even if the extension is already installed, fails due to insufficient rights.

Would it be possible to perform a manual check to determine if an extension is already installed at this location:

//...
        builder
            .Append("CREATE EXTENSION IF NOT EXISTS ")
            .Append(DelimitIdentifier(extension.Name));
//...

similar to how the schema is checked here:

//...
        // PostgreSQL has CREATE SCHEMA IF NOT EXISTS, but that requires CREATE privileges on the database even if the schema already
        // exists. This blocks multi-tenant scenarios where the user has no database privileges.
        // So we procedurally check if the schema exists instead, and create it if not.
        var schemaName = operation.Name.Replace("'", "''");

        // If we're generating an idempotent migration, we're already in a PL/PGSQL DO block; otherwise we need to start one.
        if (!Options.HasFlag(MigrationsSqlGenerationOptions.Idempotent))
        {
            builder
                .AppendLine(@"DO $EF$")
                .AppendLine("BEGIN");
        }
//...

This would also benefit other scenarios where the application might not have sufficient rights to create extensions.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions