@chidchanun/bcp 0.2.1 → 0.2.3
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/README.md +255 -211
- package/docs/README.md +118 -79
- package/docs/api-manifest.json +5 -4
- package/docs/api-reference.md +33 -4
- package/docs/configuration.md +96 -1
- package/docs/database-migrations.md +79 -19
- package/docs/database.md +197 -28
- package/docs/docs-web-manifest.json +6 -3
- package/docs/environment-validation.md +224 -0
- package/docs/platform-manifest.json +20 -5
- package/docs/releases/0.2.2.md +118 -0
- package/docs/releases/0.2.3.md +77 -0
- package/package.json +1 -1
- package/packages/cli/src/args.ts +50 -9
- package/packages/cli/src/bootstrap.ts +22 -7
- package/packages/cli/src/configuration.ts +235 -0
- package/packages/cli/src/database-migrations.ts +91 -21
- package/packages/cli/src/index.ts +101 -1
- package/packages/client/src/config.ts +26 -0
- package/packages/client/src/database-mysql.ts +291 -0
- package/packages/client/src/database-postgresql.ts +355 -0
- package/packages/client/src/database-sqlite.ts +445 -0
- package/packages/client/src/database.mjs +709 -57
- package/packages/client/src/database.ts +347 -182
- package/packages/config/src/diagnostics.ts +226 -0
- package/packages/config/src/environment-loader.ts +101 -0
- package/packages/config/src/environment-schema.ts +677 -0
package/docs/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
The `docs/` directory is the documentation source of truth for BCP Framework and is organized for **`bcp-docs-web`**.
|
|
4
4
|
|
|
5
|
-
> **Documentation target:** BCP Framework `0.2.
|
|
5
|
+
> **Documentation target:** BCP Framework `0.2.2`
|
|
6
6
|
>
|
|
7
|
-
> **Release state:** unreleased development target. Do not label `0.2.
|
|
7
|
+
> **Release state:** unreleased development target. Do not label `0.2.2` as published until RC validation, tagging and npm publication complete.
|
|
8
8
|
|
|
9
|
-
## Documentation architecture
|
|
9
|
+
## Documentation architecture
|
|
10
10
|
|
|
11
11
|
BCP uses three machine-readable documentation contracts:
|
|
12
12
|
|
|
@@ -41,20 +41,31 @@ manifest-driven sync
|
|
|
41
41
|
|
|
42
42
|
Framework source and tests remain authoritative for runtime behavior.
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## 0.2.2 — Configuration & Environment v2
|
|
45
45
|
|
|
46
|
-
`0.2.
|
|
46
|
+
`0.2.2` adds an optional typed application environment schema while preserving the established framework configuration precedence.
|
|
47
47
|
|
|
48
|
-
New sources:
|
|
48
|
+
New/updated documentation sources:
|
|
49
49
|
|
|
50
50
|
| Source | Purpose |
|
|
51
51
|
| --- | --- |
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `
|
|
55
|
-
| `
|
|
52
|
+
| `environment-validation.md` | `bcp.environment.*`, validation rules, CLI checks and secret/public boundaries |
|
|
53
|
+
| `configuration.md` | Framework configuration precedence and diagnostics workflow |
|
|
54
|
+
| `platform-manifest.json` | Declares typed environment/config diagnostics capabilities |
|
|
55
|
+
| `api-manifest.json` | Maps `bcp/config` to configuration and environment guides |
|
|
56
|
+
| `releases/0.2.2.md` | Configuration & Environment v2 release notes |
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
Primary command:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
bcp config check
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
JSON diagnostics:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
bcp config check --json
|
|
68
|
+
```
|
|
58
69
|
|
|
59
70
|
## Update rule
|
|
60
71
|
|
|
@@ -64,14 +75,14 @@ When framework behavior or public surface changes:
|
|
|
64
75
|
2. Add/update regression tests.
|
|
65
76
|
3. Update the matching Markdown guide.
|
|
66
77
|
4. Update `platform-manifest.json` when runtime/public-entrypoint/capability metadata changes.
|
|
67
|
-
5. Update `api-manifest.json` when public API
|
|
78
|
+
5. Update `api-manifest.json` when public API ownership/guide mapping changes.
|
|
68
79
|
6. Update `docs-web-manifest.json` when website routes/navigation change.
|
|
69
80
|
7. Update `docs/releases/<version>.md`.
|
|
70
81
|
8. Change release state only after the release workflow reaches that state.
|
|
71
82
|
|
|
72
83
|
## Docs-web navigation
|
|
73
84
|
|
|
74
|
-
`docs/docs-web-manifest.json` is the ordered navigation contract.
|
|
85
|
+
`docs/docs-web-manifest.json` is the authoritative ordered navigation contract.
|
|
75
86
|
|
|
76
87
|
Current sections:
|
|
77
88
|
|
|
@@ -88,46 +99,104 @@ API Reference
|
|
|
88
99
|
Releases
|
|
89
100
|
```
|
|
90
101
|
|
|
91
|
-
Important
|
|
102
|
+
Important current routes:
|
|
92
103
|
|
|
93
104
|
| Website route | Markdown source |
|
|
94
105
|
| --- | --- |
|
|
106
|
+
| `/docs/configuration` | `configuration.md` |
|
|
107
|
+
| `/docs/environment-validation` | `environment-validation.md` |
|
|
95
108
|
| `/docs/platform-contract` | `platform-contract.md` |
|
|
96
109
|
| `/docs/documentation-platform` | `documentation-platform.md` |
|
|
97
110
|
| `/docs/migration-0.2` | `migration-0.2.md` |
|
|
98
111
|
| `/docs/api-reference` | `api-reference.md` |
|
|
99
|
-
| `/releases/0.2.
|
|
112
|
+
| `/releases/0.2.2` | `releases/0.2.2.md` |
|
|
100
113
|
|
|
101
114
|
Every route/source pair is validated by unit tests.
|
|
102
115
|
|
|
116
|
+
## Configuration source model
|
|
117
|
+
|
|
118
|
+
Framework settings:
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
bcp.config.ts
|
|
122
|
+
bcp.config.mts
|
|
123
|
+
bcp.config.js
|
|
124
|
+
bcp.config.mjs
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Application environment schema:
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
bcp.environment.ts
|
|
131
|
+
bcp.environment.mts
|
|
132
|
+
bcp.environment.js
|
|
133
|
+
bcp.environment.mjs
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Only one file from each convention may exist at a time.
|
|
137
|
+
|
|
138
|
+
The environment schema is optional. Existing applications without `bcp.environment.*` continue to use the previous environment-loading behavior.
|
|
139
|
+
|
|
140
|
+
Configuration precedence remains:
|
|
141
|
+
|
|
142
|
+
```text
|
|
143
|
+
CLI override
|
|
144
|
+
↓
|
|
145
|
+
BCP_* environment
|
|
146
|
+
↓
|
|
147
|
+
bcp.config.*
|
|
148
|
+
↓
|
|
149
|
+
framework defaults
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
See [Environment Validation](environment-validation.md).
|
|
153
|
+
|
|
154
|
+
## Environment security boundary
|
|
155
|
+
|
|
156
|
+
`BCP_PUBLIC_*` values may be embedded into browser bundles. They must never contain credentials/private secrets.
|
|
157
|
+
|
|
158
|
+
A variable declared with:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
secret: true
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
must not use the `BCP_PUBLIC_` prefix. The configuration validator treats that combination as an error.
|
|
165
|
+
|
|
166
|
+
`secret: true` is validation/tooling metadata and does not encrypt a value.
|
|
167
|
+
|
|
103
168
|
## Platform manifest
|
|
104
169
|
|
|
105
|
-
`docs/platform-manifest.json` describes the supported framework baseline:
|
|
170
|
+
`docs/platform-manifest.json` describes the supported framework baseline, including:
|
|
106
171
|
|
|
107
172
|
```text
|
|
108
|
-
schema version
|
|
109
173
|
framework version/release state
|
|
110
174
|
Node/React/runtime baseline
|
|
111
175
|
production build target
|
|
112
176
|
public package entrypoints
|
|
113
177
|
CLI command families
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
previous baseline compatibility intent
|
|
178
|
+
capability flags
|
|
179
|
+
previous-baseline compatibility intent
|
|
117
180
|
documentation contract files
|
|
118
181
|
```
|
|
119
182
|
|
|
120
|
-
|
|
183
|
+
`0.2.2` declares the additional capabilities:
|
|
121
184
|
|
|
122
185
|
```text
|
|
123
|
-
|
|
186
|
+
typedEnvironmentSchema
|
|
187
|
+
configurationDiagnostics
|
|
188
|
+
configCheckCli
|
|
124
189
|
```
|
|
125
190
|
|
|
126
|
-
|
|
191
|
+
The supported production target remains:
|
|
192
|
+
|
|
193
|
+
```text
|
|
194
|
+
standalone-node
|
|
195
|
+
```
|
|
127
196
|
|
|
128
197
|
## API manifest
|
|
129
198
|
|
|
130
|
-
`docs/api-manifest.json` describes the public package entrypoints
|
|
199
|
+
`docs/api-manifest.json` describes the public package entrypoints documentation tooling may present as supported API surfaces.
|
|
131
200
|
|
|
132
201
|
Current entrypoints:
|
|
133
202
|
|
|
@@ -145,24 +214,18 @@ bcp/server-only
|
|
|
145
214
|
bcp/middleware
|
|
146
215
|
```
|
|
147
216
|
|
|
148
|
-
|
|
217
|
+
`bcp/config` owns both:
|
|
149
218
|
|
|
150
219
|
```text
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
environment boundary
|
|
154
|
-
reference route
|
|
155
|
-
summary
|
|
156
|
-
related guide routes
|
|
220
|
+
/docs/configuration
|
|
221
|
+
/docs/environment-validation
|
|
157
222
|
```
|
|
158
223
|
|
|
159
|
-
The API-manifest entrypoint set must match the public-entrypoint set
|
|
160
|
-
|
|
161
|
-
See [API Reference](api-reference.md).
|
|
224
|
+
The API-manifest entrypoint set must match the platform public-entrypoint set exactly.
|
|
162
225
|
|
|
163
226
|
## bcp-docs-web synchronization
|
|
164
227
|
|
|
165
|
-
The
|
|
228
|
+
The docs website sync loads the manifests before Markdown content:
|
|
166
229
|
|
|
167
230
|
```text
|
|
168
231
|
selected framework ref
|
|
@@ -173,41 +236,19 @@ api-manifest.json
|
|
|
173
236
|
↓
|
|
174
237
|
validate version/release/API parity
|
|
175
238
|
↓
|
|
176
|
-
load
|
|
177
|
-
↓
|
|
178
|
-
rewrite internal Markdown links to website routes
|
|
239
|
+
load referenced Markdown
|
|
179
240
|
↓
|
|
180
241
|
synchronize CMS/search/navigation
|
|
181
242
|
```
|
|
182
243
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
Examples:
|
|
244
|
+
Examples from the docs-web project:
|
|
186
245
|
|
|
187
246
|
```powershell
|
|
188
247
|
npm run docs:sync -- --dry-run
|
|
189
248
|
npm run docs:sync -- --publish-new
|
|
190
|
-
npm run docs:sync -- --ref=v0.2.
|
|
249
|
+
npm run docs:sync -- --ref=v0.2.1
|
|
191
250
|
```
|
|
192
251
|
|
|
193
|
-
Using a tag/ref is the foundation for historical/versioned documentation without manually copying current Markdown into another source tree.
|
|
194
|
-
|
|
195
|
-
## Public API guide ownership
|
|
196
|
-
|
|
197
|
-
| Entrypoint | Primary guides |
|
|
198
|
-
| --- | --- |
|
|
199
|
-
| `bcp` | `routing.md`, `server-data-loaders.md`, `route-guards.md`, `form-actions.md` |
|
|
200
|
-
| `bcp/island` | `hydration.md` |
|
|
201
|
-
| `bcp/cache` | `caching.md` |
|
|
202
|
-
| `bcp/config` | `configuration.md` |
|
|
203
|
-
| `bcp/validation` | `validation.md` |
|
|
204
|
-
| `bcp/error` | `error-handling.md` |
|
|
205
|
-
| `bcp/database` | `database.md`, `database-migrations.md` |
|
|
206
|
-
| `bcp/auth` | `authentication.md`, `auth-route-guards.md`, `session-auth.md` |
|
|
207
|
-
| `bcp/server` | `server-request-apis.md`, `file-upload.md`, `storage.md`, `storage-ecosystem.md`, `production-hardening.md` |
|
|
208
|
-
| `bcp/server-only` | `application-modules.md` |
|
|
209
|
-
| `bcp/middleware` | `middleware.md` |
|
|
210
|
-
|
|
211
252
|
## Source conventions
|
|
212
253
|
|
|
213
254
|
- one H1 per Markdown page,
|
|
@@ -220,15 +261,9 @@ Using a tag/ref is the foundation for historical/versioned documentation without
|
|
|
220
261
|
- no framework-internal module presented as public API,
|
|
221
262
|
- no secrets/runtime `.env` values in public documentation metadata.
|
|
222
263
|
|
|
223
|
-
## Search and previous/next
|
|
224
|
-
|
|
225
|
-
Search should index Markdown content and headings. Manifest titles/categories/API summaries may be used as metadata.
|
|
226
|
-
|
|
227
|
-
Sidebar and previous/next ordering should follow `docs-web-manifest.json` order so navigation surfaces cannot drift from each other.
|
|
228
|
-
|
|
229
264
|
## Release validation
|
|
230
265
|
|
|
231
|
-
Before publishing `0.2.
|
|
266
|
+
Before publishing `0.2.2`:
|
|
232
267
|
|
|
233
268
|
```bash
|
|
234
269
|
npm run typecheck
|
|
@@ -239,14 +274,17 @@ npm run test:e2e
|
|
|
239
274
|
npm run rc:check
|
|
240
275
|
```
|
|
241
276
|
|
|
242
|
-
|
|
277
|
+
Configuration & Environment v2 validation covers:
|
|
243
278
|
|
|
244
|
-
-
|
|
245
|
-
-
|
|
246
|
-
-
|
|
247
|
-
-
|
|
248
|
-
-
|
|
249
|
-
-
|
|
279
|
+
- typed environment rules/defaults,
|
|
280
|
+
- project `bcp.environment.*` loading,
|
|
281
|
+
- public/secret safety boundary,
|
|
282
|
+
- production diagnostics,
|
|
283
|
+
- `bcp config check` CLI parsing,
|
|
284
|
+
- dev schema watching,
|
|
285
|
+
- public `bcp/config` exports,
|
|
286
|
+
- prepared npm package files,
|
|
287
|
+
- docs/platform/API version parity.
|
|
250
288
|
|
|
251
289
|
The final release tag must point to the exact commit that passed the complete RC sequence.
|
|
252
290
|
|
|
@@ -272,12 +310,13 @@ release notes
|
|
|
272
310
|
Planned next milestone:
|
|
273
311
|
|
|
274
312
|
```text
|
|
275
|
-
0.2.
|
|
313
|
+
0.2.3 — Database Platform v2
|
|
276
314
|
```
|
|
277
315
|
|
|
278
316
|
Focus:
|
|
279
317
|
|
|
280
|
-
-
|
|
281
|
-
-
|
|
282
|
-
-
|
|
283
|
-
-
|
|
318
|
+
- database adapter contract,
|
|
319
|
+
- PostgreSQL support,
|
|
320
|
+
- SQLite support,
|
|
321
|
+
- connection lifecycle improvements,
|
|
322
|
+
- provider-consistent migration workflows.
|
package/docs/api-manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"framework": "bcp",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"releaseState": "unreleased",
|
|
6
6
|
"coverage": "public-entrypoints",
|
|
7
7
|
"entrypoints": [
|
|
@@ -43,9 +43,10 @@
|
|
|
43
43
|
"source": "packages/client/src/config.ts",
|
|
44
44
|
"environment": "server",
|
|
45
45
|
"route": "/docs/api-reference#bcp-config",
|
|
46
|
-
"summary": "Typed BCP configuration
|
|
46
|
+
"summary": "Typed BCP configuration, environment-schema validation and configuration diagnostics APIs.",
|
|
47
47
|
"guides": [
|
|
48
|
-
"/docs/configuration"
|
|
48
|
+
"/docs/configuration",
|
|
49
|
+
"/docs/environment-validation"
|
|
49
50
|
]
|
|
50
51
|
},
|
|
51
52
|
{
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
"source": "packages/client/src/database.ts",
|
|
74
75
|
"environment": "server",
|
|
75
76
|
"route": "/docs/api-reference#bcp-database",
|
|
76
|
-
"summary": "
|
|
77
|
+
"summary": "Provider-neutral MySQL, PostgreSQL and SQLite query, transaction, lifecycle and migration primitives.",
|
|
77
78
|
"guides": [
|
|
78
79
|
"/docs/database",
|
|
79
80
|
"/docs/database-migrations"
|
package/docs/api-reference.md
CHANGED
|
@@ -62,17 +62,27 @@ Related guide: [Caching](caching.md).
|
|
|
62
62
|
|
|
63
63
|
## `bcp/config`
|
|
64
64
|
|
|
65
|
-
Typed configuration APIs.
|
|
65
|
+
Typed framework configuration, application environment-schema validation and diagnostics APIs.
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
68
|
import {
|
|
69
|
+
applyEnvironmentDefaults,
|
|
69
70
|
defineConfig,
|
|
71
|
+
defineEnvironment,
|
|
72
|
+
diagnoseBcpConfiguration,
|
|
73
|
+
getEnvironmentSchemaFileNames,
|
|
74
|
+
loadBcpEnvironmentSchema,
|
|
70
75
|
readResolvedBcpConfig,
|
|
71
76
|
resolveBcpConfig,
|
|
77
|
+
validateEnvironment,
|
|
72
78
|
} from "bcp/config";
|
|
73
79
|
```
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
Use `defineConfig()` for framework runtime/build settings and `defineEnvironment()` for the optional `bcp.environment.*` application-variable schema.
|
|
82
|
+
|
|
83
|
+
`validateEnvironment()` returns parsed declared values and structured issues. `applyEnvironmentDefaults()` fills only missing environment keys and does not overwrite values already supplied by the environment/runtime.
|
|
84
|
+
|
|
85
|
+
Related guides: [Configuration](configuration.md), [Environment Validation](environment-validation.md).
|
|
76
86
|
|
|
77
87
|
## `bcp/validation`
|
|
78
88
|
|
|
@@ -120,16 +130,35 @@ Related guide: [Error Handling](error-handling.md).
|
|
|
120
130
|
|
|
121
131
|
## `bcp/database`
|
|
122
132
|
|
|
123
|
-
Server-only
|
|
133
|
+
Server-only Database Platform v2 APIs.
|
|
124
134
|
|
|
125
135
|
```ts
|
|
126
136
|
import {
|
|
127
137
|
createDatabase,
|
|
128
138
|
db,
|
|
139
|
+
resolveDatabaseOptions,
|
|
140
|
+
type DatabaseAdapter,
|
|
141
|
+
type DatabaseAdapterFactory,
|
|
142
|
+
type DatabaseConnectionOptions,
|
|
143
|
+
type DatabaseDriver,
|
|
144
|
+
type DatabaseOptions,
|
|
145
|
+
type DatabaseParameters,
|
|
146
|
+
type ResolvedDatabaseOptions,
|
|
147
|
+
type TransactionDatabase,
|
|
129
148
|
} from "bcp/database";
|
|
130
149
|
```
|
|
131
150
|
|
|
132
|
-
|
|
151
|
+
Built-in SQL providers are:
|
|
152
|
+
|
|
153
|
+
```text
|
|
154
|
+
mysql
|
|
155
|
+
postgresql
|
|
156
|
+
sqlite
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`BcpDatabase` instances expose lazy query/execute/transaction operations plus explicit `connect()`, `disconnect()` and backward-compatible `close()` lifecycle methods.
|
|
160
|
+
|
|
161
|
+
Use the public database helpers and adapter types instead of importing framework-internal provider/pool runtime modules.
|
|
133
162
|
|
|
134
163
|
Related guides: [Database](database.md), [Database Migrations](database-migrations.md).
|
|
135
164
|
|
package/docs/configuration.md
CHANGED
|
@@ -92,6 +92,101 @@ BCP_EXPERIMENTAL_ISLANDS
|
|
|
92
92
|
|
|
93
93
|
Application environment variables prefixed with `BCP_PUBLIC_` may be embedded into browser bundles. Other application variables remain server-side.
|
|
94
94
|
|
|
95
|
+
## Configuration & Environment v2
|
|
96
|
+
|
|
97
|
+
BCP `0.2.2` adds an optional application environment schema in one of:
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
bcp.environment.ts
|
|
101
|
+
bcp.environment.mts
|
|
102
|
+
bcp.environment.js
|
|
103
|
+
bcp.environment.mjs
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The schema validates application-specific values after `.env` files are loaded.
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import {
|
|
112
|
+
defineEnvironment,
|
|
113
|
+
} from "bcp/config";
|
|
114
|
+
|
|
115
|
+
export default defineEnvironment({
|
|
116
|
+
DATABASE_URL: {
|
|
117
|
+
type: "string",
|
|
118
|
+
required: true,
|
|
119
|
+
},
|
|
120
|
+
SESSION_SECRET: {
|
|
121
|
+
type: "string",
|
|
122
|
+
required: true,
|
|
123
|
+
secret: true,
|
|
124
|
+
minLength: 32,
|
|
125
|
+
},
|
|
126
|
+
BCP_PUBLIC_API_URL: {
|
|
127
|
+
type: "url",
|
|
128
|
+
required: true,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
This schema is additive. Projects without `bcp.environment.*` continue to use the existing environment behavior.
|
|
134
|
+
|
|
135
|
+
Read more: [Environment Validation](environment-validation.md)
|
|
136
|
+
|
|
137
|
+
## Configuration check
|
|
138
|
+
|
|
139
|
+
Validate the current project without starting the application:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
bcp config check
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
JSON diagnostics:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
bcp config check --json
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Windows project-local form:
|
|
152
|
+
|
|
153
|
+
```powershell
|
|
154
|
+
npm exec -- bcp-framework config check
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The check reports the selected config file, environment files, environment schema, resolved server/build settings and diagnostics. Raw environment values are not printed.
|
|
158
|
+
|
|
159
|
+
For production-mode warnings in PowerShell:
|
|
160
|
+
|
|
161
|
+
```powershell
|
|
162
|
+
$env:NODE_ENV = "production"
|
|
163
|
+
npm exec -- bcp-framework config check
|
|
164
|
+
Remove-Item Env:NODE_ENV
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Startup diagnostics
|
|
168
|
+
|
|
169
|
+
`bcp dev` and `bcp build` run the environment-schema diagnostics before the application starts/builds.
|
|
170
|
+
|
|
171
|
+
Schema errors stop startup/build early. Production safety warnings do not fail the build by themselves.
|
|
172
|
+
|
|
173
|
+
Examples of production warnings include:
|
|
174
|
+
|
|
175
|
+
- source maps enabled,
|
|
176
|
+
- powered-by header enabled,
|
|
177
|
+
- Content-Security-Policy disabled,
|
|
178
|
+
- trusted proxy mode enabled.
|
|
179
|
+
|
|
180
|
+
Trusted proxy mode should only be enabled when untrusted clients cannot bypass the trusted proxy/load balancer.
|
|
181
|
+
|
|
95
182
|
## Config reload in development
|
|
96
183
|
|
|
97
|
-
Changes to
|
|
184
|
+
Changes to these configuration sources restart the development worker automatically:
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
.env*
|
|
188
|
+
bcp.config.*
|
|
189
|
+
bcp.environment.*
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The parent development supervisor stays running while the worker reloads the new configuration/environment state.
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
# Database Migrations
|
|
2
2
|
|
|
3
|
-
BCP
|
|
3
|
+
BCP `0.2.3` extends framework-managed SQL migrations across MySQL, PostgreSQL and SQLite.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Supported providers
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Migration bookkeeping uses the same provider selection as `bcp/database`:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```text
|
|
10
|
+
mysql
|
|
11
|
+
postgresql
|
|
12
|
+
sqlite
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Install the optional driver used by the application:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install mysql2
|
|
19
|
+
npm install pg
|
|
20
|
+
npm install better-sqlite3
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Only one driver is required when the project uses one database provider.
|
|
24
|
+
|
|
25
|
+
## Provider configuration
|
|
26
|
+
|
|
27
|
+
MySQL:
|
|
10
28
|
|
|
11
29
|
```env
|
|
30
|
+
DB_DRIVER=mysql
|
|
12
31
|
DB_HOST=localhost
|
|
13
32
|
DB_PORT=3306
|
|
14
33
|
DB_USER=root
|
|
@@ -16,7 +35,20 @@ DB_PASSWORD=
|
|
|
16
35
|
DB_NAME=bcp_app
|
|
17
36
|
```
|
|
18
37
|
|
|
19
|
-
|
|
38
|
+
PostgreSQL:
|
|
39
|
+
|
|
40
|
+
```env
|
|
41
|
+
DATABASE_URL=postgresql://postgres:password@localhost:5432/bcp_app
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
SQLite:
|
|
45
|
+
|
|
46
|
+
```env
|
|
47
|
+
DB_DRIVER=sqlite
|
|
48
|
+
DATABASE_URL=./data/bcp.sqlite
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Database commands load the development environment before connecting, so migration commands and `bcp dev` use the same provider selection.
|
|
20
52
|
|
|
21
53
|
## Create a migration
|
|
22
54
|
|
|
@@ -24,14 +56,14 @@ A project using migrations must have `mysql2` installed. Applications created wi
|
|
|
24
56
|
bcp db create create_users
|
|
25
57
|
```
|
|
26
58
|
|
|
27
|
-
BCP creates an ordered TypeScript file
|
|
59
|
+
BCP creates an ordered TypeScript file:
|
|
28
60
|
|
|
29
61
|
```text
|
|
30
62
|
migrations/
|
|
31
|
-
|
|
63
|
+
20260829090000_create_users.ts
|
|
32
64
|
```
|
|
33
65
|
|
|
34
|
-
|
|
66
|
+
Generated migrations export `up()` and `down()`:
|
|
35
67
|
|
|
36
68
|
```ts
|
|
37
69
|
import type {
|
|
@@ -43,9 +75,9 @@ export async function up(
|
|
|
43
75
|
): Promise<void> {
|
|
44
76
|
await db.execute(`
|
|
45
77
|
CREATE TABLE users (
|
|
46
|
-
id
|
|
78
|
+
id INTEGER PRIMARY KEY,
|
|
47
79
|
email VARCHAR(255) NOT NULL UNIQUE
|
|
48
|
-
)
|
|
80
|
+
)
|
|
49
81
|
`);
|
|
50
82
|
}
|
|
51
83
|
|
|
@@ -58,7 +90,24 @@ export async function down(
|
|
|
58
90
|
}
|
|
59
91
|
```
|
|
60
92
|
|
|
61
|
-
Migration filenames use a UTC timestamp prefix
|
|
93
|
+
Migration filenames use a UTC timestamp prefix for stable execution order.
|
|
94
|
+
|
|
95
|
+
## SQL dialect responsibility
|
|
96
|
+
|
|
97
|
+
BCP keeps its own `_bcp_migrations` bookkeeping provider-aware, but it does not translate application migration SQL.
|
|
98
|
+
|
|
99
|
+
This means migrations should either:
|
|
100
|
+
|
|
101
|
+
- use SQL supported by every database target used by the application, or
|
|
102
|
+
- intentionally target one provider and use that provider's SQL syntax.
|
|
103
|
+
|
|
104
|
+
Parameter placeholders also follow the active provider:
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
MySQL ?
|
|
108
|
+
SQLite ?
|
|
109
|
+
PostgreSQL $1, $2, ...
|
|
110
|
+
```
|
|
62
111
|
|
|
63
112
|
## Run pending migrations
|
|
64
113
|
|
|
@@ -66,9 +115,15 @@ Migration filenames use a UTC timestamp prefix so migrations have a stable execu
|
|
|
66
115
|
bcp db migrate
|
|
67
116
|
```
|
|
68
117
|
|
|
69
|
-
BCP creates
|
|
118
|
+
BCP creates `_bcp_migrations` with provider-specific DDL, detects pending migration files, and executes them in filename order.
|
|
119
|
+
|
|
120
|
+
All migrations applied by one command share the same batch number. Each migration runs inside its own transaction and its bookkeeping record is written in that same transaction.
|
|
70
121
|
|
|
71
|
-
|
|
122
|
+
Provider-specific bookkeeping includes:
|
|
123
|
+
|
|
124
|
+
- MySQL `AUTO_INCREMENT`,
|
|
125
|
+
- PostgreSQL `BIGSERIAL`,
|
|
126
|
+
- SQLite `INTEGER PRIMARY KEY AUTOINCREMENT`.
|
|
72
127
|
|
|
73
128
|
## Check status
|
|
74
129
|
|
|
@@ -84,22 +139,27 @@ The command reports applied and pending migration files together with the batch
|
|
|
84
139
|
bcp db rollback
|
|
85
140
|
```
|
|
86
141
|
|
|
87
|
-
Rollback reverses only the latest migration batch. Migrations
|
|
142
|
+
Rollback reverses only the latest migration batch. Migrations run from newest to oldest and each `down()` executes in a transaction together with deletion of its migration record.
|
|
88
143
|
|
|
89
144
|
BCP refuses to roll back an applied migration when its migration file is missing.
|
|
90
145
|
|
|
91
146
|
## Project root
|
|
92
147
|
|
|
93
|
-
All database commands support the normal
|
|
148
|
+
All database commands support the normal project-root option:
|
|
94
149
|
|
|
95
150
|
```bash
|
|
96
151
|
bcp db status --root ./apps/admin
|
|
97
152
|
```
|
|
98
153
|
|
|
99
|
-
##
|
|
154
|
+
## Database Platform v2 behavior
|
|
100
155
|
|
|
101
|
-
|
|
156
|
+
`0.2.3` keeps migration commands consistent across the built-in SQL providers:
|
|
102
157
|
|
|
103
|
-
|
|
158
|
+
```text
|
|
159
|
+
bcp db create
|
|
160
|
+
bcp db migrate
|
|
161
|
+
bcp db status
|
|
162
|
+
bcp db rollback
|
|
163
|
+
```
|
|
104
164
|
|
|
105
|
-
|
|
165
|
+
The command names and migration file contract stay the same regardless of whether the application uses MySQL, PostgreSQL or SQLite.
|