public static OperationBuilder <NpgsqlEnsurePostgresExtensionOperation> EnsurePostgresExtension( this MigrationBuilder builder, [NotNull] string name, string schema = null, string version = null ) { Check.NotEmpty(name, nameof(name)); Check.NullButNotEmpty(schema, nameof(schema)); Check.NullButNotEmpty(version, nameof(schema)); var operation = new NpgsqlEnsurePostgresExtensionOperation { Name = name, Schema = schema, Version = version }; if (builder.ActiveProvider == NpgsqlProviderName) { builder.Operations.Add(operation); } return(new OperationBuilder <NpgsqlEnsurePostgresExtensionOperation>(operation)); }
public virtual void Generate(NpgsqlEnsurePostgresExtensionOperation operation, [CanBeNull] IModel model, MigrationCommandListBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder .Append("CREATE EXTENSION IF NOT EXISTS ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Name)); if (operation.Schema != null) { builder .Append(" SCHEMA ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Schema)); } if (operation.Version != null) { builder .Append(" VERSION ") .Append(SqlGenerationHelper.DelimitIdentifier(operation.Version)); } builder.AppendLine(SqlGenerationHelper.StatementTerminator); EndStatement(builder, suppressTransaction: true); }
protected virtual void Generate([NotNull] NpgsqlEnsurePostgresExtensionOperation operation, [NotNull] IndentedStringBuilder builder) { Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); builder.Append(".EnsurePostgresExtension("); if (operation.Schema == null && operation.Version == null) { builder.Append(_code.Literal(operation.Name)); } else { using (builder.Indent()) { builder .Append("name: ") .Append(_code.Literal(operation.Name)); if (operation.Schema != null) { builder .AppendLine(",") .Append("schema: ") .Append(_code.Literal(operation.Schema)); } if (operation.Version != null) { builder .AppendLine(",") .Append("version: ") .Append(_code.Literal(operation.Version)); } } } builder.Append(")"); Annotations(operation.GetAnnotations(), builder); }