33from pathlib import Path
44from dataclasses import dataclass
55
6- from sqlglot import Dialect
6+ from sqlmesh . cli . main import ENGINE_TYPE_DISPLAY_ORDER
77from sqlmesh .integrations .dlt import generate_dlt_models_and_settings
88from sqlmesh .utils .date import yesterday_ds
99from sqlmesh .utils .errors import SQLMeshError
@@ -39,17 +39,15 @@ def _gen_config(
3939 database: db.db"""
4040 )
4141
42- engine = "mssql" if engine_type == "tsql" else engine_type
43-
4442 if not settings and template != ProjectTemplate .DBT :
4543 doc_link = "https://sqlmesh.readthedocs.io/en/stable/integrations/engines{engine_link}"
4644 engine_link = ""
4745
48- if engine in CONNECTION_CONFIG_TO_TYPE :
46+ if engine_type in CONNECTION_CONFIG_TO_TYPE :
4947 required_fields = []
5048 non_required_fields = []
5149
52- for name , field in CONNECTION_CONFIG_TO_TYPE [engine ].model_fields .items ():
50+ for name , field in CONNECTION_CONFIG_TO_TYPE [engine_type ].model_fields .items ():
5351 field_name = field .alias or name
5452 if field_name in ("dialect" , "display_name" ):
5553 continue
@@ -65,7 +63,7 @@ def _gen_config(
6563 option_str = f" { '# ' if not required else '' } { field_name } : { default_value } \n "
6664
6765 # specify the DuckDB database field so quickstart runs out of the box
68- if engine == "duckdb" and field_name == "database" :
66+ if engine_type == "duckdb" and field_name == "database" :
6967 option_str = " database: db.db\n "
7068 required = True
7169
@@ -76,7 +74,7 @@ def _gen_config(
7674
7775 connection_settings = "" .join (required_fields + non_required_fields )
7876
79- engine_link = f"/{ engine } /#connection-options"
77+ engine_link = f"/{ engine_type } /#connection-options"
8078
8179 connection_settings = (
8280 " # For more information on configuring the connection to your execution engine, visit:\n "
@@ -87,16 +85,16 @@ def _gen_config(
8785 default_configs = {
8886 ProjectTemplate .DEFAULT : f"""# --- Gateway Connection ---
8987gateways:
90- { engine } :
88+ { engine_type } :
9189 connection:
9290{ connection_settings }
93- default_gateway: { engine }
91+ default_gateway: { engine_type }
9492
9593# --- Model Defaults ---
9694# https://sqlmesh.readthedocs.io/en/stable/reference/model_configuration/#model-defaults
9795
9896model_defaults:
99- dialect: { DIALECT_TO_TYPE [engine ]}
97+ dialect: { DIALECT_TO_TYPE [engine_type ]}
10098 start: { start or yesterday_ds ()} # Start date for backfill history
10199 cron: '@daily' # Run models daily at 12am UTC (can override per model)
102100
@@ -276,7 +274,6 @@ def _gen_example_objects(schema_name: str) -> ExampleObjects:
276274
277275def init_example_project (
278276 path : t .Union [str , Path ],
279- dialect : t .Optional [str ],
280277 engine_type : t .Optional [str ],
281278 template : ProjectTemplate = ProjectTemplate .DEFAULT ,
282279 pipeline : t .Optional [str ] = None ,
@@ -299,9 +296,17 @@ def init_example_project(
299296 )
300297
301298 if not engine_type and template != ProjectTemplate .DBT :
302- if not dialect :
303- raise SQLMeshError ("Please provide a default SQL dialect for your project's models." )
304- Dialect .get_or_raise (dialect )
299+ raise SQLMeshError (
300+ "Missing `engine` argument to `sqlmesh init`. Please specify a SQL engine for your project."
301+ )
302+
303+ if engine_type not in ENGINE_TYPE_DISPLAY_ORDER :
304+ engine_strings = "'" + "', '" .join (ENGINE_TYPE_DISPLAY_ORDER ) + "'"
305+ raise SQLMeshError (
306+ f"Invalid engine '{ engine_type } '. Please specify one of { engine_strings } ."
307+ )
308+
309+ dialect = DIALECT_TO_TYPE [engine_type ]
305310
306311 models : t .Set [t .Tuple [str , str ]] = set ()
307312 settings = None
@@ -316,11 +321,7 @@ def init_example_project(
316321 "Please provide a DLT pipeline with the `--dlt-pipeline` flag to generate a SQLMesh project from DLT."
317322 )
318323
319- # config generation chooses engine based on ConnectionConfig.type_
320- # - if user passes a SQL dialect, we always generate the engine whose type_ == dialect
321- # - example: if users passes `postgres` we will always choose `postgres` engine and never `gcp_postgres`
322- # - if user interactively chooses an engine, we will pass the correct ConnectionConfig.type_
323- _create_config (config_path , engine_type or dialect , settings , start , template , cli_mode )
324+ _create_config (config_path , engine_type , settings , start , template , cli_mode )
324325 if template == ProjectTemplate .DBT :
325326 return config_path
326327
0 commit comments