Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
8 changes: 8 additions & 0 deletions examples/multi/repo_1/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project: a

connections:
local:
type: duckdb
database: db.db

default_connection: local
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions examples/multi/repo_1/models/a.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MODEL (
name bronze.a
);

SELECT
1 AS col_a,
'b' AS col_b
7 changes: 7 additions & 0 deletions examples/multi/repo_1/models/b.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MODEL (
name bronze.b
);

SELECT
*
FROM bronze.a
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions examples/multi/repo_2/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project: repo_2

connections:
local:
type: duckdb
database: db.db

default_connection: local
Empty file.
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions examples/multi/repo_2/models/c.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MODEL (
name silver.c
);

SELECT DISTINCT col_a
FROM bronze.a
7 changes: 7 additions & 0 deletions examples/multi/repo_2/models/d.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MODEL (
name silver.d
);

SELECT
*
FROM silver.c
Empty file.
17 changes: 9 additions & 8 deletions sqlmesh/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@click.group(no_args_is_help=True)
@opt.path
@opt.paths
@opt.config
@click.option(
"--connection",
Expand All @@ -31,7 +31,7 @@
@error_handler
def cli(
ctx: click.Context,
path: str,
paths: t.List[str],
config: t.Optional[str] = None,
connection: t.Optional[str] = None,
test_connection: t.Optional[str] = None,
Expand All @@ -40,25 +40,26 @@ def cli(
if ctx.invoked_subcommand == "version":
return

path = os.path.abspath(path)
if ctx.invoked_subcommand == "init":
ctx.obj = path
return
if len(paths) == 1:
path = os.path.abspath(paths[0])
if ctx.invoked_subcommand == "init":
ctx.obj = path
return

# Delegates the execution of the --help option to the corresponding subcommand
if "--help" in sys.argv:
return

context = Context(
path=path,
paths=paths,
config=config,
connection=connection,
test_connection=test_connection,
)

if not context.models:
raise click.ClickException(
f"`{path}` doesn't seem to have any models... cd into the proper directory or specify the path with --path."
f"`{paths}` doesn't seem to have any models... cd into the proper directory or specify the path(s) with --paths."
)

ctx.obj = context
Expand Down
10 changes: 6 additions & 4 deletions sqlmesh/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import click

path = click.option(
"--path",
default=os.getcwd(),
help="Path to the models directory.",
paths = click.option(
"-p",
"--paths",
multiple=True,
default=[os.getcwd()],
help="Path(s) to the SQLMesh config/project.",
)

config = click.option(
Expand Down
10 changes: 8 additions & 2 deletions sqlmesh/core/config/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Config(BaseConfig):
notification_targets: The notification targets to use.
dialect: The default sql dialect of model queries. Default: same as engine dialect.
physical_schema: The default schema used to store materialized tables.
project: The project name of this config. Used for multi-repo setups.
snapshot_ttl: The period of time that a model snapshot that is not a part of any environment should exist before being deleted.
environment_ttl: The period of time that a development environment should exist before being deleted.
ignore_patterns: Files that match glob patterns specified in this list are ignored when scanning the project folder.
Expand All @@ -46,10 +47,11 @@ class Config(BaseConfig):
)
scheduler: SchedulerConfig = BuiltInSchedulerConfig()
notification_targets: t.List[NotificationTarget] = []
physical_schema: str = ""
physical_schema: str = c.SQLMESH
project: str = ""
snapshot_ttl: str = c.DEFAULT_SNAPSHOT_TTL
environment_ttl: t.Optional[str] = c.DEFAULT_ENVIRONMENT_TTL
ignore_patterns: t.List[str] = []
ignore_patterns: t.List[str] = c.IGNORE_PATTERNS
time_column_format: str = c.DEFAULT_TIME_COLUMN_FORMAT
auto_categorize_changes: CategorizerConfig = CategorizerConfig()
users: t.List[User] = []
Expand Down Expand Up @@ -111,3 +113,7 @@ def test_connection(self) -> ConnectionConfig:
if isinstance(self.test_connection_, str):
return self.get_connection(self.test_connection_)
return self.test_connection_

@property
def dialect(self) -> t.Optional[str]:
return self.model_defaults.dialect
6 changes: 3 additions & 3 deletions sqlmesh/core/config/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BuiltInSchedulerConfig(_SchedulerConfig, BaseConfig):
type_: Literal["builtin"] = Field(alias="type", default="builtin")

def create_state_sync(self, context: Context) -> t.Optional[StateSync]:
return EngineAdapterStateSync(context.engine_adapter, context.physical_schema)
return EngineAdapterStateSync(context.engine_adapter)

def create_plan_evaluator(self, context: Context) -> PlanEvaluator:
return BuiltInPlanEvaluator(
Expand Down Expand Up @@ -107,10 +107,10 @@ def create_plan_evaluator(self, context: Context) -> PlanEvaluator:
dag_creation_poll_interval_secs=self.dag_creation_poll_interval_secs,
dag_creation_max_retry_attempts=self.dag_creation_max_retry_attempts,
console=context.console,
notification_targets=context.notification_targets,
notification_targets=context.config.notification_targets,
backfill_concurrent_tasks=self.backfill_concurrent_tasks,
ddl_concurrent_tasks=self.ddl_concurrent_tasks,
users=context.users,
users=context.config.users,
)


Expand Down
6 changes: 6 additions & 0 deletions sqlmesh/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@

DEFAULT_MAX_LIMIT = 1000
"""The default maximum row limit that is used when evaluating a model."""

AUDITS = "audits"
HOOKS = "hooks"
MACROS = "macros"
MODELS = "models"
TESTS = "tests"
Loading