public virtual void Generate(NpgsqlCreatePostgresExtensionOperation 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);
        }
        public static OperationBuilder <NpgsqlCreatePostgresExtensionOperation> CreatePostgresExtension(
            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 NpgsqlCreatePostgresExtensionOperation
            {
                Name    = name,
                Schema  = schema,
                Version = version
            };

            if (builder.ActiveProvider == NpgsqlProviderName)
            {
                builder.Operations.Add(operation);
            }

            return(new OperationBuilder <NpgsqlCreatePostgresExtensionOperation>(operation));
        }
Example #3
0
        public void CreatePostgresExtension()
        {
            var op = new NpgsqlCreatePostgresExtensionOperation {
                Name = "hstore",
            };

            Generate(op);

            Assert.Equal(
                @"CREATE EXTENSION ""hstore"";" + EOL,
                Sql);
        }
        protected virtual void Generate([NotNull] NpgsqlCreatePostgresExtensionOperation operation, [NotNull] IndentedStringBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder.Append(".CreatePostgresExtension(");

            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);
        }
Example #5
0
        public virtual void Generate(NpgsqlCreatePostgresExtensionOperation operation, IModel model, RelationalCommandListBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append("CREATE EXTENSION ")
            .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));
            }
        }