You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-20Lines changed: 24 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -264,12 +264,12 @@ UPDATE my_table SET some=:'var1';
264
264
265
265
### Use Environment Variables
266
266
267
-
If you assign e.g. `process.env.HOSTS="{a,b,c}"` in your `pg-mig.config.ts` file, you can use that value in all of the version files using the standard `psql` feature:
267
+
If you assign e.g. `process.env.VAR="a,b,c"` (or return it) in your `pg-mig.config.ts` file, you can use that value in all of the version files using the standard `psql` feature:
268
268
269
269
```sql
270
270
-- mig/20231017204837.initial.public.up.sql
271
-
\set HOSTS`echo "$HOSTS"`
272
-
SELECTmy_function(:'HOSTS');
271
+
\set HOSTS`echo "$VAR"`
272
+
SELECTmy_function(:'VAR');
273
273
```
274
274
275
275
### More Meta-Commands
@@ -319,37 +319,41 @@ Here is the complete list of `-- $` pseudo comments that pg-mig supports in the
319
319
* `$parallelism_per_host=N`: as mentioned above, this option forces the parallel migrations for schemas on the same host to wait for each other, not allowing to run more than N of then at the same time.
320
320
* `$parallelism_global=N`: limits parallelism of this particular version _within the same schema prefix_ across all hosts.
321
321
* `$delay=M`: introduces a delay (in ms) between each migration. You can use it with `$parallelism_global` to reduce load on the database even further.
322
-
* `$run_alone=1`: if set to 1, no other migrations, _including other schema prefixes_, will run on any other host while this one is running. I.e. it introduces global ordering of the migration files application across schemas. This option is useful when you want to e.g. install a PostgreSQL extension used in other schemas, so you want all other schemas to wait until the installation finishes.
322
+
* `$run_alone=1`: if set to 1, no other migrations, _including other schema prefixes_, will run on any other host while this one is running. I.e. it introduces a global ordering of the migration files application across schemas. This option is useful when you want to e.g. install a PostgreSQL extension used in other schemas, so you want all other schemas to wait until the installation finishes.
323
323
324
324
## Advanced: Use With pg-microsharding Library
325
325
326
326
Overall, there are many popular alternatives to pg-mig when it comes to managing a single database with no sharding. But when it comes to migrating the entire cluster with multiple nodes, or working with microsharding, pg-mig starts shining.
327
327
328
-
The recommended library to manage the microshards schemas is [pg-microsharding](https://www.npmjs.com/package/@clickup/pg-microsharding). To couple it with pg-mig, create the following files:
328
+
The recommended library to manage the microshards schemas is [pg-microsharding](https://www.npmjs.com/package/@clickup/pg-microsharding). To couple it with pg-mig, create the following before/after scripts:
@@ -494,7 +498,7 @@ To help with this check, pg-mig exposes the concept called "version digest". It'
494
498
495
499
Digest is a string, and by comparing 2 digests lexicographically, you may make a decision, which one is "better" (or, if you don't want "better/worse" comparison, you can also compare them for strict equality). If the database's digest is **greater or equal to** the application code's digest, then the code is compatible to the currently existing cluster schema, so the code can be deployed ("your database is ahead of the code").
496
500
497
-
* Run `pg-mig --list=digest` to print the digest of the current migration files on disk (i.e. "code digest"), like `20250114061047.1552475c743aac017bf0252d540eb033859c6e`.
501
+
* Run `pg-mig --list=digest` to print the digest of the current migration files on disk (i.e. "code digest"), like `20250114061047.1552475c743aac01`.
498
502
* Use `loadDBDigest()` function exported by pg-mig Node library to extract the digest from the current databases used by the app (i.e. "database digest"). E.g. you can call it from your app's `/health` endpoint to allow querying the current database version digest from a deployment script or pipeline.
499
503
500
504
Every time the whole migration process succeeds, the digest is saved to _all database nodes_, so it can be later retrieved with `loadDBDigest()`. If you have multiple nodes managed by pg-mig, and they happen to appear out of sync, then this function will take care of choosing the most "sane" digest from those nodes, to let you compare it with the "code digest", with no single point of failure.
Copy file name to clipboardExpand all lines: docs/README.md
+24-20Lines changed: 24 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -268,12 +268,12 @@ UPDATE my_table SET some=:'var1';
268
268
269
269
### Use Environment Variables
270
270
271
-
If you assign e.g. `process.env.HOSTS = "{a,b,c}"`in your `pg-mig.config.ts` file, you can use that value in all of the version files using the standard `psql` feature:
271
+
If you assign e.g. `process.env.VAR = "a,b,c"` (or return it)in your `pg-mig.config.ts` file, you can use that value in all of the version files using the standard `psql` feature:
272
272
273
273
```sql
274
274
-- mig/20231017204837.initial.public.up.sql
275
-
\set HOSTS `echo "$HOSTS"`
276
-
SELECT my_function(:'HOSTS');
275
+
\set HOSTS `echo "$VAR"`
276
+
SELECT my_function(:'VAR');
277
277
```
278
278
279
279
### More Meta-Commands
@@ -323,37 +323,41 @@ Here is the complete list of `-- $` pseudo comments that pg-mig supports in the
323
323
*`$parallelism_per_host=N`: as mentioned above, this option forces the parallel migrations for schemas on the same host to wait for each other, not allowing to run more than Nof then at the same time.
324
324
*`$parallelism_global=N`: limits parallelism ofthis particular version _within the same schema prefix_ across all hosts.
325
325
*`$delay=M`: introduces a delay (in ms) between each migration. You can use it with`$parallelism_global` to reduce load on the database even further.
326
-
*`$run_alone=1`:if set to 1, no other migrations, _including other schema prefixes_, will run on any other host whilethis one is running. I.e. it introduces global ordering of the migration files application across schemas. This option is useful when you want to e.g. install a PostgreSQL extension used in other schemas, so you want all other schemas to wait until the installation finishes.
326
+
*`$run_alone=1`:if set to 1, no other migrations, _including other schema prefixes_, will run on any other host whilethis one is running. I.e. it introduces a global ordering of the migration files application across schemas. This option is useful when you want to e.g. install a PostgreSQL extension used in other schemas, so you want all other schemas to wait until the installation finishes.
327
327
328
328
## Advanced: Use With pg-microsharding Library
329
329
330
330
Overall, there are many popular alternatives to pg-mig when it comes to managing a single database with no sharding. But when it comes to migrating the entire cluster with multiple nodes, or working with microsharding, pg-mig starts shining.
331
331
332
-
The recommended library to manage the microshards schemas is [pg-microsharding](https://www.npmjs.com/package/@clickup/pg-microsharding). To couple it with pg-mig, create the following files:
332
+
The recommended library to manage the microshards schemas is [pg-microsharding](https://www.npmjs.com/package/@clickup/pg-microsharding). To couple it with pg-mig, create the following before/after scripts:
@@ -498,7 +502,7 @@ To help with this check, pg-mig exposes the concept called "version digest". It'
498
502
499
503
Digest is a string, and by comparing 2 digests lexicographically, you may make a decision, which one is "better" (or, if you don't want "better/worse" comparison, you can also compare them for strict equality). If the database's digest is **greater or equal to** the application code's digest, then the code is compatible to the currently existing cluster schema, so the code can be deployed ("your database is ahead of the code").
500
504
501
-
* Run `pg-mig --list=digest` to print the digest of the current migration files on disk (i.e. "code digest"), like `20250114061047.1552475c743aac017bf0252d540eb033859c6e`.
505
+
* Run `pg-mig --list=digest` to print the digest of the current migration files on disk (i.e. "code digest"), like `20250114061047.1552475c743aac01`.
502
506
* Use `loadDBDigest()` function exported by pg-mig Node library to extract the digest from the current databases used by the app (i.e. "database digest"). E.g. you can call it from your app's `/health` endpoint to allow querying the current database version digest from a deployment script or pipeline.
503
507
504
508
Every time the whole migration process succeeds, the digest is saved to _all database nodes_, so it can be later retrieved with `loadDBDigest()`. If you have multiple nodes managed by pg-mig, and they happen to appear out of sync, then this function will take care of choosing the most "sane" digest from those nodes, to let you compare it with the "code digest", with no single point of failure.
Copy file name to clipboardExpand all lines: docs/interfaces/MigrateOptions.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,4 +23,5 @@ Options for the migrate() function.
23
23
| <aid="createdb"></a> `createDB?`|`boolean`| If true, tries to create the given database. This is helpful when running the tool on a developer's machine. |
24
24
| <aid="parallelism"></a> `parallelism?`|`number`| How many schemas to process in parallel (defaults to 10). |
25
25
| <aid="dry"></a> `dry?`|`boolean`| If true, prints what it plans to do, but doesn't change anything. |
26
+
| <aid="force"></a> `force?`|`boolean`| If true, runs before/after files on apply even if nothing is changed. |
0 commit comments