@shivaedev/local-postgres 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +26 -13
- package/dist/server/PostgresVersionMismatch.d.ts +7 -0
- package/dist/server/PostgresVersionMismatch.d.ts.map +1 -0
- package/dist/server/PostgresVersionMismatch.js +10 -0
- package/dist/server/PostgresVersionMismatch.js.map +1 -0
- package/dist/server/localPostgres.d.ts.map +1 -1
- package/dist/server/localPostgres.js +2 -1
- package/dist/server/localPostgres.js.map +1 -1
- package/package.json +3 -3
- package/src/server/PostgresVersionMismatch.ts +10 -0
- package/src/server/localPostgres.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 - 2026-10-19
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `PostgresVersionMismatch` from `@shivaedev/local-postgres/PostgresVersionMismatch.ts` identifies a refused running version through `_tag`, `expectedVersion` and `observedVersion`, retaining the existing error message.
|
|
8
|
+
|
|
9
|
+
## 0.4.2 - 2026-10-18
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Setup scripts whose database names come from configured URLs no longer need their own name check; rely on preparation's local-target check. Keep an independent allowlist for setup scripts that own fixed database names.
|
|
14
|
+
|
|
3
15
|
## 0.4.1 - 2026-10-18
|
|
4
16
|
|
|
5
17
|
### Changed
|
package/README.md
CHANGED
|
@@ -7,14 +7,13 @@ Make development and integration tests share one persistent local PostgreSQL ser
|
|
|
7
7
|
A setup command should make a machine ready to work without erasing the work already on it. Reimplementing PostgreSQL startup in every repository makes that promise harder to keep. This package gives a setup script one place to prepare the service and its databases:
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import {
|
|
10
|
+
import { localPostgres, localServer } from "@shivaedev/local-postgres/localPostgres.ts";
|
|
11
11
|
|
|
12
|
-
const development = `${localServer}/example_dev`;
|
|
13
|
-
assertLocalDatabase(development, ["example_dev"]);
|
|
12
|
+
const development = process.env.DATABASE_URL ?? `${localServer}/example_dev`;
|
|
14
13
|
localPostgres(process.env).prepareDatabases([development]);
|
|
15
14
|
```
|
|
16
15
|
|
|
17
|
-
The application
|
|
16
|
+
The application supplies its configured database URL. Preparation checks that the target is local and can run again without losing the data already in the database.
|
|
18
17
|
|
|
19
18
|
## Using it
|
|
20
19
|
|
|
@@ -23,12 +22,29 @@ The application chooses `example_dev`. Preparation can run again without losing
|
|
|
23
22
|
There are three separate responsibilities:
|
|
24
23
|
|
|
25
24
|
1. The **service** is PostgreSQL running on the local machine. This package prepares access to it.
|
|
26
|
-
2. A **database** is an application-chosen name on that service. This package creates missing databases; the application
|
|
25
|
+
2. A **database** is an application-chosen name on that service. This package creates missing databases; the application chooses their names through configuration or a fixed allowlist.
|
|
27
26
|
3. The **schema and data** belong to the application. Its setup script runs migrations, loads fixtures or seeds data after preparation.
|
|
28
27
|
|
|
29
28
|
`localPostgres(environment)` returns three synchronous functions: `startPostgres`, `prepareDatabases` and `sql`. Use them in setup tooling. Use your application's database client and `@shivaedev/effect-sql` for persistence and migrations in an Effect application.
|
|
30
29
|
|
|
31
|
-
### 1. Once per application: choose
|
|
30
|
+
### 1. Once per application: choose the databases
|
|
31
|
+
|
|
32
|
+
`prepareDatabases`, `startPostgres` and `sql` each reject remote hosts, ports other than 55432 and redirecting connection parameters: `host`, `hostaddr`, `port`, `dbname` and `service`. Setup scripts can rely on these local-target checks.
|
|
33
|
+
|
|
34
|
+
When database names come from the application's configured URLs, pass those URLs directly to preparation:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { localPostgres, localServer } from "@shivaedev/local-postgres/localPostgres.ts";
|
|
38
|
+
|
|
39
|
+
const development = process.env.DATABASE_URL ?? `${localServer}/example_dev`;
|
|
40
|
+
const tests = process.env.TEST_DATABASE_URL ?? `${localServer}/example_test`;
|
|
41
|
+
|
|
42
|
+
localPostgres(process.env).prepareDatabases([development, tests]);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Generated applications use this configuration-driven approach. An allowlist built from the same URLs adds no restriction; preparation's own local-target check is the guard.
|
|
46
|
+
|
|
47
|
+
Use `assertLocalDatabase` when the setup script owns a fixed set of database names, as this repository's `script/setup-database.ts` does. Its allowlist restricts configuration to the names the script intends to touch:
|
|
32
48
|
|
|
33
49
|
```ts
|
|
34
50
|
import { assertLocalDatabase, localPostgres, localServer } from "@shivaedev/local-postgres/localPostgres.ts";
|
|
@@ -43,9 +59,7 @@ const postgres = localPostgres(process.env);
|
|
|
43
59
|
postgres.prepareDatabases([development, tests]);
|
|
44
60
|
```
|
|
45
61
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Keep the explicit name checks even though the preparation functions check their destinations. The application's allowlist says which database it intends to touch; service preparation does not choose that policy for it.
|
|
62
|
+
`assertLocalDatabase` applies the same local-target checks and also rejects a database name outside the caller's allowlist. The fixed names above provide an independent application policy.
|
|
49
63
|
|
|
50
64
|
### 2. Once per feature: prepare its schema in application tooling
|
|
51
65
|
|
|
@@ -54,10 +68,9 @@ After `prepareDatabases`, run the application's own schema or migration entry po
|
|
|
54
68
|
### 3. In daily setup: prepare again and inspect with SQL
|
|
55
69
|
|
|
56
70
|
```ts
|
|
57
|
-
import {
|
|
71
|
+
import { localPostgres, localServer } from "@shivaedev/local-postgres/localPostgres.ts";
|
|
58
72
|
|
|
59
|
-
const database = `${localServer}/example_dev`;
|
|
60
|
-
assertLocalDatabase(database, ["example_dev"]);
|
|
73
|
+
const database = process.env.DATABASE_URL ?? `${localServer}/example_dev`;
|
|
61
74
|
|
|
62
75
|
const postgres = localPostgres(process.env);
|
|
63
76
|
postgres.prepareDatabases([database]);
|
|
@@ -101,7 +114,7 @@ The shared baseline is PostgreSQL 18.6 on loopback port 55432. Docker preparatio
|
|
|
101
114
|
postgres:18.6-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873
|
|
102
115
|
```
|
|
103
116
|
|
|
104
|
-
A newly created container uses username and password `postgres`; connection URLs supply credentials for client commands. Setup
|
|
117
|
+
A newly created container uses username and password `postgres`; connection URLs supply credentials for client commands. Setup refuses a running version other than 18.6 with `PostgresVersionMismatch` from `@shivaedev/local-postgres/PostgresVersionMismatch.ts`. The error carries `_tag: "PostgresVersionMismatch"`, `expectedVersion` and `observedVersion`. A running PostgreSQL 17 service is refused without losing its existing rows; upgrading it while preserving its data is your job. Container preparation and container-client fallback also check the managed image; a successful host-`psql` version probe does not inspect that image.
|
|
105
118
|
|
|
106
119
|
Pass the process's actual Docker settings to `localPostgres`, as `process.env` in the examples does. With `DOCKER_CONTEXT`, endpoint validation uses that context and ignores `DOCKER_HOST`; otherwise it validates `DOCKER_HOST` or the active context. Remote endpoints are rejected before a Docker operation. Docker subprocesses inherit the process environment. Supplying a different object does not configure those subprocesses.
|
|
107
120
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class PostgresVersionMismatch extends Error {
|
|
2
|
+
readonly _tag = "PostgresVersionMismatch";
|
|
3
|
+
readonly expectedVersion = "18.6";
|
|
4
|
+
readonly observedVersion: string | undefined;
|
|
5
|
+
constructor(observedVersion: string | undefined);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=PostgresVersionMismatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresVersionMismatch.d.ts","sourceRoot":"","sources":["../../src/server/PostgresVersionMismatch.ts"],"names":[],"mappings":"AAAA,qBAAa,uBAAwB,SAAQ,KAAK;IACjD,QAAQ,CAAC,IAAI,6BAA6B;IAC1C,QAAQ,CAAC,eAAe,UAAU;IAClC,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7C,YAAY,eAAe,EAAE,MAAM,GAAG,SAAS,EAG9C;CACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class PostgresVersionMismatch extends Error {
|
|
2
|
+
_tag = "PostgresVersionMismatch";
|
|
3
|
+
expectedVersion = "18.6";
|
|
4
|
+
observedVersion;
|
|
5
|
+
constructor(observedVersion) {
|
|
6
|
+
super("Expected local PostgreSQL 18.6. Check the existing service; setup never removes containers or data.");
|
|
7
|
+
this.observedVersion = observedVersion;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=PostgresVersionMismatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresVersionMismatch.js","sourceRoot":"","sources":["../../src/server/PostgresVersionMismatch.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACxC,IAAI,GAAG,yBAAyB,CAAC;IACjC,eAAe,GAAG,MAAM,CAAC;IACzB,eAAe,CAAqB;IAE7C,YAAY,eAAmC;QAC9C,KAAK,CAAC,qGAAqG,CAAC,CAAC;QAC7G,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACxC,CAAC;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localPostgres.d.ts","sourceRoot":"","sources":["../../src/server/localPostgres.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,EAAU,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"localPostgres.d.ts","sourceRoot":"","sources":["../../src/server/localPostgres.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,EAAU,MAAM,kBAAkB,CAAC;AAGlE,eAAO,MAAM,WAAW,mDAAmD,CAAC;AAE5E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,qBAY1E;AAQD,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,iBAAiB,EAAE,EAAE,QAAa,EAAE,WAAkB,EAAE,GAAE,gBAAqB;+BAmEvF,SAAS,MAAM,EAAE;iBA/D/B,MAAM,GAAG,GAAG,SAAS,MAAM;;EAmF/C"}
|
|
@@ -3,6 +3,7 @@ import { env } from "node:process";
|
|
|
3
3
|
import { ensureConnections } from "./localConnections.js";
|
|
4
4
|
import { sqlInContainer, startContainer } from "./localContainer.js";
|
|
5
5
|
import { docker } from "./localDocker.js";
|
|
6
|
+
import { PostgresVersionMismatch } from "./PostgresVersionMismatch.js";
|
|
6
7
|
export const localServer = "postgresql://postgres:postgres@127.0.0.1:55432";
|
|
7
8
|
export function assertLocalDatabase(value, names) {
|
|
8
9
|
const url = new URL(value);
|
|
@@ -69,7 +70,7 @@ export function localPostgres(environment, { attempts = 30, delayMillis = 1000 }
|
|
|
69
70
|
}
|
|
70
71
|
function confirmVersion(observed) {
|
|
71
72
|
if (observed !== "18.6") {
|
|
72
|
-
throw new
|
|
73
|
+
throw new PostgresVersionMismatch(observed);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
let version;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localPostgres.js","sourceRoot":"","sources":["../../src/server/localPostgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAA0B,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"localPostgres.js","sourceRoot":"","sources":["../../src/server/localPostgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,YAAY,EAAE,MA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,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YACjD,CAAC;QACF,CAAC;QACD,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3B,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,MAAM,CAAC,QAAQ,GAAG,WAAW,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,8CAA8C,IAAI,GAAG,CAAC,EAAE,CAAC;gBACzE,GAAG,CAAC,MAAM,EAAE,oBAAoB,IAAI,GAAG,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;AACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/local-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Repeatable local PostgreSQL preparation with one shared persistent service",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/local-postgres#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"README.md"
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@shivaedev/quality": "0.
|
|
44
|
-
"@shivaedev/test-story": "0.
|
|
43
|
+
"@shivaedev/quality": "0.29.0",
|
|
44
|
+
"@shivaedev/test-story": "0.15.0",
|
|
45
45
|
"@types/node": "24.19.2",
|
|
46
46
|
"effect": "4.0.4",
|
|
47
47
|
"typescript": "7.0.2",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class PostgresVersionMismatch extends Error {
|
|
2
|
+
readonly _tag = "PostgresVersionMismatch";
|
|
3
|
+
readonly expectedVersion = "18.6";
|
|
4
|
+
readonly observedVersion: string | undefined;
|
|
5
|
+
|
|
6
|
+
constructor(observedVersion: string | undefined) {
|
|
7
|
+
super("Expected local PostgreSQL 18.6. Check the existing service; setup never removes containers or data.");
|
|
8
|
+
this.observedVersion = observedVersion;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -3,6 +3,7 @@ import { env } from "node:process";
|
|
|
3
3
|
import { ensureConnections } from "./localConnections.ts";
|
|
4
4
|
import { sqlInContainer, startContainer } from "./localContainer.ts";
|
|
5
5
|
import { type DockerEnvironment, docker } from "./localDocker.ts";
|
|
6
|
+
import { PostgresVersionMismatch } from "./PostgresVersionMismatch.ts";
|
|
6
7
|
|
|
7
8
|
export const localServer = "postgresql://postgres:postgres@127.0.0.1:55432";
|
|
8
9
|
|
|
@@ -80,7 +81,7 @@ export function localPostgres(environment: DockerEnvironment, { attempts = 30, d
|
|
|
80
81
|
}
|
|
81
82
|
function confirmVersion(observed: string | undefined) {
|
|
82
83
|
if (observed !== "18.6") {
|
|
83
|
-
throw new
|
|
84
|
+
throw new PostgresVersionMismatch(observed);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
let version: string | undefined;
|