An open API service indexing awesome lists of open source software.

https://github.com/winebarrel/qrev

qrev is a SQL execution history management tool.
https://github.com/winebarrel/qrev

database golang mysql postgresql sqlite

Last synced: 12 days ago
JSON representation

qrev is a SQL execution history management tool.

Awesome Lists containing this project

README

          

# qrev

[![test](https://github.com/winebarrel/qrev/actions/workflows/test.yml/badge.svg)](https://github.com/winebarrel/qrev/actions/workflows/test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/winebarrel/qrev)](https://goreportcard.com/report/github.com/winebarrel/qrev)

qrev is a SQL execution history management tool.

![](https://github.com/user-attachments/assets/f7ef2da9-b140-4ac8-aeaa-fc5623c6ef3c)

## Installation

```sh
brew install winebarrel/qrev/qrev
```

## Usage

```
Usage: qrev --dsn=STRING [flags]

Flags:
-h, --help Show context-sensitive help.
-d, --dsn=STRING DSN for the database to connect to ($QREV_DSN).
--timeout=3m Transaction timeout duration ($QREV_TIMEOUT).
--[no-]iam-auth Use RDS IAM authentication ($QREV_IAM_AUTH).
-C, --[no-]color Colorize output ($QREV_COLOR).
--version

Commands:
apply --dsn=STRING [] [flags]
Apply SQL files to the database and record their execution history.

init --dsn=STRING [flags]
Initialize the SQL execution history table in the database.

mark --dsn=STRING [flags]
Manually mark the status of a SQL file (e.g., done, fail) in the history.

plan --dsn=STRING [] [flags]
Show the list of SQL files that are planned to be executed.

status --dsn=STRING [] [flags]
Display the execution status of SQL files, optionally filtered by status or
filename.

Run "qrev --help" for more information on a command.
```

```
$ echo 'SELECT 1' > 001.sql
$ echo 'SELECT now()' > 002.sql
$ echo 'SELECT CURRENT_DATE' > 003.sql
$ export QREV_DSN='file:test.db'

$ qrev init
qrev_history table has been created

$ qrev status
No SQL history

$ qrev plan
001.sql SELECT 1
002.sql SELECT now()
003.sql SELECT CURRENT_DATE

$ qrev apply
done 001.sql SELECT 1
fail 002.sql SELECT now()
│ SQL logic error: no such function: now (1)
qrev: error: SQL fails

$ qrev status --show-error
Oct 12 15:40 done a0a22c9 001.sql
Oct 12 15:40 fail df4776a 002.sql
│ SQL logic error: no such function: now (1)

$ qrev plan --if-modified
003.sql SELECT CURRENT_DATE

$ echo 'SELECT CURRENT_TIMESTAMP' > 002.sql
$ qrev plan --if-modified
002.sql* SELECT CURRENT_TIMESTAMP
003.sql SELECT CURRENT_DATE

$ qrev apply --if-modified
done 002.sql SELECT CURRENT_TIMESTAMP
done 003.sql SELECT CURRENT_DATE

$ qrev apply --if-modified
No SQL file to run

$ qrev status
Oct 12 15:40 done a0a22c9 001.sql
Oct 12 15:40 done 45fb14e 002.sql
Oct 12 15:40 done e8d881b 003.sql
```

### DSN

* MySQL: https://pkg.go.dev/github.com/go-sql-driver/mysql#readme-dsn-data-source-name
* PostgreSQL: https://pkg.go.dev/github.com/jackc/pgx/v5/stdlib#pkg-overview