
## AppsFlyer Tables Troubleshooting
### Background
- AppsFlyer's database contains views. In SUNO_PROD.PROD, we should have a corresponding table for each view.
- AppsFlyer's data sharing instance only contains data for the last 14 days. To preserve the history of our data, we must regularly dump their data into SUNO_PROD for historical analysis.
  - We have Snowflake daily tasks set up for this. They start with the prefix `AF_`.
- Sometimes AppsFlyer may add tables or columns to their database instance. This shouldn't happen too often, but when it does we must update our Snowflake tables and tasks to accommodate.

### When you receive a Slack alert indicating disparity between APPSFLYER and SUNO_PROD
1. Run `uv run scripts/appsflyer/diff_af_tables.py --apply-changes`. This performs a diff between the `APPSLFYER.SNOWFLAKE.*` and `SUNO_PROD.PROD.AF_*` table schemas and asks if you want to apply the changes to your repo and Snowflake to make them in sync.
2. If APPSFLYER has tables SUNO_PROD doesn't:
   1. Follow the instructions in the script to apply changes. Create a PR for any changes.
   2. Add the task to `daily_job_procedure.sql` to ensure #data-alerts is notified of any failures to this new task.
   3. Merge your PR.
   4. Deploy this task by running `uv run deploy_local_changes.py --file <task file>`
   5. Deploy changes to `daily_job_procedure.sql` with the same command format as above.
   6. Resume the updated tasks with `uv run resume_task.py --name <task name>`
3. If an APPSFLYER table has columns SUNO_PROD doesn't:
   1. Follow the instructions in the script to apply changes. Create a PR for any changes.
   2. Merge your PR.
