Skip to content

Commit

Permalink
[DOP-22145] Add file_name_template field (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasDevelopment authored Feb 5, 2025
1 parent 31eaeab commit 40a0857
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TEST_CLICKHOUSE_PORT_FOR_CONFTEST=8123
TEST_CLICKHOUSE_HOST_FOR_WORKER=test-clickhouse
TEST_CLICKHOUSE_PORT_FOR_WORKER=8123
TEST_CLICKHOUSE_USER=default
TEST_CLICKHOUSE_PASSWORD=
TEST_CLICKHOUSE_PASSWORD=test_only
TEST_CLICKHOUSE_DB=default

TEST_MSSQL_HOST_FOR_CONFTEST=test-mssql
Expand Down
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export TEST_CLICKHOUSE_PORT_FOR_CONFTEST=8123
export TEST_CLICKHOUSE_HOST_FOR_WORKER=test-clickhouse
export TEST_CLICKHOUSE_PORT_FOR_WORKER=8123
export TEST_CLICKHOUSE_USER=default
export TEST_CLICKHOUSE_PASSWORD=
export TEST_CLICKHOUSE_PASSWORD=test_only
export TEST_CLICKHOUSE_DB=default

export TEST_MSSQL_HOST_FOR_CONFTEST=localhost
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ services:
test-clickhouse:
image: clickhouse/clickhouse-server
restart: unless-stopped
environment:
CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: test_only
CLICKHOUSE_DB: default
ports:
- 8123:8123
- 9001:9000
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/next_release/196.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `file_name_template` field to `target_params`
22 changes: 22 additions & 0 deletions syncmaster/schemas/v1/transfers/file/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ReadFileTransferTarget(BaseModel):
...,
discriminator="type",
)
file_name_template: str
options: dict[str, Any]


Expand Down Expand Up @@ -61,6 +62,10 @@ class CreateFileTransferTarget(BaseModel):
...,
discriminator="type",
)
file_name_template: str = Field(
default="{run_created_at}_{index}.{extension}",
description="Template for file naming with required placeholders 'index' and 'extension'",
)
options: dict[str, Any] = Field(default_factory=dict)

class Config:
Expand All @@ -72,3 +77,20 @@ def _directory_path_is_valid_path(cls, value):
if not PurePosixPath(value).is_absolute():
raise ValueError("Directory path must be absolute")
return value

@field_validator("file_name_template")
@classmethod
def validate_file_name_template(cls, value):
required_keys = {"index", "extension"}
placeholders = {key for key in required_keys if f"{{{key}}}" in value}

missing_keys = sorted(required_keys - placeholders)
if missing_keys:
raise ValueError(f"Missing required placeholders: {', '.join(missing_keys)}")

try:
value.format(index="", extension="", run_created_at="", run_id="")
except KeyError as e:
raise ValueError(f"Invalid placeholder: {e}")

return value
Loading

0 comments on commit 40a0857

Please sign in to comment.