Skip to content

Commit 6fa05d5

Browse files
authored
refactor: make schema-filter non optional (#5560)
Small refactoring PR to make schema-filter non optional but work with a default filter instead. Removes some annoying optional handling. Will require minor update on the types on the TS side.
1 parent f79e51f commit 6fa05d5

19 files changed

Lines changed: 80 additions & 78 deletions

File tree

query-engine/connector-test-kit-rs/qe-setup/src/mssql.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use connection_string::JdbcString;
22
use quaint::{prelude::*, single::Quaint};
33
use schema_core::{
4-
json_rpc::types::ResetInput,
4+
json_rpc::types::{ResetInput, SchemaFilter},
55
schema_connector::{ConnectorError, ConnectorParams, ConnectorResult},
66
};
77
use std::str::FromStr;
@@ -24,7 +24,11 @@ pub(crate) async fn mssql_setup(url: String, prisma_schema: &str, db_schemas: &[
2424
conn.raw_cmd(&sql).await.unwrap();
2525
} else {
2626
let mut api = schema_core::schema_api(Some(prisma_schema.to_owned()), None)?;
27-
api.reset(ResetInput { filter: None }).await.ok();
27+
api.reset(ResetInput {
28+
filter: SchemaFilter::default(),
29+
})
30+
.await
31+
.ok();
2832
api.dispose().await.ok();
2933
// Without these, our poor connection gets deadlocks if other schemas
3034
// are modified while we introspect.

schema-engine/connectors/schema-connector/src/filter.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,3 @@ impl From<json_rpc::types::SchemaFilter> for SchemaFilter {
4848
}
4949
}
5050
}
51-
52-
impl From<Option<json_rpc::types::SchemaFilter>> for SchemaFilter {
53-
fn from(filter: Option<json_rpc::types::SchemaFilter>) -> Self {
54-
let filter = filter.unwrap_or_default();
55-
Self {
56-
external_tables: filter.external_tables,
57-
external_enums: filter.external_enums,
58-
}
59-
}
60-
}

schema-engine/json-rpc-api/src/types.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub struct ApplyMigrationsInput {
234234
pub migrations_list: MigrationList,
235235

236236
/// The schema filter to use during the apply migrations.
237-
pub filters: Option<SchemaFilter>,
237+
pub filters: SchemaFilter,
238238
}
239239

240240
/// The output of the `applyMigrations` command.
@@ -289,7 +289,7 @@ pub struct CreateMigrationInput {
289289
pub schema: SchemasContainer,
290290

291291
/// Entities to be included or excluded from the migration.
292-
pub filters: Option<SchemaFilter>,
292+
pub filters: SchemaFilter,
293293
}
294294

295295
/// The output of the `createMigration` command.
@@ -363,7 +363,7 @@ pub struct DevDiagnosticInput {
363363
pub migrations_list: MigrationList,
364364

365365
/// The schema filter to use during checks on the database.
366-
pub filters: Option<SchemaFilter>,
366+
pub filters: SchemaFilter,
367367
}
368368

369369
/// The response type for `devDiagnostic`.
@@ -391,7 +391,7 @@ pub struct DiagnoseMigrationHistoryInput {
391391

392392
/// The schema filter to use during checks on the database.
393393
/// Note: Only used if opt_in_to_shadow_database is true.
394-
pub filters: Option<SchemaFilter>,
394+
pub filters: SchemaFilter,
395395
}
396396

397397
/// The result type for `diagnoseMigrationHistory` responses.
@@ -451,7 +451,7 @@ pub struct DiffParams {
451451
pub exit_code: Option<bool>,
452452

453453
/// The schema filter to use during the diff.
454-
pub filters: Option<SchemaFilter>,
454+
pub filters: SchemaFilter,
455455
}
456456

457457
/// The result type for the `diff` method.
@@ -629,7 +629,7 @@ pub struct EvaluateDataLossInput {
629629
/// The prisma schema files to migrate to.
630630
pub schema: SchemasContainer,
631631
/// Entities to be included or excluded during the data loss evaluation.
632-
pub filters: Option<SchemaFilter>,
632+
pub filters: SchemaFilter,
633633
}
634634

635635
/// The output of the `evaluateDataLoss` command.
@@ -736,7 +736,7 @@ pub struct MarkMigrationRolledBackOutput {}
736736
#[cfg_attr(target_arch = "wasm32", tsify(missing_as_null, from_wasm_abi))]
737737
pub struct ResetInput {
738738
/// The schema filter to use during the reset. Only relevant during "soft" resets though - usually we try to drop the whole database.
739-
pub filter: Option<SchemaFilter>,
739+
pub filter: SchemaFilter,
740740
}
741741

742742
/// The output of the `reset` command.
@@ -759,7 +759,7 @@ pub struct SchemaPushInput {
759759
pub schema: SchemasContainer,
760760

761761
/// The schema filter to use during the push.
762-
pub filters: Option<SchemaFilter>,
762+
pub filters: SchemaFilter,
763763
}
764764

765765
/// Response result for the `schemaPush` method.

schema-engine/sql-migration-tests/src/commands/apply_migrations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'a> ApplyMigrations<'a> {
3434
let output = apply_migrations(
3535
ApplyMigrationsInput {
3636
migrations_list,
37-
filters: None,
37+
filters: SchemaFilter::default(),
3838
},
3939
self.api,
4040
self.namespaces,

schema-engine/sql-migration-tests/src/commands/create_migration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a> CreateMigration<'a> {
133133
schema: SchemasContainer { files: self.files },
134134
draft: self.draft,
135135
migration_name: migration_name.clone(),
136-
filters: Some(self.filter),
136+
filters: self.filter,
137137
},
138138
self.api,
139139
&mut migration_schema_cache,

schema-engine/sql-migration-tests/src/commands/dev_diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a> DevDiagnostic<'a> {
3131
let fut = dev_diagnostic_cli(
3232
DevDiagnosticInput {
3333
migrations_list,
34-
filters: Some(self.filter),
34+
filters: self.filter,
3535
},
3636
None,
3737
self.api,

schema-engine/sql-migration-tests/src/commands/diagnose_migration_history.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use schema_core::{
22
CoreError, CoreResult,
3-
commands::DiagnoseMigrationHistoryOutput,
4-
commands::{DiagnoseMigrationHistoryInput, diagnose_migration_history_cli},
3+
commands::{DiagnoseMigrationHistoryInput, DiagnoseMigrationHistoryOutput, diagnose_migration_history_cli},
4+
json_rpc::types::SchemaFilter,
55
schema_connector::SchemaConnector,
66
};
77
use tempfile::TempDir;
@@ -37,7 +37,7 @@ impl<'a> DiagnoseMigrationHistory<'a> {
3737
DiagnoseMigrationHistoryInput {
3838
migrations_list,
3939
opt_in_to_shadow_database: self.opt_in_to_shadow_database,
40-
filters: None,
40+
filters: SchemaFilter::default(),
4141
},
4242
None,
4343
self.api,

schema-engine/sql-migration-tests/src/commands/evaluate_data_loss.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a> EvaluateDataLoss<'a> {
4040
EvaluateDataLossInput {
4141
migrations_list,
4242
schema: SchemasContainer { files: self.files },
43-
filters: Some(self.filter),
43+
filters: self.filter,
4444
},
4545
self.api,
4646
&mut migration_schema_cache,

schema-engine/sql-migration-tests/src/commands/schema_push.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ pub struct SchemaPush<'a> {
1414
migration_id: Option<&'a str>,
1515
// In eventually-consistent systems, we might need to wait for a while before the system refreshes
1616
max_ddl_refresh_delay: Option<Duration>,
17-
schema_filter: Option<SchemaFilter>,
17+
schema_filter: SchemaFilter,
1818
}
1919

2020
impl<'a> SchemaPush<'a> {
2121
pub fn new(
2222
api: &'a mut dyn SchemaConnector,
2323
files: &[(&str, &str)],
2424
max_refresh_delay: Option<Duration>,
25-
schema_filter: Option<SchemaFilter>,
25+
schema_filter: SchemaFilter,
2626
) -> Self {
2727
SchemaPush {
2828
api,

schema-engine/sql-migration-tests/src/multi_engine_test_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ impl EngineTestApi {
360360
&mut self.connector,
361361
&[("schema.prisma", &dm)],
362362
self.max_ddl_refresh_delay,
363-
None,
363+
SchemaFilter::default(),
364364
)
365365
}
366366

0 commit comments

Comments
 (0)