@shivaedev/local-postgres 0.4.1 → 0.4.2

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +25 -12
  3. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.2 - 2026-10-18
4
+
5
+ ### Changed
6
+
7
+ - 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.
8
+
3
9
  ## 0.4.1 - 2026-10-18
4
10
 
5
11
  ### 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 { assertLocalDatabase, localPostgres, localServer } from "@shivaedev/local-postgres/localPostgres.ts";
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 chooses `example_dev`. Preparation can run again without losing the data already in the database.
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 explicitly permits their names.
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 and validate the databases
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
- This is a complete preparation script for two application-owned databases. `assertLocalDatabase` checks the name against the list the caller supplies. It rejects a remote host, the wrong port, a different database name or any redirecting connection parameter: `host`, `hostaddr`, `port`, `dbname` or `service`. Preparation and SQL execution also reject remote database targets.
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 { assertLocalDatabase, localPostgres, localServer } from "@shivaedev/local-postgres/localPostgres.ts";
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]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/local-postgres",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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.27.0",
44
- "@shivaedev/test-story": "0.9.0",
43
+ "@shivaedev/quality": "0.27.1",
44
+ "@shivaedev/test-story": "0.10.0",
45
45
  "@types/node": "24.19.2",
46
46
  "effect": "4.0.4",
47
47
  "typescript": "7.0.2",