Bytebase Automatic Transactions: Bytebase automatically wraps all SQL statements in a migration file within a single transaction. You typically don’t need to add explicit BEGIN/COMMIT statements.
When Bytebase’s automatic transactions are sufficient:
Single-file migrations with multiple statements
Standard DDL operations (CREATE, ALTER, DROP)
Simple DML operations (INSERT, UPDATE, DELETE)
When you might need explicit transaction control:
Batched operations requiring commits between chunks
Long-running data migrations that need progress checkpoints
Database-specific requirements like PostgreSQL’s CREATE INDEX CONCURRENTLY (which cannot run in a transaction)
Example of batched migration (when needed):
-- 015__batch_archive_logs_dml.sql-- Note: This uses explicit batching for large data operationDO $$DECLARE batch_size INT := 10000; deleted_count INT;BEGIN LOOP DELETE FROM logs WHERE id IN ( SELECT id FROM logs WHERE created_at < '2024-01-01' LIMIT batch_size ); GET DIAGNOSTICS deleted_count = ROW_COUNT; EXIT WHEN deleted_count < batch_size; COMMIT; -- Commit each batch PERFORM pg_sleep(0.1); -- Throttle END LOOP;END $$;
Database-specific transaction support:
✅ PostgreSQL: DDL in transactions (except CONCURRENTLY operations)
-- 020__migrate_legacy_permissions_dml.sql-- Migrates old role system to new permission model-- Old: roles.name -> New: permissions.scope + permissions.action-- Mapping:-- 'admin' -> 'database:*'-- 'editor' -> 'database:write'-- 'viewer' -> 'database:read'UPDATE permissionsSET scope = CASE WHEN roles.name = 'admin' THEN 'database' WHEN roles.name = 'editor' THEN 'database' WHEN roles.name = 'viewer' THEN 'database' END, action = CASE WHEN roles.name = 'admin' THEN '*' WHEN roles.name = 'editor' THEN 'write' WHEN roles.name = 'viewer' THEN 'read' ENDFROM rolesWHERE permissions.role_id = roles.id;
# Database Changelog## v2.0.0 (2025-01-20)- Added `user_preferences` table for customization- Migrated legacy role system to new permissions model- **Breaking**: Removed deprecated `user_settings` table## v1.5.0 (2025-01-15)- Added email column to users table- Created indexes on frequently queried columns