@dbx-tools/appkit-autopg 0.1.4 → 0.1.5
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/package.json +2 -2
- package/README.md +0 -113
package/package.json
CHANGED
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"directory": "packages/autopg"
|
|
29
29
|
},
|
|
30
30
|
"name": "@dbx-tools/appkit-autopg",
|
|
31
|
-
"version": "0.1.
|
|
31
|
+
"version": "0.1.5",
|
|
32
32
|
"module": "index.ts",
|
|
33
33
|
"type": "module",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@dbx-tools/appkit-shared": "0.1.
|
|
35
|
+
"@dbx-tools/appkit-shared": "0.1.5"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/README.md
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
# @dbx-tools/appkit-autopg
|
|
2
|
-
|
|
3
|
-
`autopg()` is a one-line helper that fills in every Lakebase Postgres
|
|
4
|
-
env var the AppKit `lakebase` plugin needs from whatever fragments your
|
|
5
|
-
deployment actually carries. Run it once before `createApp(...)` and stop
|
|
6
|
-
hand-rolling connection strings:
|
|
7
|
-
|
|
8
|
-
```ts
|
|
9
|
-
import { createApp, lakebase, server } from "@databricks/appkit";
|
|
10
|
-
import { autopg } from "@dbx-tools/appkit-autopg";
|
|
11
|
-
|
|
12
|
-
await autopg();
|
|
13
|
-
await createApp({ plugins: [server(), lakebase()] });
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Why a top-level helper instead of an AppKit plugin
|
|
17
|
-
|
|
18
|
-
AppKit's `static phase` field orders plugin `setup()` _invocation_, not
|
|
19
|
-
async _completion_. `lakebase.setup()` synchronously throws on a missing
|
|
20
|
-
`PGHOST` after its first `await`, so a sibling plugin that performs REST
|
|
21
|
-
discovery during `setup()` races and loses every time. Awaiting
|
|
22
|
-
`autopg()` before `createApp(...)` sidesteps the race - by the time any
|
|
23
|
-
plugin runs, `process.env` is fully populated.
|
|
24
|
-
|
|
25
|
-
## What it accepts
|
|
26
|
-
|
|
27
|
-
`autopg()` looks at, in priority order:
|
|
28
|
-
|
|
29
|
-
1. Explicit `autopg({ project, branch, endpoint, database, host, port, sslMode, autoCreate })`
|
|
30
|
-
2. Env vars - the same ones `lakebase` already reads:
|
|
31
|
-
- `LAKEBASE_PROJECT`, `LAKEBASE_BRANCH`, `LAKEBASE_ENDPOINT`
|
|
32
|
-
- `PGHOST`, `PGDATABASE`, `PGPORT`, `PGSSLMODE`
|
|
33
|
-
3. Whatever the address parser can recover from
|
|
34
|
-
`LAKEBASE_ENDPOINT` / `config.endpoint`
|
|
35
|
-
|
|
36
|
-
The address input is permissive - any of these work:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
# Canonical resource path
|
|
40
|
-
LAKEBASE_ENDPOINT="projects/dbx-tools/branches/main/endpoints/primary"
|
|
41
|
-
|
|
42
|
-
# Full Postgres URI (auth, host, db, sslmode all extracted)
|
|
43
|
-
LAKEBASE_ENDPOINT="postgresql://me%40databricks.com@ep-foo.database.azuredatabricks.net/databricks_postgres?sslmode=require"
|
|
44
|
-
|
|
45
|
-
# Bare Lakebase hostname (resolver reverse-looks-up the project)
|
|
46
|
-
LAKEBASE_ENDPOINT="ep-steep-forest-e199v43w.database.eastus2.azuredatabricks.net"
|
|
47
|
-
|
|
48
|
-
# Bare project id (resolver picks the default branch + endpoint + db)
|
|
49
|
-
LAKEBASE_ENDPOINT="dbx-tools"
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Three resolution modes
|
|
53
|
-
|
|
54
|
-
After parsing, the resolver fills gaps in this order:
|
|
55
|
-
|
|
56
|
-
1. **Reverse-lookup** - given just a host, scan
|
|
57
|
-
`projects` -> `branches` -> `endpoints` for a matching
|
|
58
|
-
`status.hosts.host` and recover the owning resource path.
|
|
59
|
-
2. **Pick default** - given a `project` (and optionally a `branch`),
|
|
60
|
-
prefer the server-marked default child (`status.default`,
|
|
61
|
-
`ENDPOINT_TYPE_READ_WRITE`, `databricks_postgres`) and fall back to
|
|
62
|
-
"the only one" when a listing returns a single result.
|
|
63
|
-
3. **Auto-create** - when no projects exist at all, create one whose id
|
|
64
|
-
defaults to a slugified `projectUtils.name()` (override with
|
|
65
|
-
`autoCreate: "my-id"` or disable with `autoCreate: false`). The
|
|
66
|
-
create call is idempotent: an `ALREADY_EXISTS` response from a
|
|
67
|
-
concurrent boot is treated as success. Then poll the default
|
|
68
|
-
endpoint until `current_state` is `READY` or `IDLE`.
|
|
69
|
-
|
|
70
|
-
## Options
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
await autopg({
|
|
74
|
-
// Skip writing process.env (just inspect the returned record).
|
|
75
|
-
exportEnv: false,
|
|
76
|
-
// Pin individual fields - any of these short-circuit the resolver.
|
|
77
|
-
project: "dbx-tools",
|
|
78
|
-
branch: "main",
|
|
79
|
-
endpoint: "projects/dbx-tools/branches/main/endpoints/primary",
|
|
80
|
-
database: "databricks_postgres",
|
|
81
|
-
// Auto-create behavior.
|
|
82
|
-
autoCreate: false, // throw if no project exists
|
|
83
|
-
// autoCreate: "my-custom-id", // create with this id
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
`autopg()` returns a `Resolved` record (`project`, `branch`, `endpoint`,
|
|
88
|
-
`database`, `host`, `port`, `sslMode`). When `exportEnv: true` (the
|
|
89
|
-
default) it also writes the same values to `process.env`, only filling
|
|
90
|
-
gaps - existing values are preserved.
|
|
91
|
-
|
|
92
|
-
## Address parser
|
|
93
|
-
|
|
94
|
-
The address parser is exported as well if you want it without the
|
|
95
|
-
resolver wrapper:
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
import { parseAddress } from "@dbx-tools/appkit-autopg";
|
|
99
|
-
|
|
100
|
-
parseAddress("postgresql://user@ep-foo.database.azuredatabricks.net/dbpg");
|
|
101
|
-
// { user, host, database, port?, sslMode?, project?, branch?, endpointId? }
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Required permissions
|
|
105
|
-
|
|
106
|
-
The Databricks user / SP behind `getWorkspaceClient()` needs
|
|
107
|
-
`postgres.projects.{list,create}`, `postgres.branches.list`,
|
|
108
|
-
`postgres.endpoints.{list,get}`, and `postgres.databases.list` on the
|
|
109
|
-
account.
|
|
110
|
-
|
|
111
|
-
## License
|
|
112
|
-
|
|
113
|
-
Apache-2.0
|