@jskit-ai/agent-docs 0.1.100 → 0.1.102

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.
@@ -96,6 +96,16 @@ The app has two different migration-related layers:
96
96
 
97
97
  Those are **not** the same step.
98
98
 
99
+ There is also an important ownership distinction:
100
+
101
+ - a CRUD generator owns the installed baseline migration for the table it
102
+ scaffolds
103
+ - the table's app-local package owns later additive schema evolution
104
+
105
+ Never modify or replace a generator-owned baseline migration. Later schema
106
+ evolution must use a new immutable, package-owned additive migration in the
107
+ table's app-local package, declared through `install-migration`.
108
+
99
109
  The npm scripts hide the easy-to-miss first step for normal use. `npm run db:migrate` and `npm run db:migrate:status` run `npm run db:migrations:sync` first, then run Knex. That means package upgrades can add new JSKIT-managed migration files before Knex checks what is pending.
100
110
 
101
111
  ### `jskit migrations ...` writes managed migration files
@@ -157,6 +167,52 @@ So:
157
167
  - sometimes you need only `npm run db:migrate`
158
168
  - sometimes, after repair or re-materialization work, you need **both**
159
169
 
170
+ ### Authoring a later app-owned schema change
171
+
172
+ When an existing CRUD-owned table needs a new column, constraint, index, or
173
+ other compatible evolution, keep the generated baseline unchanged. Ask JSKIT
174
+ to create a new migration source in the app-local package that owns the table:
175
+
176
+ ```bash
177
+ npx jskit create migration \
178
+ --package @local/workflow-record-report-values \
179
+ --id extend-report-value-field-types
180
+ ```
181
+
182
+ This command:
183
+
184
+ 1. verifies that the owner is an installed app-local package
185
+ 2. rejects duplicate or unsafe migration ids
186
+ 3. creates an editable template under the package's
187
+ `templates/migrations/` directory
188
+ 4. adds the matching `install-migration` mutation to the package descriptor
189
+ 5. leaves the migration unmaterialized so its implementation can still be
190
+ completed
191
+
192
+ Implement and test the template first. It intentionally fails if someone tries
193
+ to apply the untouched scaffold. Then materialize and apply it:
194
+
195
+ ```bash
196
+ npx jskit migrations package @local/workflow-record-report-values
197
+ npm run db:migrate
198
+ ```
199
+
200
+ The materialized migration and its lock record are managed artifacts. Once
201
+ installed, the migration id and content are immutable. Any later correction
202
+ must use another additive migration with a new id.
203
+
204
+ SQL inside the source-controlled migration is supported when Knex does not
205
+ express the required schema operation directly. Ad-hoc SQL applied only to a
206
+ development or live database is not a migration and must not be used: it
207
+ creates schema drift, breaks fresh reconstruction, and leaves deployment
208
+ history incomplete.
209
+
210
+ Before completion, exercise the complete migration chain against a fresh
211
+ disposable database as well as the intended upgrade path. A down migration
212
+ must refuse safely when narrowing the schema would invalidate existing data;
213
+ it must never delete or silently transform valuable rows merely to make a
214
+ rollback pass.
215
+
160
216
  ### Shared database helpers
161
217
 
162
218
  The database layer also gives later server code a shared helper surface:
@@ -286,6 +286,25 @@ The exact fields will vary by app. What matters for the generator is:
286
286
  - the column names are stable enough to become part of your app's resource contract
287
287
  - if you are using `crud-server-generator`, do **not** hand-write a separate CRUD migration for this table; the server generator installs the CRUD migration scaffold itself
288
288
 
289
+ That last rule governs the generated baseline, not every future schema change.
290
+ Never modify or replace a generator-owned baseline migration after it has been
291
+ installed. Later schema evolution must use a new immutable, package-owned
292
+ additive migration in the table's app-local package, declared through
293
+ `install-migration`.
294
+
295
+ Create that source and descriptor mutation together with:
296
+
297
+ ```bash
298
+ npx jskit create migration \
299
+ --package @local/contacts \
300
+ --id add-contact-status
301
+ ```
302
+
303
+ Implement the generated template before running
304
+ `npx jskit migrations package @local/contacts`. SQL or Knex schema operations
305
+ inside the source-controlled migration are supported. Running ad-hoc SQL
306
+ against only one database is not, because it creates schema drift.
307
+
289
308
  In this table, `workspace_id` is the important ownership clue. That is why the next step uses:
290
309
 
291
310
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/agent-docs",
3
- "version": "0.1.100",
3
+ "version": "0.1.102",
4
4
  "description": "Distributed JSKIT agent references, prompts, guides, and generated reference maps.",
5
5
  "type": "module",
6
6
  "files": [
@@ -51,6 +51,9 @@ Rules:
51
51
  - If the table should already be CRUD-owned but should not expose public CRUD HTTP routes yet, scaffold it with `jskit generate crud-server-generator scaffold ... --internal` instead of dropping to direct knex or a hand-built pseudo-repository.
52
52
  - Create the real table directly in the database before scaffolding. `crud-server-generator` reads the live table shape.
53
53
  - If `crud-server-generator` is going to own the CRUD, do not hand-write a separate CRUD migration for that table. The generator installs and manages the CRUD migration scaffold itself.
54
+ - Never modify or replace a generator-owned baseline migration after it has
55
+ been installed. Later schema evolution must use a new immutable,
56
+ package-owned additive migration declared through `install-migration`.
54
57
  - Keep generated table creation in `migrations/` and generated foreign keys in
55
58
  `migrations/constraints/`. The database runtime deliberately runs those
56
59
  phases in that order so valid mutual foreign keys rebuild cleanly without
@@ -72,6 +75,38 @@ Rules:
72
75
  - Structured filters should use shared filter definitions and collapse to compact filter controls/sheets when they outgrow simple search. Do not stack dense desktop filter bars on phone widths.
73
76
  - Use `--navigation-role` for CRUD list placement intent. Main resources can stay `primary`; nested/detail/workflow CRUD routes should usually be `secondary`, `workflow`, or `none`.
74
77
 
78
+ ## Baseline generation versus later schema evolution
79
+
80
+ The initial CRUD scaffold and a later schema change are different operations:
81
+
82
+ - The server generator owns the baseline migration that recreates the table
83
+ from zero. Do not edit, replace, or regenerate that installed baseline to
84
+ express a later change.
85
+ - The table's app-local package owns later schema evolution. Create each change
86
+ as a new immutable additive migration:
87
+
88
+ ```bash
89
+ npx jskit create migration \
90
+ --package @local/workflow-record-report-values \
91
+ --id extend-report-value-field-types
92
+ ```
93
+
94
+ - The authoring command creates an editable migration template and adds its
95
+ `install-migration` mutation to the owning package descriptor in one
96
+ operation. Implement and test the template before materializing it.
97
+ - Materialize the completed source with
98
+ `npx jskit migrations package <package-id>`, then apply it with
99
+ `npm run db:migrate`.
100
+ - SQL or Knex schema operations inside that source-controlled migration are
101
+ supported. Ad-hoc SQL applied only to one database is not: it creates schema
102
+ drift and leaves fresh installations incorrect.
103
+ - Installed migration ids and content are immutable. A correction to an
104
+ installed migration is another additive migration with a new id.
105
+
106
+ A package-owned additive migration is not the prohibited "separate CRUD
107
+ migration." The prohibition applies to competing with or modifying the
108
+ generator-owned baseline.
109
+
75
110
  Meaning of `--internal`:
76
111
 
77
112
  - it keeps the generated repository, service, actions, provider, resource, and CRUD migration ownership chain
@@ -777,6 +777,19 @@ Local functions
777
777
  Exports
778
778
  - `runPackageCreateCommand(ctx = {}, { positional, options, cwd, io })`
779
779
 
780
+ ### `src/server/commandHandlers/packageCommands/createMigration.js`
781
+ Exports
782
+ - `addInstallMigrationMutationToDescriptor(source = "", mutation = {})`
783
+ - `createMigrationTemplate({ packageId, migrationId } = {})`
784
+ - `runMigrationCreateCommand(ctx = {}, { options, cwd, io })`
785
+ Local functions
786
+ - `maskNonCode(source = "")`
787
+ - `findMatchingDelimiter(source, openIndex, openCharacter, closeCharacter)`
788
+ - `findMutationsFilesArray(source = "")`
789
+ - `lineIndentAt(source = "", index = 0)`
790
+ - `renderInstallMigrationMutation({ from, id, indent } = {})`
791
+ - `writeMigrationSourceAndDescriptor({ descriptorPath, descriptorSource, migrationPath, migrationSource, mkdir, rename, rm, writeFile, path } = {})`
792
+
780
793
  ### `src/server/commandHandlers/packageCommands/discoverabilityHelp.js`
781
794
  Exports
782
795
  - `isHelpToken(value = "")`