summaryrefslogtreecommitdiff
path: root/README.md
blob: 69adb27240e3f2dfc89f4ce651b7601c59e0ea42 (plain)
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
# temp-postgres

The `temp-postgres` utility runs the [PostgreSQL](https://www.postgresql.org/) server off a temporary data directory.
See the [original blog post](https://www.skreutz.com/posts/temporary-postgresql-server/) for an introduction.

The project's source code is hosted on <https://git.skreutz.com/temp-postgres.git/>.

## Usage

Create and serve a temporary database:

```sh
temp-postgres
```

Wrap the `psql` command to connect to the temporary database once the server is ready:

```sh
temp-postgres -- psql
```

Run [SQLx integration tests](https://docs.rs/sqlx/latest/sqlx/attr.test.html) against a temporary database:

```sh
temp-postgres -- cargo test
```

Or configure `temp-postgres` as a wrapper for [cargo-nextest](https://nexte.st/):

```toml
experimental = ["wrapper-scripts"]

[scripts.wrapper.temp-postgres]
command = 'temp-postgres'

[[profile.default.scripts]]
platform = { host = 'cfg(unix)' }
run-wrapper = 'temp-postgres'
```

Set up a symlink to enable static client configuration:

```sh
temp-postgres --symlink ./db
psql --host "$(realpath ./db)"
```

Specify a database name, and PostgreSQL user name:

```sh
temp-postgres --dbname myproject --username alex
```


See the manual page for details.

## Dependencies

The `temp-postgres` utility depends on `sh(1)` and `postgres(1)`.

On OpenBSD you can install the dependencies using `pkg_add(1)`:

```sh
doas pkg_add postgresql-server postgresql-client
```

On FreeBSD you can install the dependencies using `pkg-install(8)`:

```sh
sudo pkg install postgresql16-server postgresql16-client
```

On Void Linux you can install the dependencies using `xbps-install(1)`:

```sh
sudo xbps-install -S dash postgresql postgresql-client
```

On Arch Linux you can install the dependencies using `pacman(8)`:

```sh
sudo pacman -Syu postgresql
```

## Installation

```sh
./configure
make
sudo make install
```

Alternatively you can run or install the experimental Nix flake:

```sh
nix run git+https://git.skreutz.com/temp-postgres.git -- --help
```

See the [NixOS example](./examples/nixos) for how to install `temp-postgres` on NixOS using Nix flakes.
Generated by cgit. See skreutz.com for my tech blog and contact information.