Skip to content

Commit 80ee0a4

Browse files
authored
feat(psl)!: remove the url property from datasource blocks (#5683)
Remove the `url` property from `datasource` blocks in PSL, refactor the code to handle URLs separately and update the tests. Ref: https://linear.app/prisma-company/issue/TML-1545/remove-url-datasource-attribute-from-psl /prisma-branch next
1 parent bb196f7 commit 80ee0a4

616 files changed

Lines changed: 3950 additions & 6497 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/driver-adapters/executor/src/demo-qc.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ async function main(): Promise<void> {
2727
2828
datasource db {
2929
provider = "sqlite"
30-
url = "file:./db.sqlite"
3130
}
3231
3332
model User {

libs/driver-adapters/executor/src/demo-se.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ async function main(): Promise<void> {
3939
4040
datasource db {
4141
provider = "sqlite"
42-
url = "${url}"
4342
}
4443
4544
model User {

libs/test-setup/src/test_api_args.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,11 @@ impl TestApiArgs {
185185

186186
pub fn datasource_block<'a>(
187187
&'a self,
188-
url: &'a str,
189188
params: &'a [(&'a str, &'a str)],
190189
preview_features: &'static [&'static str],
191190
) -> DatasourceBlock<'a> {
192191
DatasourceBlock {
193192
provider: self.db.provider,
194-
url,
195193
params,
196194
preview_features,
197195
}
@@ -201,7 +199,7 @@ impl TestApiArgs {
201199
self.db.provider
202200
}
203201

204-
pub fn shadow_database_url(&self) -> Option<&'static str> {
202+
pub fn shadow_database_url(&self) -> Option<&str> {
205203
self.db.shadow_database_url.as_deref()
206204
}
207205

@@ -216,16 +214,10 @@ impl TestApiArgs {
216214

217215
pub struct DatasourceBlock<'a> {
218216
provider: &'a str,
219-
url: &'a str,
220217
params: &'a [(&'a str, &'a str)],
221218
preview_features: &'static [&'static str],
222219
}
223220

224-
impl DatasourceBlock<'_> {
225-
pub fn url(&self) -> &str {
226-
self.url
227-
}
228-
}
229221
fn generator_block(preview_features: &'static [&'static str]) -> String {
230222
let preview_features: Vec<String> = preview_features.iter().map(|pf| format!(r#""{pf}""#)).collect();
231223

@@ -251,8 +243,6 @@ impl Display for DatasourceBlock<'_> {
251243

252244
f.write_str("datasource db {\n provider = \"")?;
253245
f.write_str(self.provider)?;
254-
f.write_str("\"\n url = \"")?;
255-
f.write_str(self.url)?;
256246
f.write_str("\"\n")?;
257247

258248
for (param_name, param_value) in self.params {

prisma-fmt/schema.prisma

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
datasource db {
22
provider = "postgresql"
3-
url = env("MEOW")
43
}

prisma-fmt/src/code_actions/multi_schema.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,8 @@ pub(super) fn add_schema_to_schemas(
161161
)
162162
}
163163
None => {
164-
let has_properties = datasource.provider_defined() | datasource.url_defined()
165-
|| datasource.direct_url_defined()
166-
|| datasource.shadow_url_defined()
167-
|| datasource.relation_mode_defined()
168-
|| datasource.schemas_defined();
164+
let has_properties =
165+
datasource.provider_defined() || datasource.relation_mode_defined() || datasource.schemas_defined();
169166

170167
let formatted_attribute = super::format_block_property(
171168
"schemas",
@@ -180,7 +177,7 @@ pub(super) fn add_schema_to_schemas(
180177
datasource_content,
181178
formatted_attribute,
182179
true,
183-
datasource.url_span,
180+
datasource.provider_span,
184181
)
185182
}
186183
};

prisma-fmt/src/get_config.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ mod tests {
193193
"datasource.prisma",
194194
r#"datasource db {
195195
provider = "postgresql"
196-
url = "postgresql://example.com/db"
197196
}"#,
198197
),
199198
];
@@ -203,33 +202,14 @@ mod tests {
203202
});
204203

205204
let expected = expect![[
206-
r#"{"config":{"generators":[{"name":"js","provider":{"fromEnvVar":null,"value":"prisma-client"},"output":null,"config":{},"binaryTargets":[],"previewFeatures":[],"sourceFilePath":"generator.prisma"}],"datasources":[{"name":"db","provider":"postgresql","activeProvider":"postgresql","url":{"fromEnvVar":null,"value":"postgresql://example.com/db"},"schemas":[],"sourceFilePath":"datasource.prisma"}],"warnings":[]},"errors":[]}"#
205+
r#"{"config":{"generators":[{"name":"js","provider":{"fromEnvVar":null,"value":"prisma-client"},"output":null,"config":{},"binaryTargets":[],"previewFeatures":[],"sourceFilePath":"generator.prisma"}],"datasources":[{"name":"db","provider":"postgresql","activeProvider":"postgresql","schemas":[],"sourceFilePath":"datasource.prisma"}],"warnings":[]},"errors":[]}"#
207206
]];
208207
let response = get_config(&request.to_string());
209208
expected.assert_eq(&response);
210209
}
211210

212211
#[test]
213-
fn get_config_env_var() {
214-
let schema = r#"
215-
datasource thedb {
216-
provider = "postgresql"
217-
url = env("IGNORED")
218-
}
219-
"#;
220-
221-
let request = json!({
222-
"prismaSchema": schema,
223-
});
224-
let expected = expect![[
225-
r#"{"config":{"generators":[],"datasources":[{"name":"thedb","provider":"postgresql","activeProvider":"postgresql","url":{"fromEnvVar":"IGNORED","value":null},"schemas":[],"sourceFilePath":"schema.prisma"}],"warnings":[]},"errors":[]}"#
226-
]];
227-
let response = get_config(&request.to_string());
228-
expected.assert_eq(&response);
229-
}
230-
231-
#[test]
232-
fn get_config_direct_url_should_error() {
212+
fn get_config_urls_should_error() {
233213
let schema = r#"
234214
datasource thedb {
235215
provider = "postgresql"
@@ -245,7 +225,7 @@ mod tests {
245225
}
246226
});
247227
let expected = expect![[
248-
r#"{"config":{"generators":[],"datasources":[{"name":"thedb","provider":"postgresql","activeProvider":"postgresql","url":{"fromEnvVar":"DBURL","value":null},"schemas":[],"sourceFilePath":"schema.prisma"}],"warnings":[]},"errors":[{"file_name":"schema.prisma","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe datasource property `directUrl` is no longer supported in schema files. Move connection URLs to `prisma.config.ts`. See https://pris.ly/d/config-datasource\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m url = env(\"DBURL\")\n\u001b[1;94m 5 | \u001b[0m \u001b[1;91mdirectUrl = \"postgresql://example.com/direct\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n"}]}"#
228+
r#"{"config":{"generators":[],"datasources":[{"name":"thedb","provider":"postgresql","activeProvider":"postgresql","schemas":[],"sourceFilePath":"schema.prisma"}],"warnings":[]},"errors":[{"file_name":"schema.prisma","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe datasource property `url` is no longer supported in schema files. Move connection URLs for Migrate to `prisma.config.ts` and pass either `adapter` for a direct database connection or `accelerateUrl` for Accelerate to the `PrismaClient` constructor. See https://pris.ly/d/config-datasource and https://pris.ly/d/prisma7-client-config\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:4\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 3 | \u001b[0m provider = \"postgresql\"\n\u001b[1;94m 4 | \u001b[0m \u001b[1;91murl = env(\"DBURL\")\u001b[0m\n\u001b[1;94m | \u001b[0m\n"},{"file_name":"schema.prisma","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe datasource property `directUrl` is no longer supported in schema files. Move connection URLs to `prisma.config.ts`. See https://pris.ly/d/config-datasource\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m url = env(\"DBURL\")\n\u001b[1;94m 5 | \u001b[0m \u001b[1;91mdirectUrl = \"postgresql://example.com/direct\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n"}]}"#
249229
]];
250230
let response = get_config(&request.to_string());
251231
expected.assert_eq(&response);

prisma-fmt/src/get_datamodel.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ mod tests {
3737
3838
datasource db {
3939
provider = "postgresql"
40-
url = env("DATABASE_URL")
4140
}
4241
4342
model User {

prisma-fmt/src/get_dmmf.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ mod tests {
5050
}
5151

5252
#[test]
53-
fn get_dmmf_missing_env_var() {
53+
fn get_dmmf_single_file() {
5454
let schema = r#"
5555
datasource thedb {
5656
provider = "postgresql"
57-
url = env("NON_EXISTING_ENV_VAR_WE_COUNT_ON_IT_AT_LEAST")
5857
}
5958
"#;
6059

@@ -190,28 +189,6 @@ mod tests {
190189
expected.assert_eq(&prettified_response);
191190
}
192191

193-
#[test]
194-
fn get_dmmf_direct_url_direct_empty() {
195-
let schema = r#"
196-
datasource thedb {
197-
provider = "postgresql"
198-
url = env("DBURL")
199-
directUrl = ""
200-
}
201-
"#;
202-
203-
let request = json!({
204-
"prismaSchema": schema,
205-
});
206-
207-
let expected = expect![[
208-
r#"{"error_code":"P1012","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe datasource property `directUrl` is no longer supported in schema files. Move connection URLs to `prisma.config.ts`. See https://pris.ly/d/config-datasource\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m url = env(\"DBURL\")\n\u001b[1;94m 5 | \u001b[0m \u001b[1;91mdirectUrl = \"\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1"}"#
209-
]];
210-
211-
let response = get_dmmf(&request.to_string()).unwrap_err();
212-
expected.assert_eq(&response);
213-
}
214-
215192
#[test]
216193
fn get_dmmf_multiple_files() {
217194
let schema = vec![
@@ -220,7 +197,6 @@ mod tests {
220197
r#"
221198
datasource thedb {
222199
provider = "postgresql"
223-
url = env("DBURL")
224200
}
225201
226202
model A {
@@ -6907,7 +6883,6 @@ mod tests {
69076883
let schema = r#"
69086884
datasource db {
69096885
provider = "sqlite"
6910-
url = "sqlite"
69116886
relationMode = "prisma"
69126887
referentialIntegrity = "foreignKeys"
69136888
}
@@ -6918,7 +6893,7 @@ mod tests {
69186893
});
69196894

69206895
let expected = expect![[
6921-
r#"{"error_code":"P1012","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe `referentialIntegrity` and `relationMode` attributes cannot be used together. Please use only `relationMode` instead.\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:6\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 5 | \u001b[0m relationMode = \"prisma\"\n\u001b[1;94m 6 | \u001b[0m \u001b[1;91mreferentialIntegrity = \"foreignKeys\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1"}"#
6896+
r#"{"error_code":"P1012","message":"\u001b[1;91merror\u001b[0m: \u001b[1mThe `referentialIntegrity` and `relationMode` attributes cannot be used together. Please use only `relationMode` instead.\u001b[0m\n \u001b[1;94m-->\u001b[0m \u001b[4mschema.prisma:5\u001b[0m\n\u001b[1;94m | \u001b[0m\n\u001b[1;94m 4 | \u001b[0m relationMode = \"prisma\"\n\u001b[1;94m 5 | \u001b[0m \u001b[1;91mreferentialIntegrity = \"foreignKeys\"\u001b[0m\n\u001b[1;94m | \u001b[0m\n\nValidation Error Count: 1"}"#
69226897
]];
69236898
let response = get_dmmf(&request.to_string()).unwrap_err();
69246899
expected.assert_eq(&response);

prisma-fmt/src/lint.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ mod tests {
101101
let schema = indoc! {r#"
102102
datasource db {
103103
provider = "postgresql"
104-
url = env("DATABASE_URL")
105104
}
106105
107106
generator client {
@@ -119,8 +118,8 @@ mod tests {
119118
[
120119
{
121120
"file_name": "schema.prisma",
122-
"start": 146,
123-
"end": 160,
121+
"start": 113,
122+
"end": 127,
124123
"text": "Preview feature \"createMany\" is deprecated. The functionality can be used without specifying it as a preview feature.",
125124
"is_warning": true
126125
}
@@ -134,7 +133,6 @@ mod tests {
134133
let schema1 = indoc! {r#"
135134
datasource db {
136135
provider = "postgresql"
137-
url = env("DATABASE_URL")
138136
}
139137
140138
generator client {
@@ -158,8 +156,8 @@ mod tests {
158156
[
159157
{
160158
"file_name": "schema1.prisma",
161-
"start": 146,
162-
"end": 160,
159+
"start": 113,
160+
"end": 127,
163161
"text": "Preview feature \"createMany\" is deprecated. The functionality can be used without specifying it as a preview feature.",
164162
"is_warning": true
165163
}

0 commit comments

Comments
 (0)