示例#1
0
        public void ShouldAllowChangingConstraintName()
        {
            var op = new AddCheckConstraintOperation("schema", "table", "name", "1", true, true);

            op.Name = "new name";
            Assert.That(op.Name, Is.EqualTo("new name"));
        }
示例#2
0
        public void ShouldDisableWhenMergedWithRemoveCheckConstraint()
        {
            var op       = new AddCheckConstraintOperation("schema", "table", "name", "1", true, true);
            var removeOp = new RemoveCheckConstraintOperation("SCHEMA", "TABLE", "NAME");

            op.Merge(removeOp);
            Assert.That(op.Disabled, Is.True);
            Assert.That(removeOp.Disabled, Is.True);
        }
示例#3
0
        public void ShouldWriteQueryWithDBOSchemaAndWithValuesFalseForAddCheckConstrait()
        {
            var  schemaName        = "schemaName";
            var  tableName         = "tableName";
            var  name              = "constraintName";
            var  expression        = "expression";
            bool notForReplication = false;

            var op = new AddCheckConstraintOperation(schemaName, tableName, name, expression, notForReplication, false);

            Trace.WriteLine(op.ToQuery());
            var expectedQuery = @"alter table [schemaName].[tableName] add constraint [constraintName] check (expression)";

            Assert.AreEqual(expectedQuery, op.ToQuery());
        }
示例#4
0
        public void ShouldWriteQueryForAddCheckConstraint()
        {
            var  schemaName        = "schemaName";
            var  tableName         = "tableName";
            var  name              = "constraintName";
            var  expression        = "expression";
            bool notForReplication = true;
            bool withNoCheck       = true;

            var op = new AddCheckConstraintOperation(schemaName, tableName, name, expression, notForReplication, withNoCheck);

            var expectedQuery = @"alter table [schemaName].[tableName] with nocheck add constraint [constraintName] check not for replication (expression)";

            Assert.AreEqual(expectedQuery, op.ToQuery());
        }
示例#5
0
        /// <summary>
        ///     Configures a check constraint on the table.
        /// </summary>
        /// <param name="name"> The constraint name. </param>
        /// <param name="sql"> The sql expression used in the CHECK constraint. </param>
        /// <returns> The same builder so that multiple calls can be chained. </returns>
        public virtual OperationBuilder <AddCheckConstraintOperation> CheckConstraint(
            string name,
            string sql)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(sql, nameof(sql));

            var operation = new AddCheckConstraintOperation
            {
                Schema = Operation.Schema,
                Table  = Operation.Name,
                Name   = name,
                Sql    = sql
            };

            Operation.CheckConstraints.Add(operation);

            return(new OperationBuilder <AddCheckConstraintOperation>(operation));
        }
示例#6
0
        public void ShouldSetPropertiesForAddDefaultConstraint()
        {
            var  schemaName        = "schemaName";
            var  tableName         = "tableName";
            var  name              = "constraintName";
            var  expression        = "expression";
            bool notForReplication = true;
            bool withNoCheck       = true;

            var op = new AddCheckConstraintOperation(schemaName, tableName, name, expression, notForReplication, withNoCheck);

            Assert.AreEqual(schemaName, op.SchemaName);
            Assert.AreEqual(tableName, op.TableName);
            Assert.AreEqual(name, op.Name);
            Assert.AreEqual(expression, op.Expression);
            Assert.AreEqual(notForReplication, op.NotForReplication);
            Assert.AreEqual(withNoCheck, op.WithNoCheck);
            Assert.That(op.ObjectName, Is.EqualTo($"{schemaName}.{name}"));
            Assert.That(op.TableObjectName, Is.EqualTo($"{schemaName}.{tableName}"));
            Assert.That(op.ConstraintType, Is.EqualTo(ConstraintType.Check));
        }
示例#7
0
 /// <summary>
 ///     Throws <see cref="NotSupportedException" /> since this operation requires table rebuilds, which
 ///     are not yet supported.
 /// </summary>
 /// <param name="operation"> The operation. </param>
 /// <param name="model"> The target model which may be <see langword="null" /> if the operations exist without a model. </param>
 /// <param name="builder"> The command builder to use to build the commands. </param>
 protected override void Generate(AddCheckConstraintOperation operation, IModel model, MigrationCommandListBuilder builder)
 => throw new NotSupportedException(
           SqliteStrings.InvalidMigrationOperation(operation.GetType().ShortDisplayName()));