@@ -12,15 +12,15 @@ use crate::core_error::CoreError;
1212#[ serde( rename_all = "camelCase" ) ]
1313pub struct DatasourceUrls {
1414 /// Direct URL to the database.
15- pub url : String ,
15+ pub url : Option < String > ,
1616 /// The URL to a live shadow database, if Prisma should use it instead of creating one.
1717 pub shadow_database_url : Option < String > ,
1818}
1919
2020/// Datasource URLs that have passed validation and are safe to consume by the schema engine.
2121#[ derive( Debug , Clone ) ]
2222pub struct ValidatedDatasourceUrls {
23- url : String ,
23+ url : Option < String > ,
2424 shadow_database_url : Option < String > ,
2525}
2626
@@ -43,15 +43,15 @@ impl DatasourceUrls {
4343 /// Creates a `DatasourceUrls` instance containing only a primary URL.
4444 pub fn from_url ( url : impl Into < String > ) -> Self {
4545 Self {
46- url : url. into ( ) ,
46+ url : Some ( url. into ( ) ) ,
4747 shadow_database_url : None ,
4848 }
4949 }
5050
5151 /// Creates a `DatasourceUrls` instance with both primary and shadow database URLs.
5252 pub fn from_url_and_shadow_database_url ( url : impl Into < String > , shadow_database_url : impl Into < String > ) -> Self {
5353 Self {
54- url : url. into ( ) ,
54+ url : Some ( url. into ( ) ) ,
5555 shadow_database_url : Some ( shadow_database_url. into ( ) ) ,
5656 }
5757 }
@@ -61,7 +61,9 @@ impl DatasourceUrls {
6161 & self ,
6262 connector : & dyn psl:: datamodel_connector:: Connector ,
6363 ) -> Result < ValidatedDatasourceUrls , DatasourceError > {
64- validate_datasource_url ( & self . url , connector, "url" ) ?;
64+ if let Some ( url) = & self . url {
65+ validate_datasource_url ( url, connector, "url" ) ?;
66+ }
6567
6668 if let Some ( shadow_database_url) = & self . shadow_database_url {
6769 validate_datasource_url ( shadow_database_url, connector, "shadowDatabaseUrl" ) ?;
@@ -115,8 +117,8 @@ impl From<DatasourceError> for CoreError {
115117
116118impl ValidatedDatasourceUrls {
117119 /// Returns the validated primary datasource URL.
118- pub fn url ( & self ) -> & str {
119- & self . url
120+ pub fn url ( & self ) -> Option < & str > {
121+ self . url . as_deref ( )
120122 }
121123
122124 /// Returns the validated shadow database URL, if any.
@@ -125,14 +127,14 @@ impl ValidatedDatasourceUrls {
125127 }
126128
127129 /// Resolves relative paths in the URL against the provided configuration directory.
128- pub fn url_with_config_dir ( & self , flavour : Flavour , config_dir : & Path ) -> Cow < ' _ , str > {
129- set_config_dir ( flavour, config_dir, & self . url )
130+ pub fn url_with_config_dir ( & self , flavour : Flavour , config_dir : & Path ) -> Option < Cow < ' _ , str > > {
131+ self . url . as_deref ( ) . map ( |url| set_config_dir ( flavour, config_dir, url) )
130132 }
131133
132134 /// Returns both URLs with relative file paths rewritten relative to the configuration directory.
133135 pub fn with_config_dir ( & self , flavour : Flavour , config_dir : & Path ) -> DatasourceUrlsWithConfigDir < ' _ > {
134136 DatasourceUrlsWithConfigDir {
135- url : set_config_dir ( flavour, config_dir, & self . url ) ,
137+ url : self . url_with_config_dir ( flavour, config_dir) ,
136138 shadow_database_url : self
137139 . shadow_database_url
138140 . as_deref ( )
@@ -144,14 +146,14 @@ impl ValidatedDatasourceUrls {
144146/// Datasource URLs with relative paths resolved against the configuration directory.
145147#[ derive( Debug , Clone ) ]
146148pub struct DatasourceUrlsWithConfigDir < ' a > {
147- url : Cow < ' a , str > ,
149+ url : Option < Cow < ' a , str > > ,
148150 shadow_database_url : Option < Cow < ' a , str > > ,
149151}
150152
151153impl DatasourceUrlsWithConfigDir < ' _ > {
152154 /// Returns the primary datasource URL, with resolved paths if needed.
153- pub fn url ( & self ) -> & str {
154- & self . url
155+ pub fn url ( & self ) -> Option < & str > {
156+ self . url . as_deref ( )
155157 }
156158
157159 /// Returns the shadow database URL, with resolved paths if present.
0 commit comments