mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-31 04:10:38 +00:00
fix: can't adding new columns as primary key (#2310)
This commit is contained in:
committed by
Ruihang Xia
parent
38697e0c4d
commit
b1599ad3a5
@@ -270,6 +270,17 @@ fn parse_column_default_constraint(
|
||||
}
|
||||
}
|
||||
|
||||
/// Return true when the `ColumnDef` options contain primary key
|
||||
pub fn has_primary_key_option(column_def: &ColumnDef) -> bool {
|
||||
column_def
|
||||
.options
|
||||
.iter()
|
||||
.any(|options| match options.option {
|
||||
ColumnOption::Unique { is_primary } => is_primary,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
// TODO(yingwen): Make column nullable by default, and checks invalid case like
|
||||
// a column is not nullable but has a default value null.
|
||||
/// Create a `ColumnSchema` from `ColumnDef`.
|
||||
@@ -748,6 +759,28 @@ mod tests {
|
||||
assert!(!grpc_column_def.is_nullable);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_has_primary_key_option() {
|
||||
let column_def = ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double,
|
||||
collation: None,
|
||||
options: vec![],
|
||||
};
|
||||
assert!(!has_primary_key_option(&column_def));
|
||||
|
||||
let column_def = ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double,
|
||||
collation: None,
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Unique { is_primary: true },
|
||||
}],
|
||||
};
|
||||
assert!(has_primary_key_option(&column_def));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_column_def_to_schema() {
|
||||
let column_def = ColumnDef {
|
||||
|
||||
Reference in New Issue
Block a user