Skip to content

Conversation

koleo
Copy link
Contributor

@koleo koleo commented Aug 26, 2025

sql-migrate "status" command displays applied and unapplied migrations in a pretty "table" format. Pretty for humans, but not suited for automation.

Introducing a new optional parameter --output to handle JSON output format.

Tests

Show help

% ~/go/bin/sql-migrate status --help
Usage: sql-migrate status [options] ...

  Show migration status.

Options:

  -config=dbconfig.yml   Configuration file to use.
  -env="development"     Environment.
  -output="json"         Print output in JSON format (default is table format).

No migration applied

$ ~/go/bin/sql-migrate status
+-----------+---------+
| MIGRATION | APPLIED |
+-----------+---------+
| 1.sql     | no      |
| 2.sql     | no      |
+-----------+---------+

$ ~/go/bin/sql-migrate status --output json
[
  {
    "migration": "1.sql",
    "applied": "no"
  },
  {
    "migration": "2.sql",
    "applied": "no"
  }
]

Migration applied

$ ~/go/bin/sql-migrate up -limit 1
Applied 1 migration

$ ~/go/bin/sql-migrate status
+-----------+---------------------+
| MIGRATION |       APPLIED       |
+-----------+---------------------+
| 1.sql     | 2025-08-26 16:51:28 |
| 2.sql     | no                  |
+-----------+---------------------+

$ ~/go/bin/sql-migrate status --output json
[
  {
    "migration": "1.sql",
    "applied": "2025-08-26T16:51:28+02:00"
  },
  {
    "migration": "2.sql",
    "applied": "no"
  }
]

Default output

Only --output JSON will output in JSON format

$ ~/go/bin/sql-migrate status --output table
+-----------+---------------------+
| MIGRATION |       APPLIED       |
+-----------+---------------------+
| 1.sql     | 2025-08-26 16:51:28 |
| 2.sql     | no                  |
+-----------+---------------------+
$ ~/go/bin/sql-migrate status --output anything
+-----------+---------------------+
| MIGRATION |       APPLIED       |
+-----------+---------------------+
| 1.sql     | 2025-08-26 16:51:28 |
| 2.sql     | no                  |
+-----------+---------------------+

@rubenv
Copy link
Owner

rubenv commented Aug 26, 2025

@koleo Any reason in particular why you're automating things from bash, as opposed to using sql-migrate as a library in your application?

Signed-off-by: Nicolas Payart <npayart@gmail.com>
@koleo
Copy link
Contributor Author

koleo commented Sep 2, 2025

@rubenv I mainly use sql-migrate as a library.
I reported the output=json option to sql-migrate as it could still be useful in certain situations.
However, if you think it's irrelevant, feel free to discard the pull request! (I just fixed the build lint)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants