Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dm_from_con() can use multiple schemata #1449

Merged
merged 6 commits into from Sep 20, 2022

Conversation

mgirlich
Copy link
Contributor

@mgirlich mgirlich commented Sep 2, 2022

Fixes #1441.

@@ -241,7 +245,7 @@ filter_dm_meta <- function(dm_meta, catalog = NULL, schema = NULL) {
constraint_column_usage <- constraint_column_usage %>% filter(table_catalog %in% !!catalog)
}

if (!is.null(schema) && !is.na(schema)) {
if (!is.null(schema) && isTRUE(!is.na(schema))) {
schemata <- schemata %>% filter(schema_name %in% !!schema)
tables <- tables %>% filter(table_schema %in% !!schema)
columns <- columns %>% filter(table_schema %in% !!schema)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition below

} else if (!isTRUE(is.na(schema)) && is_mariadb(dm_get_con(dm_meta))) {

is in my opinion confusing. I think the idea is to use a default for MariaDB if schema is NULL. If so, this should use is.null(schema). Also, it might be better to implement these defaults differently. There is a function schema_mariadb() which seems to implement this default. But it always uses database() and here the default handling is different in case database() is NULL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC DATABASE() can be NULL in MariaDB/MySQL if connecting without a default database, and this could be the reason for this ... hack?

Copy link
Collaborator

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Should we document this explicitly?

R/meta.R Outdated Show resolved Hide resolved
Comment on lines +488 to +490
expect_snapshot_output(my_dm <- dm_from_con(my_db, schema = c("Accidents", "Ad")))
expect_snapshot(dm::dm_get_all_fks(my_dm))
expect_snapshot(dm::dm_get_all_pks(my_dm))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test output looks odd, perhaps because the connection uses dbname = "Financial_ijs" ?

I wonder what's a good test design on Postgres and MSSQL for this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simply setup our own DB.

R/meta.R Outdated Show resolved Hide resolved
@krlmlr krlmlr changed the title Can use multiple schemata in dm_from_con() feat: dm_from_con() can use multiple schemata Sep 20, 2022
@krlmlr krlmlr merged commit 04c184c into cynkra:main Sep 20, 2022
@krlmlr
Copy link
Collaborator

krlmlr commented Sep 20, 2022

Thanks!

@mgirlich mgirlich deleted the dm-from-con-multiple-schema branch July 12, 2023 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

dm_from_con() should accept multiple schemas
2 participants