# Add any tasks that are not dependant on files in the .PHONY list
.PHONY: pipenv_dev test_integration run seed test clean

pipenv_dev:
	pipenv install --dev --ignore-pipfile
	pipenv run dbt deps

install_dbt_deps:
	pipenv run dbt deps

reset_snowflake_schema:
	pipenv run reset_snowflake_schema

test_integration_smart:
	$(MAKE) reset_snowflake_schema
	scripts/run_test_smart.sh

# Running integration tests involves seeding fixture data, running the views,
# then asserting against the actual values in the resulting views
test_integration:
	$(MAKE) clean
	$(MAKE) install_dbt_deps
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh mappings
	scripts/test_integration_models.sh data_availability
	scripts/test_integration_models.sh streams
	scripts/test_integration_models.sh metrics
	scripts/test_integration_models.sh operations
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh views
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh downloads
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh summary_demographics
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh summary_geographics_v2
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh summary_streams
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh point_of_sale
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh playlists

# Run integration tests for a specific package
# Example usage: make test_integration_package package=metrics
test_integration_package:
	$(MAKE) clean
	$(MAKE) install_dbt_deps
	$(MAKE) reset_snowflake_schema
	scripts/test_integration_models.sh $(package)

# Build views incrementally (or from scratch if they don't already exist)
run:
	scripts/run_seed.sh --target $${target:-profile}
	scripts/run_views.sh --target $${target:-profile} --models $${models:-*} --exclude $${exclude:-no_such_model}

# Build views from scratch
run_full_refresh:
	scripts/run_seed.sh --target $${target:-profile} --full-refresh
	scripts/run_views.sh --target $${target:-profile} --full-refresh --models $${models:-*} --exclude $${exclude:-no_such_model}

run_no_seed:
	scripts/run_views.sh --target $${target:-profile} --models $${models:-*} --exclude $${exclude:-no_such_model}

run_full_refresh_no_seed:
	scripts/run_views.sh --target $${target:-profile} --full-refresh --models $${models:-*} --exclude $${exclude:-no_such_model}

seed:
	pipenv run dbt seed --target $${target:-profile}

test:
	pipenv run dbt test --target test

test_unit:
	pipenv run dbt test -s 'test_type:unit' --target test

test_schema:
	pipenv run dbt test --schema --target test

list_models:
	pipenv run dbt ls --resource-type model --output name

# Remove directories produced by "dbt run"
clean:
	pipenv run dbt clean

generate_docs:
	pipenv run dbt deps
	pipenv run dbt docs generate --target test

serve_docs:
	pipenv run dbt docs serve
