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

database-introspection: support hyphenated names #4840

Merged
merged 3 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
database-introspection: Support hyphenated names
  • Loading branch information
aknuds1 committed Aug 22, 2019
commit 081d4f1cb8f09de19dde2c4cf4071002cdce94ef
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 @@ -1395,6 +1395,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 @@ -2016,9 +2046,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