From 2212743dcf34fa34aeebbb2292152cc4d9d6dcdf Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 13 Jan 2024 23:21:39 -0500 Subject: Add support for turning off transaction execution --- README.md | 21 +++++ internal/repositories/migration_db_repo.go | 107 +++++++++++++++++------- internal/repositories/migration_db_repo_test.go | 55 ++++++++++++ internal/sqlparse/sqlparse.go | 44 ++++++++++ internal/sqlparse/sqlparse_test.go | 56 +++++++++++++ 5 files changed, 251 insertions(+), 32 deletions(-) create mode 100644 internal/sqlparse/sqlparse.go create mode 100644 internal/sqlparse/sqlparse_test.go diff --git a/README.md b/README.md index e89e4f4..68da9f7 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Bolt is a command-line tool designed to simplify and streamline your database mi - [Downgrading Your Migration](#downgrading-your-migration) - [Verifying Migration Reversion](#verifying-migration-reversion) - [Next Steps](#next-steps) +- [How-to](#how-to) + - [How to execute a migration script without a transaction](#how-to-execute-a-migration-script-without-a-transaction) - [Reference](#reference) - [Database Compatibility](#database-compatibility) - [Configuration](#configuration) @@ -38,6 +40,7 @@ Bolt is a command-line tool designed to simplify and streamline your database mi - [`bolt up`](#bolt-up) - [`bolt down`](#bolt-down) - [`bolt status`](#bolt-status) + - [Script Execution Options](#script-execution-options) - [Explanation](#explanation) - [How Are Migration Scripts Executed?](#how-are-migration-scripts-executed) - [How Does Bolt Know What Migrations Have Been Applied?](#how-does-bolt-know-what-migrations-have-been-applied) @@ -214,6 +217,16 @@ bolt_tutorial_db=# \dt Congrats! You've learned the core features of Bolt. If you want learn more, see the [Reference](#reference) or [Explanation](#explanation) section. +## How-to + +### How to execute a migration script without a transaction + +In your `upgrade.sql` or `downgrade.sql`, add the following line as the first line of your script: + +```sql +-- bolt: no-transaction +``` + ## Reference ### Database Compatibility @@ -315,6 +328,14 @@ status: List the database migrations and their statuses ``` +### Script Execution Options + +Bolt provides a way for you to customize how your migration scripts are executed if you need something different than the default behavior. + +You can do this by adding a comment to the top of your migration script. The comment must be in the following format: `-- bolt: