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

Commit

Permalink
database-introspection: Support hyphenated names
Browse files Browse the repository at this point in the history
  • Loading branch information
aknuds1 committed Aug 22, 2019
1 parent c01f5a4 commit ae89aac
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
8 changes: 4 additions & 4 deletions server/prisma-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/prisma-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ members = [
]

[patch.crates-io]
barrel = { git = "https://github.com/aknuds1/barrel.git", branch = "bugfix/fix-index-creation" }
barrel = { git = "https://github.com/aknuds1/barrel.git", branch = "master" }
2 changes: 1 addition & 1 deletion server/prisma-rs/libs/database-introspection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
rusqlite = { version = "0.19", features = ["chrono", "bundled"] }
prisma-query = { git = "https://github.com/prisma/prisma-query.git" }
barrel = { version = "0.6.3-alpha.0", features = ["sqlite3", "mysql", "pg"] }
itertools = "0.8"
url = "1.7.2"
postgres = { version = "0.16.0-rc.2", features = ["runtime", "with-serde_json-1", "with-chrono-0_4", "with-uuid-0_7"] }
Expand All @@ -20,5 +19,6 @@ mysql = { version = "16", features = ["ssl"] }
regex = "1.2"

[dev-dependencies]
barrel = { version = "0.6.3-alpha.0", features = ["sqlite3", "mysql", "pg"] }
fern = "0.5"
pretty_assertions = "0.6"
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,36 @@ fn multi_column_foreign_keys_must_work() {
);
}

#[test]
fn names_with_hyphens_must_work() {
setup();

test_each_backend(
|_, migration| {
migration.create_table("User-table", |t| {
t.add_column("column-1", types::integer().nullable(false));
});
},
|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,
},
];
assert_eq!(user_table.columns, expected_columns);
},
);
}

#[test]
fn postgres_foreign_key_on_delete_must_be_handled() {
setup();
Expand Down Expand Up @@ -1767,9 +1797,9 @@ fn get_mysql_connector(sql: &str) -> mysql::IntrospectionConnector {
.pass(Some(password));
let mut conn = prisma_query::connector::Mysql::new(opts_builder).expect("connect to MySQL");

conn.execute_raw(&format!("DROP SCHEMA IF EXISTS {}", SCHEMA), &[])
conn.execute_raw(&format!("DROP SCHEMA IF EXISTS `{}`", SCHEMA), &[])
.expect("dropping schema");
conn.execute_raw(&format!("CREATE SCHEMA {}", SCHEMA), &[])
conn.execute_raw(&format!("CREATE SCHEMA `{}`", SCHEMA), &[])
.expect("creating schema");

debug!("Executing MySQL migrations: {}", sql);
Expand Down

0 comments on commit ae89aac

Please sign in to comment.