Update dbt_project.yml and profiles.yml files based on variant configuration.
(variant, task_name)
| 229 | |
| 230 | |
| 231 | def update_dbt_config(variant, task_name): |
| 232 | """Update dbt_project.yml and profiles.yml files based on variant configuration.""" |
| 233 | sandbox_dir = Path("dev/sandbox") |
| 234 | project_name = variant["project_name"] |
| 235 | db_type = variant["db_type"] |
| 236 | |
| 237 | # Update dbt_project.yml to use the right profile |
| 238 | dbt_project_path = sandbox_dir / "dbt_project.yml" |
| 239 | if not dbt_project_path.exists(): |
| 240 | print(f"❌ dbt_project.yml not found in {sandbox_dir}") |
| 241 | return False |
| 242 | |
| 243 | try: |
| 244 | # Use the existing _update_project_profile function logic |
| 245 | profile_name = f"{project_name}-{db_type}" |
| 246 | |
| 247 | with open(dbt_project_path, "r") as f: |
| 248 | dbt_project = yaml.safe_load(f) |
| 249 | |
| 250 | dbt_project["profile"] = profile_name |
| 251 | |
| 252 | with open(dbt_project_path, "w") as f: |
| 253 | yaml.safe_dump(dbt_project, f) |
| 254 | |
| 255 | print(f"✓ Updated dbt_project.yml to use profile: {profile_name}") |
| 256 | |
| 257 | except Exception as e: |
| 258 | print(f"❌ Failed to update dbt_project.yml: {e}") |
| 259 | return False |
| 260 | |
| 261 | # Update profiles.yml |
| 262 | profiles_path = sandbox_dir / "profiles.yml" |
| 263 | if not profiles_path.exists(): |
| 264 | print(f"❌ profiles.yml not found in {sandbox_dir}") |
| 265 | return False |
| 266 | |
| 267 | try: |
| 268 | if db_type == "snowflake": |
| 269 | # Use the existing _update_snowflake_creds function logic |
| 270 | from ade_bench.setup.setup_utils import generate_task_snowflake_credentials |
| 271 | |
| 272 | creds = generate_task_snowflake_credentials(task_name) |
| 273 | |
| 274 | with open(profiles_path, "r") as f: |
| 275 | profiles = yaml.safe_load(f) |
| 276 | |
| 277 | profiles[profile_name]["outputs"]["dev"]["account"] = creds["account"].replace( |
| 278 | ".snowflakecomputing.com", "" |
| 279 | ) |
| 280 | profiles[profile_name]["outputs"]["dev"]["user"] = creds["user"] |
| 281 | profiles[profile_name]["outputs"]["dev"]["password"] = creds["password"] |
| 282 | profiles[profile_name]["outputs"]["dev"]["role"] = creds["role"] |
| 283 | profiles[profile_name]["outputs"]["dev"]["database"] = creds["database"] |
| 284 | profiles[profile_name]["outputs"]["dev"]["schema"] = creds["schema"] |
| 285 | profiles[profile_name]["outputs"]["dev"]["warehouse"] = creds["warehouse"] |
| 286 | |
| 287 | with open(profiles_path, "w") as f: |
| 288 | yaml.safe_dump(profiles, f) |
no test coverage detected