Moved constraint variant outside of TableConstraint enum (#2054)

Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
Luca Cappelletti 2025-10-08 13:03:26 +02:00 committed by GitHub
parent ade4082656
commit 8c82fc0a19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 688 additions and 484 deletions

View file

@ -607,9 +607,10 @@ fn parse_alter_table_constraints_unique_nulls_distinct() {
{
Statement::AlterTable { operations, .. } => match &operations[0] {
AlterTableOperation::AddConstraint {
constraint: TableConstraint::Unique { nulls_distinct, .. },
constraint: TableConstraint::Unique(constraint),
..
} => {
let nulls_distinct = &constraint.nulls_distinct;
assert_eq!(nulls_distinct, &NullsDistinctOption::NotDistinct)
}
_ => unreachable!(),
@ -5578,7 +5579,7 @@ fn parse_create_domain() {
data_type: DataType::Integer(None),
collation: None,
default: None,
constraints: vec![TableConstraint::Check {
constraints: vec![CheckConstraint {
name: None,
expr: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Identifier(Ident::new("VALUE"))),
@ -5586,7 +5587,8 @@ fn parse_create_domain() {
right: Box::new(Expr::Value(test_utils::number("0").into())),
}),
enforced: None,
}],
}
.into()],
});
assert_eq!(pg().verified_stmt(sql1), expected);
@ -5597,7 +5599,7 @@ fn parse_create_domain() {
data_type: DataType::Integer(None),
collation: Some(Ident::with_quote('"', "en_US")),
default: None,
constraints: vec![TableConstraint::Check {
constraints: vec![CheckConstraint {
name: None,
expr: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Identifier(Ident::new("VALUE"))),
@ -5605,7 +5607,8 @@ fn parse_create_domain() {
right: Box::new(Expr::Value(test_utils::number("0").into())),
}),
enforced: None,
}],
}
.into()],
});
assert_eq!(pg().verified_stmt(sql2), expected);
@ -5616,7 +5619,7 @@ fn parse_create_domain() {
data_type: DataType::Integer(None),
collation: None,
default: Some(Expr::Value(test_utils::number("1").into())),
constraints: vec![TableConstraint::Check {
constraints: vec![CheckConstraint {
name: None,
expr: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Identifier(Ident::new("VALUE"))),
@ -5624,7 +5627,8 @@ fn parse_create_domain() {
right: Box::new(Expr::Value(test_utils::number("0").into())),
}),
enforced: None,
}],
}
.into()],
});
assert_eq!(pg().verified_stmt(sql3), expected);
@ -5635,7 +5639,7 @@ fn parse_create_domain() {
data_type: DataType::Integer(None),
collation: Some(Ident::with_quote('"', "en_US")),
default: Some(Expr::Value(test_utils::number("1").into())),
constraints: vec![TableConstraint::Check {
constraints: vec![CheckConstraint {
name: None,
expr: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Identifier(Ident::new("VALUE"))),
@ -5643,7 +5647,8 @@ fn parse_create_domain() {
right: Box::new(Expr::Value(test_utils::number("0").into())),
}),
enforced: None,
}],
}
.into()],
});
assert_eq!(pg().verified_stmt(sql4), expected);
@ -5654,7 +5659,7 @@ fn parse_create_domain() {
data_type: DataType::Integer(None),
collation: None,
default: None,
constraints: vec![TableConstraint::Check {
constraints: vec![CheckConstraint {
name: Some(Ident::new("my_constraint")),
expr: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Identifier(Ident::new("VALUE"))),
@ -5662,7 +5667,8 @@ fn parse_create_domain() {
right: Box::new(Expr::Value(test_utils::number("0").into())),
}),
enforced: None,
}],
}
.into()],
});
assert_eq!(pg().verified_stmt(sql5), expected);
@ -6467,7 +6473,7 @@ fn parse_alter_table_constraint_not_valid() {
assert_eq!(
operations,
vec![AlterTableOperation::AddConstraint {
constraint: TableConstraint::ForeignKey {
constraint: ForeignKeyConstraint {
name: Some("bar".into()),
index_name: None,
columns: vec!["baz".into()],
@ -6476,7 +6482,8 @@ fn parse_alter_table_constraint_not_valid() {
on_delete: None,
on_update: None,
characteristics: None,
},
}
.into(),
not_valid: true,
}]
);