Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

database-introspection: Change index field 'unique' to enum named 'tpe' #4843

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions server/prisma-rs/libs/database-introspection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ pub struct Table {
pub foreign_keys: Vec<ForeignKey>,
}

/// The type of an index.
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum IndexType {
Unique,
Normal,
}

/// An index of a table.
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -82,8 +90,8 @@ pub struct Index {
pub name: String,
/// Index columns.
pub columns: Vec<String>,
/// Is index unique?
pub unique: bool,
/// Type of index.
pub tpe: IndexType,
}

/// The primary key of a table.
Expand Down
5 changes: 4 additions & 1 deletion server/prisma-rs/libs/database-introspection/src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ impl IntrospectionConnector {
Some(Index {
name: index_name,
columns: vec![column_name],
unique: is_unique,
tpe: match is_unique {
true => IndexType::Unique,
false => IndexType::Normal,
},
})
}
})
Expand Down
6 changes: 5 additions & 1 deletion server/prisma-rs/libs/database-introspection/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,14 @@ impl IntrospectionConnector {
pk = Some(PrimaryKey { columns });
None
} else {
let is_unique = index.get("is_unique").and_then(|x| x.as_bool()).expect("is_unique");
Some(Index {
name: index.get("name").and_then(|x| x.to_string()).expect("name"),
columns,
unique: index.get("is_unique").and_then(|x| x.as_bool()).expect("is_unique"),
tpe: match is_unique {
true => IndexType::Unique,
false => IndexType::Normal,
},
})
}
})
Expand Down
5 changes: 4 additions & 1 deletion server/prisma-rs/libs/database-introspection/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ impl IntrospectionConnector {
.map(|index_repr| {
let mut index = Index {
name: index_repr.name.clone(),
unique: index_repr.is_unique,
tpe: match index_repr.is_unique {
true => IndexType::Unique,
false => IndexType::Normal,
},
columns: vec![],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1408,18 +1408,16 @@ fn names_with_hyphens_must_work() {
|db_type, inspector| {
let result = inspector.introspect(SCHEMA).expect("introspecting");
let user_table = result.get_table("User-table").expect("getting User table");
let expected_columns = vec![
Column {
name: "column-1".to_string(),
tpe: ColumnType {
raw: int_type(db_type),
family: ColumnTypeFamily::Int,
},
arity: ColumnArity::Required,
default: None,
auto_increment: false,
let expected_columns = vec![Column {
name: "column-1".to_string(),
tpe: ColumnType {
raw: int_type(db_type),
family: ColumnTypeFamily::Int,
},
];
arity: ColumnArity::Required,
default: None,
auto_increment: false,
}];
assert_eq!(user_table.columns, expected_columns);
},
);
Expand Down Expand Up @@ -1888,7 +1886,7 @@ fn indices_must_work() {
indices: vec![Index {
name: "count".to_string(),
columns: vec!["count".to_string()],
unique: false,
tpe: IndexType::Normal,
},],
primary_key: Some(PrimaryKey {
columns: vec!["id".to_string()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"columns": [
"column2"
],
"unique": false
"tpe": "normal"
}
],
"primaryKey": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn database_schema_is_serializable() {
indices: vec![Index {
name: "column2".to_string(),
columns: vec!["column2".to_string()],
unique: false,
tpe: IndexType::Normal,
}],
primary_key: Some(PrimaryKey {
columns: vec!["column1".to_string()],
Expand Down