Skip to content

Commit ed5fe70

Browse files
committed
fix: cleanups and comments
1 parent 4b84927 commit ed5fe70

6 files changed

Lines changed: 14 additions & 25 deletions

File tree

schema-engine/commands/src/commands/create_migration.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ pub async fn create_migration(
3131
let previous_migrations = list_migrations(input.migrations_list.migration_directories.clone());
3232
let sources: Vec<_> = input.schema.to_psl_input();
3333
let dialect = connector.schema_dialect();
34-
34+
// We need to start with the 'to', which is the Schema, in order to grab the
35+
// namespaces, in case we've got MultiSchema enabled.
3536
let to = dialect.schema_from_datamodel(sources.clone())?;
3637

3738
let from = migration_schema_cache
3839
.get_or_insert(&input.migrations_list.migration_directories, || async {
3940
let namespaces = dialect.extract_namespaces(&to);
40-
// TODO(MultiSchema): we may need to do something similar to
41-
// namespaces_and_preview_features_from_diff_targets here as well,
42-
// particularly if it's not correctly setting the preview features flags.
41+
// We pass the namespaces here, because we want to describe all of these namespaces.
4342
connector.schema_from_migrations(&previous_migrations, namespaces).await
4443
})
4544
.await?;

schema-engine/commands/src/commands/diagnose_migration_history.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ pub async fn diagnose_migration_history(
147147
.await
148148
})
149149
.await;
150-
151150
let to = connector.schema_from_database(namespaces.clone()).await;
152151
let drift = match from.and_then(|from| to.map(|to| dialect.diff(from, to))).map(|mig| {
153152
if dialect.migration_is_empty(&mig) {

schema-engine/commands/src/migration_schema_cache.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::hash::{Hash, Hasher};
44

55
use schema_connector::DatabaseSchema;
66

7-
/// A cache for migrations to avoid redundant work during `prisma migrate dev`.
7+
/// A cache for DatabaseSchemas based on the migration directories to avoid redundant work during `prisma migrate dev`.
88
pub struct MigrationSchemaCache {
99
migrations: HashMap<String, DatabaseSchema>,
1010
}
@@ -17,7 +17,7 @@ impl MigrationSchemaCache {
1717
}
1818
}
1919

20-
/// Gets a migration from the cache, or computes it using the provided async closure if not found.
20+
/// Gets a DatabaseSchema from the cache, or calls the provided async closure if not found and stores its result in the cache.
2121
pub async fn get_or_insert<F, Fut, E, T>(
2222
&mut self,
2323
migration_directories: &Vec<T>,
@@ -28,25 +28,16 @@ impl MigrationSchemaCache {
2828
Fut: std::future::Future<Output = Result<DatabaseSchema, E>>,
2929
T: Hash,
3030
{
31-
let key = self.cache_key(migration_directories);
31+
let mut hasher = DefaultHasher::new();
32+
migration_directories.hash(&mut hasher);
33+
let cache_key = hasher.finish().to_string();
3234

33-
if !self.migrations.contains_key(&key) {
34-
println!("Cache miss for key: {}", key);
35+
if !self.migrations.contains_key(&cache_key) {
3536
let schema = f().await?;
36-
self.migrations.insert(key.clone(), schema);
37-
} else {
38-
println!("Cache hit for key: {}", key);
37+
self.migrations.insert(cache_key.clone(), schema);
3938
}
4039

41-
Ok(self.migrations.get(&key).unwrap().clone())
42-
}
43-
44-
fn cache_key<T: Hash>(&self, migration_directories: &Vec<T>) -> String {
45-
let mut hasher = DefaultHasher::new();
46-
47-
migration_directories.hash(&mut hasher);
48-
49-
hasher.finish().to_string()
40+
Ok(self.migrations.get(&cache_key).unwrap().clone())
5041
}
5142
}
5243

schema-engine/core/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) struct EngineState {
3636
//
3737
// To a channel leading to a spawned MigrationConnector.
3838
connectors: Mutex<HashMap<ConnectorRequestType, mpsc::Sender<ErasedConnectorRequest>>>,
39-
/// The cache for migrations to avoid redundant work during `prisma migrate dev`.
39+
/// The cache for DatabaseSchemas based of migration directories to avoid redundant work during `prisma migrate dev`.
4040
migration_schema_cache: Arc<Mutex<MigrationSchemaCache>>,
4141
}
4242

schema-engine/schema-engine-wasm/src/wasm/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub struct SchemaEngine {
7272
/// The dispatcher for tracing.
7373
dispatch: Dispatch,
7474

75-
/// The cache for migrations to avoid redundant work during `prisma migrate dev`.
75+
/// The cache for DatabaseSchemas based of migration directories to avoid redundant work during `prisma migrate dev`.
7676
migration_schema_cache: MigrationSchemaCache,
7777
}
7878

schema-engine/sql-schema-describer/src/connector_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'de> Deserialize<'de> for ConnectorData {
4141

4242
impl Clone for ConnectorData {
4343
fn clone(&self) -> Self {
44-
let cloned_data = self.data.as_ref().map(|d| (&**d).clone_box());
44+
let cloned_data = self.data.as_ref().map(|d| (**d).clone_box());
4545

4646
ConnectorData { data: cloned_data }
4747
}

0 commit comments

Comments
 (0)