aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 68723aa661801f56a6bf48f591ca4cb417e75b2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Bolt

[![Go Reference](https://pkg.go.dev/badge/git.eugenetriguba.com/bolt/cli.svg)](https://pkg.go.dev/git.eugenetriguba.com/bolt/cli)
![Version](https://img.shields.io/badge/version-0.14.0-blue)

Bolt is a command-line tool for database migrations.

## Why Bolt?

Bolt aims to be a simple and reliable tool that can work anywhere you need to
run database migrations.

- Schema migrations are written in plain SQL.
- Migrations are versioned sequentially.
- All migrations run in transactions by default.
- Supports up and down migrations and jumping to any particular schema version.
- Supports PostgreSQL, MySQL, SQL Server, and SQLite3.

## What It Looks Like

Migrations are separated by "up" and "down" comments to delineate what runs when
you apply the migration and what runs when you revert it.

```sql
-- migrate:up
CREATE TABLE posts (
    id SERIAL PRIMARY KEY,
    user_id INTEGER NOT NULL REFERENCES users(id),
    title VARCHAR(255) NOT NULL,
    content TEXT NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- migrate:down
DROP TABLE posts;
```

```bash
$ bolt status
Version    Message               Applied
0001       create_users_table    X
0002       create_posts_table    X
0003       add_email_index
```

## Installation

### From Source

Clone the repository:

```
git clone https://git.eugenetriguba.com/bolt/cli bolt
```

Build the binary:

```
cd bolt
make
```

Install the binary and man pages:

```
sudo make install
```

### Homebrew

If you're on macOS (or Linux and use Homebrew), you can install Bolt from the tap:

```bash
brew tap eugenetriguba/bolt https://git.eugenetriguba.com/bolt/homebrew-tap
brew install bolt
```

## Documentation

After installation, documentation is available via man pages.

### Commands

| Page | Description |
|------|-------------|
| bolt(1) | Main command overview |
| bolt-new(1) | Create a new migration |
| bolt-up(1) | Apply migrations |
| bolt-down(1) | Revert migrations |
| bolt-status(1) | List migration statuses |
| bolt-version(1) | Print version |
| bolt-help(1) | Show manual pages |

### File Formats

| Page | Description |
|------|-------------|
| bolt.toml(5) | Configuration file and environment variables |
| bolt-migration(5) | Migration script format |

### Concepts

| Page | Description |
|------|-------------|
| bolt-tutorial(7) | Getting started tutorial |
| bolt-databases(7) | Database drivers and DSN formats |
| bolt-execution(7) | How migrations are executed |

## License

MIT License. See [LICENSE](./LICENSE) for details.