Function Signature
Description
Drops (deletes) an existing database. This is a destructive operation that permanently removes the database and all its data.Parameters
The database connection URL. The database name specified in the URL will be dropped:
- PostgreSQL:
postgres://user:password@host:port/database_name?sslmode=disable - MySQL:
mysql://root:password@localhost:3306/database_name - MariaDB:
mariadb://root:password@localhost:3307/database_name - SQLite:
sqlite://./database.sqlite(file will be deleted) - LibSQL: Should be dropped using the LibSQL/Turso interface
Authentication token for LibSQL/Turso databases. Use
None for other database types.Name of the migrations tracking table. This parameter is required for consistency but won’t matter since the database will be deleted.
Path to the migration files directory. Required for consistency with other operations.
Name of the schema dump file. Required for consistency with other operations.
Timeout in seconds to wait for the database server to be ready. Use
Some(30) for 30 seconds, or None for default timeout.Return Value
ReturnsResult<()> which:
- Returns
Ok(())if the database was dropped successfully - Returns
Errif there was a connection error, permission issue, or the database doesn’t exist
Usage Example
PostgreSQL Example
MySQL Example
Database-Specific Behavior
PostgreSQL, MySQL, MariaDB
- Connects to the database server
- Terminates any active connections to the database
- Drops the database and all its contents
- All tables, views, functions, and data are permanently deleted
SQLite
- Deletes the database file from the filesystem
- The file path is determined from the database URL
- Any associated WAL (Write-Ahead Logging) files are also removed
LibSQL/Turso
- LibSQL databases should be dropped using the Turso CLI or web interface
- Use the Turso CLI:
turso db destroy <database-name> - This function may not work for cloud-hosted LibSQL databases
Error Handling
The function may return errors in these cases:- Database server is unreachable
- Insufficient permissions to drop the database
- Database doesn’t exist
- Active connections preventing database deletion
- File system errors (for SQLite)
Safe Deletion Pattern
Here’s a recommended pattern for safely dropping a database with user confirmation:Testing Workflow
Common pattern for integration tests:See Also
- create_database - Create a new database
- dump_database - Backup database schema before dropping
- migrate_database - Run migrations