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
dependenciesMigrationsSqlGeneratorDependenciesParameter object containing dependencies for this service.
npgsqlSingletonOptionsINpgsqlSingletonOptionsThe 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
columnColumnOperationmodelIModelnamestringschemastringtablestring
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
schemastringThe schema that contains the table, or null to use the default schema.
tablestringThe table that contains the column.
namestringThe column name.
operationColumnOperationThe column metadata.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
schemastringThe schema that contains the table, or
nullto use the default schema.tablestringThe table that contains the column.
namestringThe column name.
operationColumnOperationThe column metadata.
modelIModelThe target model which may be
nullif the operations exist without a model.builderMigrationCommandListBuilderThe 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
defaultValueobjectThe default value for the column.
defaultValueSqlstringThe SQL expression to use for the column's default constraint.
columnTypestringStore/database type of the column.
builderMigrationCommandListBuilderThe 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
operationAddColumnOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe command builder to use to build the commands.
terminateboolIndicates 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
operationAlterColumnOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationAlterDatabaseOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationAlterTableOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationCreateIndexOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe command builder to use to build the commands.
terminateboolIndicates 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
operationCreateSequenceOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationCreateTableOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe command builder to use to build the commands.
terminateboolIndicates 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
operationDropColumnOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe command builder to use to build the commands.
terminateboolIndicates 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
operationDropIndexOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe command builder to use to build the commands.
terminateboolIndicates 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
operationEnsureSchemaOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationInsertDataOperationThe operation.
modelIModelThe target model which may be
nullif the operations exist without a model.builderMigrationCommandListBuilderThe command builder to use to build the commands.
terminateboolIndicates 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
operationMigrationOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationRenameColumnOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationRenameIndexOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationRenameSequenceOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationRenameTableOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe 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
operationRestartSequenceOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe command builder to use to build the commands.
Generate(NpgsqlCreateDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void Generate(NpgsqlCreateDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operationNpgsqlCreateDatabaseOperationmodelIModelbuilderMigrationCommandListBuilder
Generate(NpgsqlDropDatabaseOperation, IModel?, MigrationCommandListBuilder)
public virtual void Generate(NpgsqlDropDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operationNpgsqlDropDatabaseOperationmodelIModelbuilderMigrationCommandListBuilder
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
operationsIReadOnlyList<MigrationOperation>The operations.
modelIModelThe target model which may be null if the operations exist without a model.
optionsMigrationsSqlGenerationOptionsThe options to use when generating commands.
Returns
- IReadOnlyList<MigrationCommand>
The list of commands to be executed or scripted.
GenerateAddEnumLabel(PostgresEnum, string, string?, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateAddEnumLabel(PostgresEnum enumType, string addedLabel, string? beforeLabel, IModel? model, MigrationCommandListBuilder builder)
Parameters
enumTypePostgresEnumaddedLabelstringbeforeLabelstringmodelIModelbuilderMigrationCommandListBuilder
GenerateCollationStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCollationStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operationAlterDatabaseOperationmodelIModelbuilderMigrationCommandListBuilder
GenerateCreateCollation(PostgresCollation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateCollation(PostgresCollation collation, IModel? model, MigrationCommandListBuilder builder)
Parameters
collationPostgresCollationmodelIModelbuilderMigrationCommandListBuilder
GenerateCreateEnum(PostgresEnum, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateEnum(PostgresEnum enumType, IModel? model, MigrationCommandListBuilder builder)
Parameters
enumTypePostgresEnummodelIModelbuilderMigrationCommandListBuilder
GenerateCreateExtension(PostgresExtension, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateExtension(PostgresExtension extension, IModel? model, MigrationCommandListBuilder builder)
Parameters
extensionPostgresExtensionmodelIModelbuilderMigrationCommandListBuilder
GenerateCreateRange(PostgresRange, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateCreateRange(PostgresRange rangeType, IModel? model, MigrationCommandListBuilder builder)
Parameters
rangeTypePostgresRangemodelIModelbuilderMigrationCommandListBuilder
GenerateDropCollation(PostgresCollation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateDropCollation(PostgresCollation collation, IModel? model, MigrationCommandListBuilder builder)
Parameters
collationPostgresCollationmodelIModelbuilderMigrationCommandListBuilder
GenerateDropEnum(PostgresEnum, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateDropEnum(PostgresEnum enumType, IModel? model, MigrationCommandListBuilder builder)
Parameters
enumTypePostgresEnummodelIModelbuilderMigrationCommandListBuilder
GenerateDropRange(PostgresRange, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateDropRange(PostgresRange rangeType, IModel? model, MigrationCommandListBuilder builder)
Parameters
rangeTypePostgresRangemodelIModelbuilderMigrationCommandListBuilder
GenerateEnumStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateEnumStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operationAlterDatabaseOperationmodelIModelbuilderMigrationCommandListBuilder
GenerateRangeStatements(AlterDatabaseOperation, IModel?, MigrationCommandListBuilder)
protected virtual void GenerateRangeStatements(AlterDatabaseOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operationAlterDatabaseOperationmodelIModelbuilderMigrationCommandListBuilder
IdentityDefinition(ColumnOperation, MigrationCommandListBuilder)
protected virtual void IdentityDefinition(ColumnOperation operation, MigrationCommandListBuilder builder)
Parameters
operationColumnOperationbuilderMigrationCommandListBuilder
IndexOptions(CreateIndexOperation, IModel?, MigrationCommandListBuilder)
Generates a SQL fragment for extras (filter, included columns, options) of an index from a CreateIndexOperation.
protected override void IndexOptions(CreateIndexOperation operation, IModel? model, MigrationCommandListBuilder builder)
Parameters
operationCreateIndexOperationThe operation.
modelIModelThe target model which may be null if the operations exist without a model.
builderMigrationCommandListBuilderThe command builder to use to add the SQL fragment.
RecreateIndexes(IColumn?, MigrationOperation, MigrationCommandListBuilder)
protected virtual void RecreateIndexes(IColumn? column, MigrationOperation currentOperation, MigrationCommandListBuilder builder)
Parameters
columnIColumncurrentOperationMigrationOperationbuilderMigrationCommandListBuilder
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
schemastringThe current schema of the object to rename.
namestringThe current name of the object to rename.
newNamestringThe new name.
typestringThe type of the object (e.g. TABLE, INDEX, SEQUENCE).
builderMigrationCommandListBuilderThe builder to which operations are appended.
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
newSchemastringThe new schema.
schemastringThe current schema.
namestringThe name of the object to transfer.
typestringThe type of the object (e.g. TABLE, INDEX, SEQUENCE).
builderMigrationCommandListBuilderThe builder to which operations are appended.