Skip to content

Commit 06e69c2

Browse files
Refactor docs (#510)
Signed-off-by: Alexis Rico <[email protected]> --------- Signed-off-by: Alexis Rico <[email protected]> Co-authored-by: Andrew Farries <[email protected]>
1 parent 34b623f commit 06e69c2

36 files changed

+1099
-888
lines changed

docs/cli-reference.md

Lines changed: 0 additions & 232 deletions
This file was deleted.

docs/cli/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Command line reference
2+
3+
The `pgroll` CLI has the following top-level flags:
4+
5+
- `--postgres-url`: The URL of the postgres instance against which migrations will be run.
6+
- `--schema`: The Postgres schema in which migrations will be run (default `"public"`).
7+
- `--pgroll-schema`: The Postgres schema in which `pgroll` will store its internal state (default: `"pgroll"`). One `--pgroll-schema` may be used safely with multiple `--schema`s.
8+
- `--lock-timeout`: The Postgres `lock_timeout` value to use for all `pgroll` DDL operations, specified in milliseconds (default `500`).
9+
- `--role`: The Postgres role to use for all `pgroll` DDL operations (default: `""`, which doesn't set any role).
10+
11+
Each of these flags can also be set via an environment variable:
12+
13+
- `PGROLL_PG_URL`
14+
- `PGROLL_SCHEMA`
15+
- `PGROLL_STATE_SCHEMA`
16+
- `PGROLL_LOCK_TIMEOUT`
17+
- `PGROLL_ROLE`
18+
19+
The CLI flag takes precedence if a flag is set via both an environment variable and a CLI flag.

docs/cli/complete.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Complete
3+
description: Complete a pgroll migration, removing the previous schema and leaving only the latest schema.
4+
---
5+
6+
## Command
7+
8+
```
9+
$ pgroll complete
10+
```
11+
12+
This completes the most recently started migration.
13+
14+
Running `pgroll complete` when there is no migration in progress is a no-op.
15+
16+
Completing a `pgroll` migration removes the previous schema version from the database (e.g. `public_02_create_table`), leaving only the latest version of the schema (e.g. `public_03_add_column`). At this point, any temporary columns and triggers created on the affected tables in the `public` schema will also be cleaned up, leaving the table schema in its final state. Note that the real schema (e.g. `public`) should never be used directly by the client as that is not safe; instead, clients should use the schemas with versioned views (e.g. `public_03_add_column`).
17+
18+
<Warning>
19+
Before running `pgroll complete` ensure that all applications that depend on
20+
the old version of the database schema are no longer live. Prematurely running
21+
`pgroll complete` can cause downtime of old application instances that depend
22+
on the old schema.
23+
</Warning>

docs/cli/init.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Init
3+
description: Initializes pgroll for first use.
4+
---
5+
6+
## Command
7+
8+
```
9+
$ pgroll init
10+
```
11+
12+
This will create a new schema in the database called `pgroll` (or whatever value is specified with the `--pgroll-schema` switch).
13+
14+
The tables and functions in this schema store `pgroll`'s internal state and are not intended to be modified outside of `pgroll` CLI.

docs/cli/latest.mdx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Latest
3+
description: Prints the latest schema version in either the target database or a local directory of migration files.
4+
---
5+
6+
## Command
7+
8+
By default, `pgroll latest` prints the latest version in the target database. Use the `--local` flag to print the latest version in a local directory of migration files instead.
9+
10+
In both cases, the `--with-schema` flag can be used to prefix the latest version with the schema name.
11+
12+
### Database
13+
14+
Assuming that the [example migrations](https://github.com/xataio/pgroll/tree/main/examples) have been applied to the `public` schema in the target database, running:
15+
16+
```
17+
$ pgroll latest
18+
```
19+
20+
will print the latest version in the target database:
21+
22+
```
23+
45_add_table_check_constraint
24+
```
25+
26+
The exact output will vary as the `examples/` directory is updated.
27+
28+
### Local
29+
30+
Assuming that the [example migrations](https://github.com/xataio/pgroll/tree/main/examples) are on disk in a directory called `examples`, running:
31+
32+
```
33+
$ pgroll latest --local examples/
34+
```
35+
36+
will print the latest migration in the directory:
37+
38+
```
39+
45_add_table_check_constraint
40+
```
41+
42+
The exact output will vary as the `examples/` directory is updated.

docs/cli/migrate.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Migrate
3+
description: Applies all outstanding migrations from a directory to the target database.
4+
---
5+
6+
## Command
7+
8+
Assuming that migrations up to and including migration `40_create_enum_type` from the [example migrations](https://github.com/xataio/pgroll/tree/main/examples) directory have been applied, running:
9+
10+
```
11+
$ pgroll migrate examples/
12+
```
13+
14+
will apply migrations from `41_add_enum_column` onwards to the target database.
15+
16+
If the `--complete` flag is passed to `pgroll migrate` the final migration to be applied will be completed. Otherwise the final migration will be left active (started but not completed).

docs/cli/pull.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Pull
3+
description: Pull the complete schema history of applied migrations from the target database and write the migrations to disk.
4+
---
5+
6+
## Command
7+
8+
Assuming that all [example migrations](https://github.com/xataio/pgroll/tree/main/examples) have been applied, running:
9+
10+
```
11+
$ pgroll pull migrations/
12+
```
13+
14+
will write the complete schema history as `.json` files to the `migrations/` directory:
15+
16+
```
17+
$ ls migrations/
18+
19+
01_create_tables.json
20+
02_create_another_table.json
21+
03_add_column_to_products.json
22+
04_rename_table.json
23+
05_sql.json
24+
06_add_column_to_sql_table.json
25+
...
26+
```
27+
28+
The command takes an optional `--with-prefixes` flag which will write each filename prefixed with its position in the schema history:
29+
30+
```
31+
$ ls migrations/
32+
33+
0001_01_create_tables.json
34+
0002_02_create_another_table.json
35+
0003_03_add_column_to_products.json
36+
0004_04_rename_table.json
37+
0005_05_sql.json
38+
0006_06_add_column_to_sql_table.json
39+
...
40+
```
41+
42+
The `--with-prefixes` flag ensures that files are sorted lexicographically by their time of application.
43+
44+
If the directory specified as the required argument to `pgroll pull` does not exist, `pgroll pull` will create it.

0 commit comments

Comments
 (0)