protected virtual void SequenceOptions(
            [CanBeNull] string schema,
            [NotNull] string name,
            [NotNull] int increment,
            long?minimumValue,
            long?maximumValue,
            [NotNull] bool cycle,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(increment, nameof(increment));
            Check.NotNull(cycle, nameof(cycle));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append(" INCREMENT BY ")
            .Append(Sql.GenerateLiteral(increment));

            if (minimumValue != null)
            {
                builder
                .Append(" MINVALUE ")
                .Append(Sql.GenerateLiteral(minimumValue));
            }
            else
            {
                builder.Append(" NO MINVALUE");
            }

            if (maximumValue != null)
            {
                builder
                .Append(" MAXVALUE ")
                .Append(Sql.GenerateLiteral(maximumValue));
            }
            else
            {
                builder.Append(" NO MAXVALUE");
            }

            builder.Append(cycle ? " CYCLE" : " NO CYCLE");
        }
        public override void ForeignKeyAction(ReferentialAction referentialAction, SqlBatchBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            if (referentialAction == ReferentialAction.Restrict)
            {
                builder.Append("NO ACTION");
            }
            else
            {
                base.ForeignKeyAction(referentialAction, builder);
            }
        }
        public override void IndexTraits(MigrationOperation operation, IModel model, SqlBatchBuilder builder)
        {
            Check.NotNull(operation, nameof(operation));
            Check.NotNull(builder, nameof(builder));

            var clustered = (string)operation[SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.Clustered];
            if (clustered != null)
            {
                builder.Append(clustered == "True" ? "CLUSTERED " : "NONCLUSTERED ");
            }
        }
        public override void ColumnDefinition(
            string schema,
            string table,
            string name,
            string type,
            bool nullable,
            object defaultValue,
            string defaultExpression,
            IAnnotatable annotatable,
            IModel model,
            SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(type, nameof(type));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            var computedExpression = annotatable[SqlServerAnnotationNames.Prefix
                + SqlServerAnnotationNames.ColumnComputedExpression];
            if (computedExpression != null)
            {
                builder
                    .Append(_sql.DelimitIdentifier(name))
                    .Append(" AS ")
                    .Append(computedExpression);

                return;
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                type,
                nullable,
                defaultValue,
                defaultExpression,
                annotatable,
                model,
                builder);

            var valueGeneration = (string)annotatable[SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.ValueGeneration];
            if (valueGeneration == "Identity")
            {
                builder.Append(" IDENTITY");
            }
        }
Beispiel #5
0
        public override void ColumnDefinition(
            string schema,
            string table,
            string name,
            string type,
            bool nullable,
            object defaultValue,
            string defaultExpression,
            IAnnotatable annotatable,
            IModel model,
            SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(type, nameof(type));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            var computedExpression = annotatable[NpgsqlAnnotationNames.Prefix
                                                 + NpgsqlAnnotationNames.ColumnComputedExpression];

            if (computedExpression != null)
            {
                builder
                .Append(_sql.DelimitIdentifier(name))
                .Append(" AS ")
                .Append(computedExpression);

                return;
            }


            var valueGeneration = (string)annotatable[NpgsqlAnnotationNames.Prefix + NpgsqlAnnotationNames.ValueGeneration];

            if (valueGeneration == "Identity")
            {
                switch (type)
                {
                case "int":
                    type = "serial";
                    break;

                case "bigint":
                    type = "bigserial";
                    break;

                case "smallint":
                    type = "smallint";
                    break;

                default:
                    throw new InvalidOperationException($"Column {name} of type {type} can't be Identity");
                }
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                type,
                nullable,
                defaultValue,
                defaultExpression,
                annotatable,
                model,
                builder);
        }