Skip to content

Commit be8f40a

Browse files
Merge branch 'main' into feat/order-by-to-many-field
2 parents cc4210b + 8c28700 commit be8f40a

10 files changed

Lines changed: 77 additions & 56 deletions

File tree

schema-engine/connectors/sql-schema-connector/src/flavour/postgres.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,8 @@ async fn sql_schema_from_migrations_and_db(
703703
migration.migration_name()
704704
);
705705

706-
conn.raw_cmd(&script)
706+
conn.apply_migration_script(migration.migration_name(), &script)
707707
.await
708-
.map_err(imp::quaint_error_mapper(params))
709708
.map_err(|connector_error| {
710709
connector_error.into_migration_does_not_apply_cleanly(migration.migration_name().to_owned())
711710
})?;

schema-engine/core/src/commands/diff_cli.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub async fn diff_cli(
3434
let from = json_rpc_diff_target_to_dialect(
3535
&params.from,
3636
datasource_urls,
37-
params.shadow_database_url.as_deref(),
3837
namespaces.clone(),
3938
&filter,
4039
preview_features,
@@ -44,7 +43,6 @@ pub async fn diff_cli(
4443
let to = json_rpc_diff_target_to_dialect(
4544
&params.to,
4645
datasource_urls,
47-
params.shadow_database_url.as_deref(),
4846
namespaces,
4947
&filter,
5048
preview_features,
@@ -55,7 +53,6 @@ pub async fn diff_cli(
5553
// The `from` connector takes precedence, because if we think of diffs as migrations, `from` is
5654
// the target where the migration would be applied.
5755
//
58-
// TODO: make sure the shadow_database_url param is _always_ taken into account.
5956
// TODO: make sure the connectors are the same in from and to.
6057
let (dialect, from, to) = match (from, to) {
6158
(Some((connector, from)), Some((_, to))) => (connector, from, to),
@@ -132,21 +129,11 @@ fn namespaces_and_preview_features_from_diff_targets(
132129
async fn json_rpc_diff_target_to_dialect(
133130
target: &DiffTarget,
134131
datasource_urls: &DatasourceUrls,
135-
shadow_database_url: Option<&str>, // TODO: delete the parameter
136132
namespaces: Option<Namespaces>,
137133
filter: &SchemaFilter,
138134
preview_features: BitFlags<psl::PreviewFeature>,
139135
extension_types: &dyn ExtensionTypes,
140136
) -> CoreResult<Option<(Box<dyn SchemaDialect>, DatabaseSchema)>> {
141-
let datasource_urls = if let Some(shadow_database_url) = shadow_database_url {
142-
&DatasourceUrls {
143-
url: datasource_urls.url.clone(),
144-
shadow_database_url: Some(shadow_database_url.to_owned()),
145-
}
146-
} else {
147-
datasource_urls
148-
};
149-
150137
match target {
151138
DiffTarget::Empty => Ok(None),
152139
DiffTarget::SchemaDatasource(schemas) => {
@@ -237,7 +224,7 @@ async fn json_rpc_diff_target_to_dialect(
237224
Ok(Some((connector.schema_dialect(), schema)))
238225
}
239226
(Some(_), None) => Err(ConnectorError::from_msg(
240-
"You must pass the `--shadow-database-url` flag or set `datasource.shadowDatabaseUrl` in your `prisma.config.ts` if you want to diff a migrations directory.".to_owned(),
227+
"You must set `datasource.shadowDatabaseUrl` in your `prisma.config.ts` if you want to diff a migrations directory.".to_owned(),
241228
)),
242229
(None, _) => Err(ConnectorError::from_msg(
243230
"Could not determine the connector from the migrations directory (missing migration_lock.toml)."

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,6 @@ pub struct DiffParams {
432432
/// end-state.
433433
pub to: DiffTarget,
434434

435-
/// The URL to a live database to use as a shadow database. The schema and data on
436-
/// that database will be wiped during diffing.
437-
///
438-
/// This is only necessary when one of `from` or `to` is referencing a migrations
439-
/// directory as a source for the schema.
440-
/// @deprecated.
441-
pub shadow_database_url: Option<String>,
442-
443435
/// By default, the response will contain a human-readable diff. If you want an
444436
/// executable script, pass the `"script": true` param.
445437
pub script: bool,

schema-engine/sql-migration-tests/tests/errors/error_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ async fn diff_from_empty_schema_to_datamodel_should_not_require_url() {
577577
content: dm.to_string(),
578578
}],
579579
}),
580-
shadow_database_url: None,
581580
script: false,
582581
exit_code: None,
583582
filters: SchemaFilter::default(),

schema-engine/sql-migration-tests/tests/migrations/diff.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ fn from_unique_index_to_without(mut api: TestApi) {
6666
content: from_schema.to_string(),
6767
}],
6868
}),
69-
shadow_database_url: None,
7069
to: DiffTarget::SchemaDatamodel(SchemasContainer {
7170
files: vec![SchemaContainer {
7271
path: to_file.to_string_lossy().into_owned(),
@@ -177,7 +176,6 @@ fn from_unique_index_to_pk(mut api: TestApi) {
177176
content: from_schema.to_string(),
178177
}],
179178
}),
180-
shadow_database_url: None,
181179
to: DiffTarget::SchemaDatamodel(SchemasContainer {
182180
files: vec![SchemaContainer {
183181
path: to_file.to_string_lossy().into_owned(),
@@ -369,7 +367,6 @@ fn from_empty_to_migrations_directory(mut api: TestApi) {
369367
from: DiffTarget::Empty,
370368
to: DiffTarget::Migrations(migrations_list),
371369
script: true,
372-
shadow_database_url: Some(api.connection_string().to_owned()),
373370
filters: SchemaFilter::default(),
374371
};
375372

@@ -421,7 +418,6 @@ fn from_empty_to_migrations_folder_without_shadow_db_url_must_error(mut api: Tes
421418
from: DiffTarget::Empty,
422419
to: DiffTarget::Migrations(migrations_list),
423420
script: true,
424-
shadow_database_url: None, // TODO: ?
425421
filters: SchemaFilter::default(),
426422
};
427423

@@ -436,7 +432,7 @@ fn from_empty_to_migrations_folder_without_shadow_db_url_must_error(mut api: Tes
436432
.unwrap_err();
437433

438434
let expected_error = expect![[r#"
439-
You must pass the `--shadow-database-url` flag or set `datasource.shadowDatabaseUrl` in your `prisma.config.ts` if you want to diff a migrations directory.
435+
You must set `datasource.shadowDatabaseUrl` in your `prisma.config.ts` if you want to diff a migrations directory.
440436
"#]];
441437
expected_error.assert_eq(&err.to_string());
442438
}
@@ -478,7 +474,6 @@ fn from_schema_datamodel_to_url(mut api: TestApi) {
478474
}],
479475
}),
480476
script: true,
481-
shadow_database_url: None,
482477
to: DiffTarget::Url(UrlContainer { url: second_url }),
483478
filters: SchemaFilter::default(),
484479
};
@@ -530,7 +525,6 @@ fn from_schema_datasource_relative(api: TestApi) {
530525
config_dir: schema_path.parent().unwrap().to_string_lossy().into_owned(),
531526
}),
532527
script: true,
533-
shadow_database_url: None,
534528
to: DiffTarget::Empty,
535529
filters: SchemaFilter::default(),
536530
};
@@ -590,7 +584,6 @@ fn from_schema_datasource_to_url(mut api: TestApi) {
590584
config_dir: schema_path.parent().unwrap().to_string_lossy().into_owned(),
591585
}),
592586
script: true,
593-
shadow_database_url: None,
594587
to: DiffTarget::Url(UrlContainer { url: second_url }),
595588
filters: SchemaFilter::default(),
596589
};
@@ -649,7 +642,6 @@ fn with_schema_filters(api: TestApi) {
649642
config_dir: schema_path.parent().unwrap().to_string_lossy().into_owned(),
650643
}),
651644
script: true,
652-
shadow_database_url: None,
653645
to: DiffTarget::Url(UrlContainer { url: second_url }),
654646
filters: SchemaFilter {
655647
external_tables: vec!["external_table".to_string()],
@@ -704,7 +696,6 @@ fn with_invalid_schema_filter_sqlite(mut api: TestApi) {
704696
config_dir: schema_path.parent().unwrap().to_string_lossy().into_owned(),
705697
}),
706698
script: true,
707-
shadow_database_url: None,
708699
to: DiffTarget::Url(UrlContainer { url: second_url }),
709700
filters: SchemaFilter {
710701
external_tables: vec!["public.external_table".to_string()],
@@ -743,7 +734,6 @@ fn with_invalid_schema_filter_postgres(mut api: TestApi) {
743734
config_dir: schema_path.parent().unwrap().to_string_lossy().into_owned(),
744735
}),
745736
script: true,
746-
shadow_database_url: None,
747737
to: DiffTarget::Url(UrlContainer {
748738
url: connection_string.to_string(),
749739
}),
@@ -786,7 +776,6 @@ fn from_url_to_url(mut api: TestApi) {
786776
exit_code: None,
787777
from: DiffTarget::Url(UrlContainer { url: first_url }),
788778
script: true,
789-
shadow_database_url: None,
790779
to: DiffTarget::Url(UrlContainer { url: second_url }),
791780
filters: SchemaFilter::default(),
792781
};
@@ -845,7 +834,6 @@ fn diffing_mongo_schemas_to_script_returns_a_nice_error() {
845834
content: from.to_string(),
846835
}],
847836
}),
848-
shadow_database_url: None,
849837
to: DiffTarget::SchemaDatamodel(SchemasContainer {
850838
files: vec![SchemaContainer {
851839
path: to_file.to_string_lossy().into_owned(),
@@ -879,7 +867,6 @@ fn diff_sqlite_migration_directories() {
879867
exit_code: None,
880868
from: DiffTarget::Migrations(migrations_list),
881869
script: true,
882-
shadow_database_url: None,
883870
to: DiffTarget::Migrations(migrations_list_2),
884871
filters: SchemaFilter::default(),
885872
};
@@ -946,7 +933,6 @@ fn from_migrations_to_schema_datamodel_ignores_manual_partial_indexes_without_pr
946933
}],
947934
}),
948935
script: false,
949-
shadow_database_url: Some(api.connection_string().to_owned()),
950936
filters: SchemaFilter::default(),
951937
},
952938
);
@@ -1011,7 +997,6 @@ fn from_schema_datamodel_to_migrations_ignores_manual_partial_indexes_without_pr
1011997
}),
1012998
to: DiffTarget::Migrations(list_migrations(migrations_dir.path()).unwrap()),
1013999
script: false,
1014-
shadow_database_url: Some(api.connection_string().to_owned()),
10151000
filters: SchemaFilter::default(),
10161001
},
10171002
);
@@ -1084,7 +1069,6 @@ fn from_migrations_to_url_ignores_manual_partial_indexes_with_engine_seeded_sche
10841069
url: api.connection_string().to_owned(),
10851070
}),
10861071
script: false,
1087-
shadow_database_url: Some(api.connection_string().to_owned()),
10881072
filters: SchemaFilter::default(),
10891073
},
10901074
);
@@ -1140,7 +1124,6 @@ fn diffing_mongo_schemas_works() {
11401124
content: from.to_string(),
11411125
}],
11421126
}),
1143-
shadow_database_url: None,
11441127
to: DiffTarget::SchemaDatamodel(SchemasContainer {
11451128
files: vec![SchemaContainer {
11461129
path: to_file.to_string_lossy().into_owned(),
@@ -1193,7 +1176,6 @@ fn diff_with_exit_code_and_empty_diff_returns_zero() {
11931176
}],
11941177
}),
11951178
script: false,
1196-
shadow_database_url: None,
11971179
filters: SchemaFilter::default(),
11981180
},
11991181
);
@@ -1234,7 +1216,6 @@ fn diff_with_exit_code_and_non_empty_diff_returns_two() {
12341216
}],
12351217
}),
12361218
script: false,
1237-
shadow_database_url: None,
12381219
filters: SchemaFilter::default(),
12391220
},
12401221
);
@@ -1262,7 +1243,6 @@ fn diff_with_non_existing_sqlite_database_from_url() {
12621243
exit_code: Some(true),
12631244
from: DiffTarget::Empty,
12641245
script: false,
1265-
shadow_database_url: None,
12661246
to: DiffTarget::Url(UrlContainer {
12671247
url: format!("file:{}", tmpdir.path().join("db.sqlite").to_string_lossy()),
12681248
}),
@@ -1298,7 +1278,6 @@ fn diff_with_non_existing_sqlite_database_from_datasource() {
12981278
exit_code: Some(true),
12991279
from: DiffTarget::Empty,
13001280
script: false,
1301-
shadow_database_url: None,
13021281
to: DiffTarget::SchemaDatasource(SchemasWithConfigDir {
13031282
files: vec![SchemaContainer {
13041283
path: schema_path.to_string_lossy().into_owned(),
@@ -1370,7 +1349,6 @@ fn from_multi_file_schema_datasource_to_url(mut api: TestApi) {
13701349
config_dir: base_dir.path().to_string_lossy().into_owned(),
13711350
}),
13721351
script: true,
1373-
shadow_database_url: None,
13741352
to: DiffTarget::Url(UrlContainer { url: second_url }),
13751353
filters: SchemaFilter::default(),
13761354
};
@@ -1436,7 +1414,6 @@ fn from_multi_file_schema_datamodel_to_url(mut api: TestApi) {
14361414
exit_code: None,
14371415
from: DiffTarget::SchemaDatamodel(SchemasContainer { files: from_files }),
14381416
script: true,
1439-
shadow_database_url: None,
14401417
to: DiffTarget::Url(UrlContainer { url: second_url }),
14411418
filters: SchemaFilter::default(),
14421419
};

schema-engine/sql-migration-tests/tests/migrations/drift_summary.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ fn check(provider: &str, from: &str, to: &str, expectation: Expect) {
2020
}],
2121
}),
2222
script: false,
23-
shadow_database_url: None,
2423
to: schema_core::json_rpc::types::DiffTarget::SchemaDatamodel(SchemasContainer {
2524
files: vec![SchemaContainer {
2625
path: to_schema.to_str().unwrap().to_owned(),

schema-engine/sql-migration-tests/tests/migrations/mysql.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ fn dropping_m2m_relation_from_datamodel_works() {
513513
}],
514514
}),
515515
script: true,
516-
shadow_database_url: None,
517516
filters: SchemaFilter::default(),
518517
},
519518
);

schema-engine/sql-migration-tests/tests/migrations/postgres.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,3 +1114,51 @@ fn postgres_create_index_concurrently_works(api: TestApi) {
11141114
.send_sync()
11151115
.assert_applied_migrations(&["01init"]);
11161116
}
1117+
1118+
#[test_connector(tags(Postgres))]
1119+
fn postgres_create_migration_works_with_multiple_create_index_concurrently_statements(api: TestApi) {
1120+
let migrations_directory = api.create_migrations_directory();
1121+
let dm = "";
1122+
let migration = r#"
1123+
CREATE TABLE "Cat" (
1124+
id INTEGER PRIMARY KEY,
1125+
name TEXT NOT NULL,
1126+
age INTEGER NOT NULL
1127+
);
1128+
1129+
CREATE INDEX CONCURRENTLY "Cat_name_idx" ON "Cat"(name);
1130+
CREATE INDEX CONCURRENTLY "Cat_age_idx" ON "Cat"(age);
1131+
"#;
1132+
1133+
api.create_migration("01init", dm, &migrations_directory)
1134+
.draft(true)
1135+
.send_sync()
1136+
.modify_migration(|contents| {
1137+
contents.clear();
1138+
contents.push_str(migration);
1139+
});
1140+
1141+
let dm2 = api.datamodel_with_provider(
1142+
r#"
1143+
model Cat {
1144+
id Int @id
1145+
name String
1146+
age Int
1147+
breed String?
1148+
1149+
@@index([name])
1150+
@@index([age])
1151+
}
1152+
"#,
1153+
);
1154+
1155+
api.create_migration("02add_breed", &dm2, &migrations_directory)
1156+
.send_sync()
1157+
.assert_migration("02add_breed", |migration| {
1158+
migration.assert_contents(
1159+
r#"-- AlterTable
1160+
ALTER TABLE "Cat" ADD COLUMN "breed" TEXT;
1161+
"#,
1162+
)
1163+
});
1164+
}

schema-engine/sql-migration-tests/tests/single_migration_tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ fn run_single_migration_test(test_file_path: &str, test_function_name: &'static
106106
tok(schema_engine.diff(schema_core::json_rpc::types::DiffParams {
107107
exit_code: None,
108108
script: true,
109-
shadow_database_url: None,
110109
from: schema_core::json_rpc::types::DiffTarget::Empty,
111110
to: schema_core::json_rpc::types::DiffTarget::SchemaDatamodel(SchemasContainer {
112111
files: vec![schema_core::json_rpc::types::SchemaContainer {
@@ -133,7 +132,6 @@ fn run_single_migration_test(test_file_path: &str, test_function_name: &'static
133132
let second_migration_result = tok(schema_engine.diff(schema_core::json_rpc::types::DiffParams {
134133
exit_code: Some(true),
135134
script: true,
136-
shadow_database_url: None,
137135
from: schema_core::json_rpc::types::DiffTarget::Url(schema_core::json_rpc::types::UrlContainer {
138136
url: connection_string,
139137
}),

0 commit comments

Comments
 (0)