This directory contains utility scripts for managing your Dune dbt project.
Drops tables and views in a Dune schema via the Trino API endpoint.
This script connects to the Dune Trino API using the same configuration as dbt and drops tables and views based on:
- Target environment (dev or prod)
dev(default): Drops all tables matching{DUNE_TEAM_NAME}__tmp_%pattern (bulk drops allowed)prod: Only allows dropping ONE specific table/view at a time (requires--schemaand--table)
- Schema pattern matching (dev only - override with
--schemafor custom patterns) - Specific table/view (drop a single table or view)
The script uses INFORMATION_SCHEMA.TABLES to find tables and generates appropriate DROP TABLE or DROP VIEW commands based on the object type.
- Trino's
DROP TABLEcommand only removes the metastore entry, leaving orphaned data in S3 - S3 cleanup should be handled separately via scheduled cleanup jobs
- This script does not clean up S3 data (requires separate AWS access)
Production Safety:
- Prod drops require BOTH
--schemaAND--table(no bulk drops) - Interactive confirmation is required before executing prod drops
- This ensures prod drops are deliberate, specific, and rare
- Ensure you have set the
DUNE_API_KEYenvironment variable - Optionally set
DUNE_TEAM_NAMEenvironment variable (defaults to 'dune') - Install dependencies:
uv sync
By default, the script uses dev target and matches all schemas starting with {DUNE_TEAM_NAME}__tmp_:
# Dry run - drops all tables in dev schemas matching dune__tmp_*
# This includes dune__tmp_, dune__tmp_pr123, dune__tmp_jeff, etc.
python scripts/drop_tables.py
# Execute - actually drop dev tables
python scripts/drop_tables.py --executeDev pattern matching uses SQL LIKE: The pattern dune__tmp_% will match:
dune__tmp_(exact match)dune__tmp_pr123(with PR number suffix)dune__tmp_alice(with user suffix)- Any other schema starting with
dune__tmp_
--schema AND --table.
You can only drop one specific table/view at a time in prod. Bulk drops are not allowed.
# Dry run - drop specific prod table
python scripts/drop_tables.py --target prod --schema dune --table my_table
# Execute - drop specific prod table (REQUIRES CONFIRMATION)
python scripts/drop_tables.py --target prod --schema dune --table my_table --execute--target prod with --execute:
- You MUST specify both
--schemaand--table(no pattern matching) - Script confirms the specific table that will be dropped
- Requires you to type
yesto confirm - Operation is cancelled if you type anything else or press Ctrl+C
This restriction ensures prod drops are deliberate, specific, and rare.
Drop all tables in a specific schema (exact match):
# Dry run - show what would be dropped
python scripts/drop_tables.py --schema my_custom_schema
# Execute - actually drop the tables
python scripts/drop_tables.py --schema my_custom_schema --executeDrop a single table or view:
# Dry run - show what would be dropped
python scripts/drop_tables.py --table my_table_name --schema my_schema
# Execute - actually drop the table
python scripts/drop_tables.py --table my_table_name --schema my_schema --executeNote: When dropping a specific table, you must provide the exact schema name (not a pattern).
# Verbose logging for debugging
python scripts/drop_tables.py --verbose
# Specify API key directly (instead of using env var)
python scripts/drop_tables.py --execute --api-key YOUR_API_KEY_HERE| Argument | Description | Default |
|---|---|---|
--target |
Target environment: dev or prod |
dev |
--schema |
Schema name or pattern (overrides --target) |
None (uses target default) |
--table |
Specific table/view name (requires --schema) |
None (drops all) |
--execute |
Execute the drop operations (default is dry-run) | False |
--api-key |
Dune API key | DUNE_API_KEY env var |
--verbose, -v |
Enable verbose (debug) logging | False |
Target Defaults:
dev: Uses schema pattern{DUNE_TEAM_NAME}__tmp_%(matches all dev schemas)prod: Uses schema{DUNE_TEAM_NAME}(exact production schema)
# Drop all dev tables (dry run - default target)
python scripts/drop_tables.py
# Drop all dev tables (execute)
python scripts/drop_tables.py --execute
# Drop all tables in specific dev schema (dry run)
python scripts/drop_tables.py --schema dune__tmp_pr123
# Drop all tables in specific dev schema (execute)
python scripts/drop_tables.py --schema dune__tmp_pr123 --execute
# Drop specific dev table (dry run)
python scripts/drop_tables.py --table my_model --schema dune__tmp_jeff
# Drop specific dev table (execute)
python scripts/drop_tables.py --table my_model --schema dune__tmp_jeff --execute
# Drop specific PROD table (dry run - REQUIRES --schema AND --table)
python scripts/drop_tables.py --target prod --schema dune --table my_model
# Drop specific PROD table (execute - REQUIRES CONFIRMATION)
python scripts/drop_tables.py --target prod --schema dune --table my_model --execute
# Drop with custom pattern (any dev schema starting with 'test_')
python scripts/drop_tables.py --schema test_% --execute
# Verbose output for debugging
python scripts/drop_tables.py --verboseShows all DROP commands that would be executed:
2025-11-09 15:12:47 - __main__ - WARNING - ================================================================================
2025-11-09 15:12:47 - __main__ - WARNING - DRY RUN MODE - No operations will be executed
2025-11-09 15:12:47 - __main__ - WARNING - To execute operations, add the --execute flag
2025-11-09 15:12:47 - __main__ - WARNING - ================================================================================
2025-11-09 15:12:47 - __main__ - INFO - Target: All tables matching schema pattern 'dune__tmp_%'
2025-11-09 15:12:47 - __main__ - INFO - Initialized Dune Trino connection config (host=trino.api.dune.com, catalog=dune)
2025-11-09 15:12:47 - __main__ - INFO - Connecting to Dune Trino API...
2025-11-09 15:12:47 - __main__ - INFO - Successfully connected to Dune Trino API
2025-11-09 15:12:47 - __main__ - INFO - Querying tables matching schema pattern: dune__tmp_%
2025-11-09 15:12:49 - __main__ - INFO - ================================================================================
2025-11-09 15:12:49 - __main__ - INFO - Preparing to drop 305 table(s)/view(s)
2025-11-09 15:12:49 - __main__ - INFO - ================================================================================
2025-11-09 15:12:49 - __main__ - INFO - DROP: drop table if exists dune.dune__tmp_jeff.my_table
2025-11-09 15:12:49 - __main__ - INFO - DROP: drop view if exists dune.dune__tmp_jeff.my_view
2025-11-09 15:12:49 - __main__ - INFO - DROP: drop table if exists dune.dune__tmp_pr123.another_table
...
2025-11-09 15:12:49 - __main__ - INFO - ================================================================================
2025-11-09 15:12:49 - __main__ - INFO - Drop summary: 305 successful, 0 failed
2025-11-09 15:12:49 - __main__ - INFO - ================================================================================
2025-11-09 15:12:49 - __main__ - INFO -
2025-11-09 15:12:49 - __main__ - INFO - ================================================================================
2025-11-09 15:12:49 - __main__ - INFO - DRY RUN COMPLETE
2025-11-09 15:12:49 - __main__ - INFO - Above are the DROP commands that would be executed.
2025-11-09 15:12:49 - __main__ - INFO - Use --execute flag to actually drop the tables/views.
2025-11-09 15:12:49 - __main__ - INFO - ================================================================================
2025-11-09 15:12:49 - __main__ - INFO - Connection closed
When executing with --execute, each drop is confirmed with ✓ or ✗:
2025-11-09 15:15:00 - __main__ - INFO - DROP: drop table if exists dune.dune__tmp_jeff.my_table
2025-11-09 15:15:01 - __main__ - INFO - ✓ Successfully dropped: dune__tmp_jeff.my_table
2025-11-09 15:15:01 - __main__ - INFO - DROP: drop view if exists dune.dune__tmp_jeff.my_view
2025-11-09 15:15:02 - __main__ - INFO - ✓ Successfully dropped: dune__tmp_jeff.my_view
...
2025-11-09 15:15:10 - __main__ - INFO - ================================================================================
2025-11-09 15:15:10 - __main__ - INFO - Drop summary: 305 successful, 0 failed
2025-11-09 15:15:10 - __main__ - INFO - ================================================================================
The script uses the following connection configuration (matching profiles.yml):
- Host:
trino.api.dune.com - Port:
443 - User:
dune(fixed) - Catalog:
dune(fixed) - Authentication: Basic auth with DUNE_API_KEY
- HTTP Scheme: HTTPS
- Session Properties:
transformations: true
- Reads
DUNE_API_KEYandDUNE_TEAM_NAMEfrom environment variables - Establishes a connection to Dune's Trino API endpoint
- Queries
INFORMATION_SCHEMA.TABLESbased on the target:- Pattern mode: Uses
LIKEto match schema names (e.g.,dune__tmp_%) - Specific schema: Queries exact schema name
- Specific table: Queries for exact schema and table name
- Pattern mode: Uses
- For each table/view found:
- Generates appropriate
DROP TABLEorDROP VIEWcommand based on type - Logs the DROP command (visible in both dry run and execute modes)
- If
--executeflag is set, executes the DROP command
- Generates appropriate
- Displays a summary of successful and failed drops
- Closes the connection
Pattern Matching Behavior:
- Default pattern
{DUNE_TEAM_NAME}__tmp_%matches all dev schemas - The
%wildcard matches any characters (including none) - You can provide custom patterns with
--schema(e.g.,test_%,staging_%)
This approach is particularly useful for:
- Cleaning up all dev schemas at once (including PR schemas)
- Cleaning up after CI/CD test runs
- Removing temporary tables from pattern-matched schemas
- Dry run by default: Prevents accidental deletions
- Clear logging: All DROP commands are displayed before execution
- Pattern visibility: Shows which schemas are matched before dropping
- Summary reporting: Confirms what was dropped and if any failures occurred
- Uses
IF EXISTS: DROP commands won't fail if table doesn't exist