# This is a Databricks asset bundle definition for {{.project_name}}.
# See https://docs.databricks.com/dev-tools/bundles/index.html for documentation.
bundle:
  name: {{.project_name}}
  uuid: {{bundle_uuid}}

include:
  - resources/*.yml

# Variable declarations. These variables are assigned in the dev/prod targets below.
variables:
  warehouse_id:
    description: The warehouse to use
  catalog:
    description: The catalog to use
  schema:
    description: The schema to use

{{- $dev_schema := .shared_schema }}
{{- $prod_schema := .shared_schema }}
{{- if (regexp "^yes").MatchString .personal_schemas}}
  {{- $dev_schema = "${workspace.current_user.short_name}"}}
  {{- $prod_schema = "default"}}
{{- end}}

targets:
  dev:
    # The default target uses 'mode: development' to create a development copy.
    # - Deployed resources get prefixed with '[dev my_user_name]'
    # - Any job schedules and triggers are paused by default.
    # See also https://docs.databricks.com/dev-tools/bundles/deployment-modes.html.
    mode: development
    default: true
    workspace:
      host: {{workspace_host}}
    variables:
      warehouse_id: {{index ((regexp "[^/]+$").FindStringSubmatch .http_path) 0}}
      catalog: {{.default_catalog}}
      schema: {{$dev_schema}}

  prod:
    mode: production
    workspace:
      host: {{workspace_host}}
      # We explicitly specify /Workspace/Users/{{user_name}} to make sure we only have a single copy.
      root_path: /Workspace/Users/{{user_name}}/.bundle/${bundle.name}/${bundle.target}
    variables:
      warehouse_id: {{index ((regexp "[^/]+$").FindStringSubmatch .http_path) 0}}
      catalog: {{.default_catalog}}
      schema: {{$prod_schema}}
    permissions:
      - {{if is_service_principal}}service_principal{{else}}user{{end}}_name: {{user_name}}
        level: CAN_MANAGE
    run_as:
      {{if is_service_principal}}service_principal{{else}}user{{end}}_name: {{user_name}}
