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
fix: re-introspection with @@map
and relationMode
#3335
Conversation
…ionMode/referentialIntegrity and with/without '@@Map'
Note: |
introspection-engine/introspection-engine-tests/tests/re_introspection/relation_mode/sqlite.rs
Outdated
Show resolved
Hide resolved
let old_model_name_to_final_database_name: HashMap<String, String> = old_data_model | ||
.models() | ||
.map(|m| (m.name.clone(), String::from(m.final_database_name()))) | ||
.collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestion on how to avoid these clones while still being able to use the function in the following closures is well accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry about it here, but you can change line 147 to .map(|m| (m.name.as_str(), m.final_database_name()))
and the type ascription to HashMap<&str, &str>
. To optimize further, you could make the HashMap potentially a lot smaller if you .filter()
for only the models with a mapped name first — then a model missing in the map would mean the model is not remapped, which would be handled with the existing code lower down.
But we shouldn't worry too much here, we're in the process of rewriting this file and the string comparisons will go away, we'll have a big map of integer identifiers for these lookups, since they happen repeatedly during introspection and reintrospection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I have simply got rid of .clone()
in favor of .as_str()
. I will skip other optimizations for now, as we expect this file to change significantly already
Yes it's probably a whitespace issue — I've never encountered it though so I'm a bit puzzled. Maybe it's due to the extra indentation from the inline modules ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should fix it 👍
let old_model_name_to_final_database_name: HashMap<String, String> = old_data_model | ||
.models() | ||
.map(|m| (m.name.clone(), String::from(m.final_database_name()))) | ||
.collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't worry about it here, but you can change line 147 to .map(|m| (m.name.as_str(), m.final_database_name()))
and the type ascription to HashMap<&str, &str>
. To optimize further, you could make the HashMap potentially a lot smaller if you .filter()
for only the models with a mapped name first — then a model missing in the map would mean the model is not remapped, which would be handled with the existing code lower down.
But we shouldn't worry too much here, we're in the process of rewriting this file and the string comparisons will go away, we'll have a big map of integer identifiers for these lookups, since they happen repeatedly during introspection and reintrospection.
introspection-engine/introspection-engine-tests/tests/re_introspection/relation_mode/mssql.rs
Outdated
Show resolved
Hide resolved
Ok(()) | ||
} | ||
|
||
// referentialIntegrity = "foreignKeys" with @@map loses track of the relation policy ("foreignKeys"), but preserves @relations, which are moved to the bottom. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether we should be testing relationIntegrity = "foreignKeys"
more than once, since that's the default everywhere. Let's keep these tests since they're already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you mean, "more than once"? I'm not sure I'm following
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once would be on just sqlite, or just postgres, for example
Currently, re-introspection with
relationMode = "prisma"
orreferentialIntegrity = "prisma"
loses track of@relation
s in the schema. This PR fixes that.Fixes prisma/prisma#11022.