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
-
MigrationsSqlGenerator.SequenceOptions(CreateSequenceOperation, IModel, MigrationCommandListBuilder)
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
MigrationsSqlGeneratorDependenciesParameter object containing dependencies for this service.
npgsqlSingletonOptions
INpgsqlSingletonOptionsThe 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
ColumnOperationmodel
IModelname
stringschema
stringtable
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
stringThe schema that contains the table, or null to use the default schema.
table
stringThe table that contains the column.
name
stringThe column name.
operation
ColumnOperationThe column metadata.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
stringThe schema that contains the table, or
null
to use the default schema.table
stringThe table that contains the column.
name
stringThe column name.
operation
ColumnOperationThe column metadata.
model
IModelThe target model which may be
null
if the operations exist without a model.builder
MigrationCommandListBuilderThe 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
objectThe default value for the column.
defaultValueSql
stringThe SQL expression to use for the column's default constraint.
columnType
stringStore/database type of the column.
builder
MigrationCommandListBuilderThe 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
AddColumnOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe command builder to use to build the commands.
terminate
boolIndicates 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
AlterColumnOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
AlterDatabaseOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
AlterTableOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
CreateIndexOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe command builder to use to build the commands.
terminate
boolIndicates 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
CreateSequenceOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
CreateTableOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe command builder to use to build the commands.
terminate
boolIndicates 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
DropColumnOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe command builder to use to build the commands.
terminate
boolIndicates 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
DropIndexOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe command builder to use to build the commands.
terminate
boolIndicates 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
EnsureSchemaOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
InsertDataOperationThe operation.
model
IModelThe target model which may be
null
if the operations exist without a model.builder
MigrationCommandListBuilderThe command builder to use to build the commands.
terminate
boolIndicates 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
MigrationOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
RenameColumnOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
RenameIndexOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
RenameSequenceOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
RenameTableOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
RestartSequenceOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe command builder to use to build the commands.
Generate(NpgsqlCreateDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void Generate(NpgsqlCreateDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operation
NpgsqlCreateDatabaseOperationmodel
IModelbuilder
MigrationCommandListBuilder
Generate(NpgsqlDropDatabaseOperation, IModel?, MigrationCommandListBuilder)
public virtual void Generate(NpgsqlDropDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operation
NpgsqlDropDatabaseOperationmodel
IModelbuilder
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
IModelThe target model which may be null if the operations exist without a model.
options
MigrationsSqlGenerationOptionsThe 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
PostgresEnumaddedLabel
stringbeforeLabel
stringafterLabel
stringmodel
IModelbuilder
MigrationCommandListBuilder
GenerateCollationStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCollationStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operation
AlterDatabaseOperationmodel
IModelbuilder
MigrationCommandListBuilder
GenerateCreateCollation(PostgresCollation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateCollation(PostgresCollation collation, IModel? model, MigrationCommandListBuilder builder)
Parameters
collation
PostgresCollationmodel
IModelbuilder
MigrationCommandListBuilder
GenerateCreateEnum(PostgresEnum, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateEnum(PostgresEnum enumType, IModel? model, MigrationCommandListBuilder builder)
Parameters
enumType
PostgresEnummodel
IModelbuilder
MigrationCommandListBuilder
GenerateCreateExtension(PostgresExtension, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateExtension(PostgresExtension extension, IModel? model, MigrationCommandListBuilder builder)
Parameters
extension
PostgresExtensionmodel
IModelbuilder
MigrationCommandListBuilder
GenerateCreateRange(PostgresRange, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateRange(PostgresRange rangeType, IModel? model, MigrationCommandListBuilder builder)
Parameters
rangeType
PostgresRangemodel
IModelbuilder
MigrationCommandListBuilder
GenerateDropCollation(PostgresCollation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateDropCollation(PostgresCollation collation, IModel? model, MigrationCommandListBuilder builder)
Parameters
collation
PostgresCollationmodel
IModelbuilder
MigrationCommandListBuilder
GenerateDropEnum(PostgresEnum, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateDropEnum(PostgresEnum enumType, IModel? model, MigrationCommandListBuilder builder)
Parameters
enumType
PostgresEnummodel
IModelbuilder
MigrationCommandListBuilder
GenerateDropRange(PostgresRange, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateDropRange(PostgresRange rangeType, IModel? model, MigrationCommandListBuilder builder)
Parameters
rangeType
PostgresRangemodel
IModelbuilder
MigrationCommandListBuilder
GenerateEnumStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateEnumStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operation
AlterDatabaseOperationmodel
IModelbuilder
MigrationCommandListBuilder
GenerateRangeStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateRangeStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operation
AlterDatabaseOperationmodel
IModelbuilder
MigrationCommandListBuilder
IdentityDefinition(ColumnOperation, MigrationCommandListBuilder)
protected virtual void IdentityDefinition(ColumnOperation operation, MigrationCommandListBuilder builder)
Parameters
operation
ColumnOperationbuilder
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
MigrationOperationThe operation.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe 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
IColumncurrentOperation
MigrationOperationbuilder
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
stringThe current schema of the object to rename.
name
stringThe current name of the object to rename.
newName
stringThe new name.
type
stringThe type of the object (e.g. TABLE, INDEX, SEQUENCE).
builder
MigrationCommandListBuilderThe 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
stringThe schema that contains the sequence, or null to use the default schema.
name
stringThe sequence name.
operation
SequenceOperationThe sequence options.
model
IModelThe target model which may be null if the operations exist without a model.
builder
MigrationCommandListBuilderThe command builder to use to add the SQL fragment.
forAlter
boolIf 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
stringThe new schema.
schema
stringThe current schema.
name
stringThe name of the object to transfer.
type
stringThe type of the object (e.g. TABLE, INDEX, SEQUENCE).
builder
MigrationCommandListBuilderThe builder to which operations are appended.