Skip to content

Commit

Permalink
adapt to api changes in introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
mavilein committed Aug 23, 2019
1 parent 64b9504 commit 5dcbe75
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a> DatabaseSchemaCalculator<'a> {
Index {
name: format!("{}.{}", &model.db_name(), &f.db_name()),
columns: vec![f.name.clone()],
unique: true,
tpe: IndexType::Unique,
}
)
} else {
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<'a> DatabaseSchemaCalculator<'a> {
indices: vec![Index {
name: format!("{}_AB_unique", relation.table_name()),
columns: vec![relation.model_a_column(), relation.model_b_column()],
unique: true,
tpe: IndexType::Unique,
}],
primary_key: None,
foreign_keys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ impl<'a> DatabaseSchemaDiffer<'a> {
if let None = previous_index_opt {
let create = CreateIndex {
table: next_table.name.clone(),
name: index.name.clone(),
tpe: IndexType::Unique,
columns: index.columns.clone(),
index: index.clone(),
};
result.push(create);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ fn fix(_alter_table: &AlterTable, current: &Table, next: &Table, schema_name: &s
result.append(&mut next.indices.iter().map(|index|{
SqlMigrationStep::CreateIndex(CreateIndex {
table: next.name.clone(),
name: index.name.clone(),
columns: index.columns.clone(),
tpe: if index.unique { IndexType::Unique } else { IndexType::Normal }
index: index.clone(),
})
}).collect());
// todo: recreate triggers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,9 @@ fn render_raw_sql(step: &SqlMigrationStep, sql_family: SqlFamily, schema_name: &
}
SqlMigrationStep::CreateIndex(CreateIndex {
table,
name,
tpe,
columns,
index,
}) => {
let Index { name, columns, tpe } = index;
let index_type = match tpe {
IndexType::Unique => "UNIQUE",
IndexType::Normal => "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,11 @@ pub struct AlterColumn {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct CreateIndex {
pub table: String,
pub name: String,
pub tpe: IndexType,
pub columns: Vec<String>,
pub index: Index
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct DropIndex {
pub table: String,
pub name: String,
}

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum IndexType {
// can later add fulltext or custom ones
Unique,
Normal,
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn creating_a_field_for_an_existing_column_and_changing_its_type_must_work() {
.iter()
.find(|i| i.columns == vec!["title"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);
});
}

Expand Down Expand Up @@ -267,7 +267,7 @@ fn updating_a_field_for_a_non_existent_column() {
.iter()
.find(|i| i.columns == vec!["title"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);
});
}

Expand Down
12 changes: 6 additions & 6 deletions server/prisma-rs/migration-engine/core/tests/migrations_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ fn adding_a_new_unique_field_must_work() {
.iter()
.find(|i| i.columns == vec!["field"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);
});
}

Expand All @@ -700,7 +700,7 @@ fn sqlite_must_recreate_indexes() {
.iter()
.find(|i| i.columns == vec!["field"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);

let dm2 = r#"
model A {
Expand All @@ -716,7 +716,7 @@ fn sqlite_must_recreate_indexes() {
.iter()
.find(|i| i.columns == vec!["field"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);
});
}

Expand All @@ -737,7 +737,7 @@ fn removing_an_existing_unique_field_must_work() {
.iter()
.find(|i| i.columns == vec!["field"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);

let dm2 = r#"
model A {
Expand Down Expand Up @@ -784,7 +784,7 @@ fn adding_unique_to_an_existing_field_must_work() {
.iter()
.find(|i| i.columns == vec!["field"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);
});
}

Expand All @@ -805,7 +805,7 @@ fn removing_unique_from_an_existing_field_must_work() {
.iter()
.find(|i| i.columns == vec!["field"]);
assert_eq!(index.is_some(), true);
assert_eq!(index.unwrap().unique, true);
assert_eq!(index.unwrap().tpe, IndexType::Unique);

let dm2 = r#"
model A {
Expand Down

0 comments on commit 5dcbe75

Please sign in to comment.