Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What is the purpose of the --bun:split line in SQL migrations


What is the purpose of the --bun:split line in SQL migrations


The `--bun:split` line in SQL migrations for Bun.js serves as a separator to allow the inclusion of multiple SQL statements within a single migration file. When this line is encountered, it indicates that the preceding SQL commands should be treated as one batch, while the commands following the `--bun:split` line will be executed as a separate batch.

This feature is particularly useful when you want to organize complex migrations that involve several SQL commands, ensuring that they can be executed in a structured manner. For example:

sql
SELECT 1;

--bun:split

SELECT 2;

In this example, the first `SELECT` statement will execute independently of the second one, which follows the split marker. This allows for better management and organization of migration scripts, especially when dealing with multiple operations that may need to be executed in sequence or separately[1].

Citations:
[1] https://bun.uptrace.dev/guide/migrations.html
[2] https://www.red-gate.com/simple-talk/databases/sql-server/database-administration-sql-server/using-migration-scripts-in-database-deployments/
[3] https://github.com/uptrace/bun/issues/41
[4] https://pkg.go.dev/github.com/uptrace/bun/example/migrate
[5] https://stackoverflow.com/questions/33166382/split-table-into-many-to-many-relationship-data-migration
[6] https://orm.drizzle.team/kit-docs/commands
[7] https://www.reddit.com/r/golang/comments/18g9w4a/what_does_your_company_use_for_migrations_and_db/
[8] https://dev.to/techschoolguru/how-to-write-run-database-migration-in-golang-5h6g