Table of Contents

Class NpgsqlMigrationsSqlGenerator

Namespace
Npgsql.EntityFrameworkCore.PostgreSQL.Migrations
Assembly
Npgsql.EntityFrameworkCore.PostgreSQL.dll

PostgreSQL-specific implementation of MigrationsSqlGenerator.

public class NpgsqlMigrationsSqlGenerator : MigrationsSqlGenerator, IMigrationsSqlGenerator
Inheritance
NpgsqlMigrationsSqlGenerator
Implements
Inherited Members

Remarks

The service lifetime is Scoped. This means that each DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.

See Database migrations.

Constructors

NpgsqlMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies, INpgsqlSingletonOptions)

Creates a new NpgsqlMigrationsSqlGenerator instance.

public NpgsqlMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, INpgsqlSingletonOptions npgsqlSingletonOptions)

Parameters

dependencies MigrationsSqlGeneratorDependencies

Parameter object containing dependencies for this service.

npgsqlSingletonOptions INpgsqlSingletonOptions

The singleton options to use.

Methods

ApplyTsVectorColumnSql(ColumnOperation, IModel?, string, string?, string)

Checks for a TsVectorConfig annotation on the given column, and if found, assigns the appropriate SQL to ComputedColumnSql.

protected virtual void ApplyTsVectorColumnSql(ColumnOperation column, IModel? model, string name, string? schema, string table)

Parameters

column ColumnOperation
model IModel
name string
schema string
table string

ColumnDefinition(string?, string, string, ColumnOperation, IModel?, MigrationCommandListBuilder)

Generates a SQL fragment for a column definition for the given column metadata.

protected override void ColumnDefinition(string? schema, string table, string name, ColumnOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

schema string

The schema that contains the table, or null to use the default schema.

table string

The table that contains the column.

name string

The column name.

operation ColumnOperation

The column metadata.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to add the SQL fragment.

ComputedColumnDefinition(string?, string, string, ColumnOperation, IModel?, MigrationCommandListBuilder)

Generates a SQL fragment for a computed column definition for the given column metadata.

protected override void ComputedColumnDefinition(string? schema, string table, string name, ColumnOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

schema string

The schema that contains the table, or null to use the default schema.

table string

The table that contains the column.

name string

The column name.

operation ColumnOperation

The column metadata.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to add the SQL fragment.

DefaultValue(object?, string?, string?, MigrationCommandListBuilder)

Generates a SQL fragment for the default constraint of a column.

protected override void DefaultValue(object? defaultValue, string? defaultValueSql, string? columnType, MigrationCommandListBuilder builder)

Parameters

defaultValue object

The default value for the column.

defaultValueSql string

The SQL expression to use for the column's default constraint.

columnType string

Store/database type of the column.

builder MigrationCommandListBuilder

The command builder to use to add the SQL fragment.

Generate(AddColumnOperation, IModel?, MigrationCommandListBuilder, bool)

Builds commands for the given AddColumnOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(AddColumnOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)

Parameters

operation AddColumnOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

terminate bool

Indicates whether or not to terminate the command after generating SQL for the operation.

Generate(AlterColumnOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given AlterColumnOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(AlterColumnOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation AlterColumnOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that the default implementation of this method throws NotSupportedException. Providers must override if they are to support this kind of operation.

Generate(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given AlterDatabaseOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation AlterDatabaseOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that there is no default implementation of this method. Providers must override if they are to support this kind of operation.

Generate(AlterTableOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given AlterTableOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(AlterTableOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation AlterTableOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that the default implementation of this method does nothing because there is no common metadata relating to this operation. Providers only need to override this method if they have some provider-specific annotations that must be handled.

Generate(CreateIndexOperation, IModel?, MigrationCommandListBuilder, bool)

Builds commands for the given CreateIndexOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(CreateIndexOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)

Parameters

operation CreateIndexOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

terminate bool

Indicates whether or not to terminate the command after generating SQL for the operation.

Generate(CreateSequenceOperation, IModel?, MigrationCommandListBuilder)

Builds commands for the given CreateSequenceOperation by making calls on the given MigrationCommandListBuilder, and then terminates the final command.

protected override void Generate(CreateSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation CreateSequenceOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Generate(CreateTableOperation, IModel?, MigrationCommandListBuilder, bool)

Builds commands for the given CreateTableOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(CreateTableOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)

Parameters

operation CreateTableOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

terminate bool

Indicates whether or not to terminate the command after generating SQL for the operation.

Generate(DropColumnOperation, IModel?, MigrationCommandListBuilder, bool)

Builds commands for the given DropColumnOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(DropColumnOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)

Parameters

operation DropColumnOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

terminate bool

Indicates whether or not to terminate the command after generating SQL for the operation.

Generate(DropIndexOperation, IModel?, MigrationCommandListBuilder, bool)

Can be overridden by database providers to build commands for the given DropIndexOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(DropIndexOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)

Parameters

operation DropIndexOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

terminate bool

Indicates whether or not to terminate the command after generating SQL for the operation.

Remarks

Note that the default implementation of this method throws NotSupportedException. Providers must override if they are to support this kind of operation.

Generate(EnsureSchemaOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given EnsureSchemaOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(EnsureSchemaOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation EnsureSchemaOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that the default implementation of this method throws NotSupportedException. Providers must override if they are to support this kind of operation.

Generate(InsertDataOperation, IModel?, MigrationCommandListBuilder, bool)

Builds commands for the given InsertDataOperation by making calls on the given MigrationCommandListBuilder, and then terminates the final command.

protected override void Generate(InsertDataOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)

Parameters

operation InsertDataOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

terminate bool

Indicates whether or not to terminate the command after generating SQL for the operation.

Generate(MigrationOperation, IModel?, MigrationCommandListBuilder)

Builds commands for the given MigrationOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(MigrationOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation MigrationOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

This method uses a double-dispatch mechanism to call one of the 'Generate' methods that are specific to a certain subtype of MigrationOperation. Typically database providers will override these specific methods rather than this method. However, providers can override this methods to handle provider-specific operations.

Generate(RenameColumnOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given RenameColumnOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(RenameColumnOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation RenameColumnOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that the default implementation of this method throws NotSupportedException. Providers must override if they are to support this kind of operation.

Generate(RenameIndexOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given RenameIndexOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(RenameIndexOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation RenameIndexOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that the default implementation of this method throws NotSupportedException. Providers must override if they are to support this kind of operation.

Generate(RenameSequenceOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given RenameSequenceOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(RenameSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation RenameSequenceOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that the default implementation of this method throws NotSupportedException. Providers must override if they are to support this kind of operation.

Generate(RenameTableOperation, IModel?, MigrationCommandListBuilder)

Can be overridden by database providers to build commands for the given RenameTableOperation by making calls on the given MigrationCommandListBuilder.

protected override void Generate(RenameTableOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation RenameTableOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Remarks

Note that the default implementation of this method throws NotSupportedException. Providers must override if they are to support this kind of operation.

Generate(RestartSequenceOperation, IModel?, MigrationCommandListBuilder)

Builds commands for the given RestartSequenceOperation by making calls on the given MigrationCommandListBuilder, and then terminates the final command.

protected override void Generate(RestartSequenceOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation RestartSequenceOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to build the commands.

Generate(NpgsqlCreateDatabaseOperation, IModel?, MigrationCommandListBuilder)

protected virtual void Generate(NpgsqlCreateDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation NpgsqlCreateDatabaseOperation
model IModel
builder MigrationCommandListBuilder

Generate(NpgsqlDropDatabaseOperation, IModel?, MigrationCommandListBuilder)

public virtual void Generate(NpgsqlDropDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation NpgsqlDropDatabaseOperation
model IModel
builder MigrationCommandListBuilder

Generate(IReadOnlyList<MigrationOperation>, IModel?, MigrationsSqlGenerationOptions)

Generates commands from a list of operations.

public override IReadOnlyList<MigrationCommand> Generate(IReadOnlyList<MigrationOperation> operations, IModel? model = null, MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default)

Parameters

operations IReadOnlyList<MigrationOperation>

The operations.

model IModel

The target model which may be null if the operations exist without a model.

options MigrationsSqlGenerationOptions

The options to use when generating commands.

Returns

IReadOnlyList<MigrationCommand>

The list of commands to be executed or scripted.

GenerateAddEnumLabel(PostgresEnum, string, string?, string?, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateAddEnumLabel(PostgresEnum enumType, string addedLabel, string? beforeLabel, string? afterLabel, IModel? model, MigrationCommandListBuilder builder)

Parameters

enumType PostgresEnum
addedLabel string
beforeLabel string
afterLabel string
model IModel
builder MigrationCommandListBuilder

GenerateCollationStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateCollationStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation AlterDatabaseOperation
model IModel
builder MigrationCommandListBuilder

GenerateCreateCollation(PostgresCollation, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateCreateCollation(PostgresCollation collation, IModel? model, MigrationCommandListBuilder builder)

Parameters

collation PostgresCollation
model IModel
builder MigrationCommandListBuilder

GenerateCreateEnum(PostgresEnum, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateCreateEnum(PostgresEnum enumType, IModel? model, MigrationCommandListBuilder builder)

Parameters

enumType PostgresEnum
model IModel
builder MigrationCommandListBuilder

GenerateCreateExtension(PostgresExtension, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateCreateExtension(PostgresExtension extension, IModel? model, MigrationCommandListBuilder builder)

Parameters

extension PostgresExtension
model IModel
builder MigrationCommandListBuilder

GenerateCreateRange(PostgresRange, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateCreateRange(PostgresRange rangeType, IModel? model, MigrationCommandListBuilder builder)

Parameters

rangeType PostgresRange
model IModel
builder MigrationCommandListBuilder

GenerateDropCollation(PostgresCollation, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateDropCollation(PostgresCollation collation, IModel? model, MigrationCommandListBuilder builder)

Parameters

collation PostgresCollation
model IModel
builder MigrationCommandListBuilder

GenerateDropEnum(PostgresEnum, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateDropEnum(PostgresEnum enumType, IModel? model, MigrationCommandListBuilder builder)

Parameters

enumType PostgresEnum
model IModel
builder MigrationCommandListBuilder

GenerateDropRange(PostgresRange, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateDropRange(PostgresRange rangeType, IModel? model, MigrationCommandListBuilder builder)

Parameters

rangeType PostgresRange
model IModel
builder MigrationCommandListBuilder

GenerateEnumStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateEnumStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation AlterDatabaseOperation
model IModel
builder MigrationCommandListBuilder

GenerateRangeStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)

protected virtual void GenerateRangeStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation AlterDatabaseOperation
model IModel
builder MigrationCommandListBuilder

IdentityDefinition(ColumnOperation, MigrationCommandListBuilder)

protected virtual void IdentityDefinition(ColumnOperation operation, MigrationCommandListBuilder builder)

Parameters

operation ColumnOperation
builder MigrationCommandListBuilder

IndexOptions(MigrationOperation, IModel?, MigrationCommandListBuilder)

Generates a SQL fragment for extras (filter, included columns, options) of an index from a CreateIndexOperation.

protected override void IndexOptions(MigrationOperation operation, IModel? model, MigrationCommandListBuilder builder)

Parameters

operation MigrationOperation

The operation.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to add the SQL fragment.

RecreateIndexes(IColumn?, MigrationOperation, MigrationCommandListBuilder)

protected virtual void RecreateIndexes(IColumn? column, MigrationOperation currentOperation, MigrationCommandListBuilder builder)

Parameters

column IColumn
currentOperation MigrationOperation
builder MigrationCommandListBuilder

Rename(string?, string, string, string, MigrationCommandListBuilder)

Renames a database object such as a table, index, or sequence.

public virtual void Rename(string? schema, string name, string newName, string type, MigrationCommandListBuilder builder)

Parameters

schema string

The current schema of the object to rename.

name string

The current name of the object to rename.

newName string

The new name.

type string

The type of the object (e.g. TABLE, INDEX, SEQUENCE).

builder MigrationCommandListBuilder

The builder to which operations are appended.

SequenceOptions(string?, string, SequenceOperation, IModel?, MigrationCommandListBuilder, bool)

Generates a SQL fragment configuring a sequence with the given options.

protected override void SequenceOptions(string? schema, string name, SequenceOperation operation, IModel? model, MigrationCommandListBuilder builder, bool forAlter)

Parameters

schema string

The schema that contains the sequence, or null to use the default schema.

name string

The sequence name.

operation SequenceOperation

The sequence options.

model IModel

The target model which may be null if the operations exist without a model.

builder MigrationCommandListBuilder

The command builder to use to add the SQL fragment.

forAlter bool

If true, then all options are included, even if default.

Transfer(string, string?, string, string, MigrationCommandListBuilder)

Transfers a database object such as a table, index, or sequence between schemas.

public virtual void Transfer(string newSchema, string? schema, string name, string type, MigrationCommandListBuilder builder)

Parameters

newSchema string

The new schema.

schema string

The current schema.

name string

The name of the object to transfer.

type string

The type of the object (e.g. TABLE, INDEX, SEQUENCE).

builder MigrationCommandListBuilder

The builder to which operations are appended.