@openreachtech/hora-skills-ort-renchan 0.0.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/LICENSE +201 -0
- package/README.ja.md +135 -0
- package/README.md +135 -0
- package/dist/skills/hor-agent-loop/SKILL.md +123 -0
- package/dist/skills/hor-agent-loop/references/core.md +485 -0
- package/dist/skills/hor-agent-loop/references/graphql-integration.md +178 -0
- package/dist/skills/hor-agent-loop/references/renchan-job-integration.md +368 -0
- package/dist/skills/hor-agent-loop/references/testing.md +492 -0
- package/dist/skills/hor-ai-agent-structure/SKILL.md +403 -0
- package/dist/skills/hor-ai-agent-structure/references/loop-and-actions.md +100 -0
- package/dist/skills/hor-ai-prompt-document-store/SKILL.md +220 -0
- package/dist/skills/hor-ai-prompt-document-store/references/models-and-composition.md +156 -0
- package/dist/skills/hor-backend-testing/SKILL.md +118 -0
- package/dist/skills/hor-backend-testing/references/placement-and-ordering.md +89 -0
- package/dist/skills/hor-backend-testing/references/purity-and-mocks.md +82 -0
- package/dist/skills/hor-backend-testing/references/running-tests.md +186 -0
- package/dist/skills/hor-bank-id/SKILL.md +91 -0
- package/dist/skills/hor-build-e2e-test-environment/SKILL.md +609 -0
- package/dist/skills/hor-build-e2e-test-environment/references/compose-definition.md +368 -0
- package/dist/skills/hor-build-e2e-test-environment/references/edge-and-proxy.md +287 -0
- package/dist/skills/hor-build-e2e-test-environment/references/environment-and-ports.md +201 -0
- package/dist/skills/hor-build-e2e-test-environment/references/runner-and-lifecycle.md +330 -0
- package/dist/skills/hor-build-e2e-test-environment/references/seed-data.md +145 -0
- package/dist/skills/hor-build-e2e-test-environment/references/windows-runner.md +146 -0
- package/dist/skills/hor-constant-definition/SKILL.md +139 -0
- package/dist/skills/hor-cookie-authentication/SKILL.md +33 -0
- package/dist/skills/hor-cookie-authentication/references/auth-filter.md +55 -0
- package/dist/skills/hor-cookie-authentication/references/cookie-context.md +53 -0
- package/dist/skills/hor-cookie-authentication/references/dev-login-seeder.md +22 -0
- package/dist/skills/hor-cookie-authentication/references/environment.md +64 -0
- package/dist/skills/hor-cookie-authentication/references/error-codes.md +24 -0
- package/dist/skills/hor-cookie-authentication/references/migrations.md +18 -0
- package/dist/skills/hor-cookie-authentication/references/resolvers.md +97 -0
- package/dist/skills/hor-cookie-authentication/references/session-clerk.md +41 -0
- package/dist/skills/hor-cookie-authentication/references/token-models.md +125 -0
- package/dist/skills/hor-database-design/SKILL.md +54 -0
- package/dist/skills/hor-database-design/references/column-types.md +92 -0
- package/dist/skills/hor-database-design/references/datetimes.md +88 -0
- package/dist/skills/hor-database-design/references/master-tables.md +117 -0
- package/dist/skills/hor-database-design/references/normalization.md +40 -0
- package/dist/skills/hor-database-design/references/update-history.md +35 -0
- package/dist/skills/hor-execution-placement-pattern/SKILL.md +216 -0
- package/dist/skills/hor-external-api-client/SKILL.md +99 -0
- package/dist/skills/hor-external-api-client/references/architecture.md +127 -0
- package/dist/skills/hor-external-api-client/references/authorization.md +105 -0
- package/dist/skills/hor-external-api-client/references/capsule.md +130 -0
- package/dist/skills/hor-external-api-client/references/conventions.md +68 -0
- package/dist/skills/hor-external-api-client/references/launcher.md +138 -0
- package/dist/skills/hor-external-api-client/references/payload.md +176 -0
- package/dist/skills/hor-external-api-client/references/sdk-wrapper.md +291 -0
- package/dist/skills/hor-external-api-client/references/testing.md +130 -0
- package/dist/skills/hor-external-api-client/references/usage.md +152 -0
- package/dist/skills/hor-graphql-schema/SKILL.md +360 -0
- package/dist/skills/hor-graphql-server-engine/SKILL.md +356 -0
- package/dist/skills/hor-light-rag/SKILL.md +242 -0
- package/dist/skills/hor-light-rag/references/retrieval-internals.md +143 -0
- package/dist/skills/hor-multi-llm-provider/SKILL.md +288 -0
- package/dist/skills/hor-multi-llm-provider/references/provider-internals.md +153 -0
- package/dist/skills/hor-mutation-resolver/SKILL.md +360 -0
- package/dist/skills/hor-mutation-resolver/references/dependency-injection.md +148 -0
- package/dist/skills/hor-mutation-resolver/references/errors.md +120 -0
- package/dist/skills/hor-mutation-resolver/references/resolve-flow.md +275 -0
- package/dist/skills/hor-mutation-resolver/references/testing.md +125 -0
- package/dist/skills/hor-mutation-resolver/references/transaction.md +197 -0
- package/dist/skills/hor-post-worker/SKILL.md +320 -0
- package/dist/skills/hor-query-resolver/SKILL.md +246 -0
- package/dist/skills/hor-query-resolver/references/anatomy.md +384 -0
- package/dist/skills/hor-query-resolver/references/data-access.md +248 -0
- package/dist/skills/hor-query-resolver/references/errors-and-context.md +172 -0
- package/dist/skills/hor-query-resolver/references/testing.md +241 -0
- package/dist/skills/hor-renchan-job-bullmq/SKILL.md +178 -0
- package/dist/skills/hor-renchan-job-bullmq/references/daemon-and-scheduler.md +182 -0
- package/dist/skills/hor-renchan-job-bullmq/references/engine-and-infra.md +106 -0
- package/dist/skills/hor-renchan-job-bullmq/references/job-triple.md +189 -0
- package/dist/skills/hor-renchan-job-bullmq/references/queues.md +74 -0
- package/dist/skills/hor-renchan-job-bullmq/references/subscriptions.md +113 -0
- package/dist/skills/hor-resolver-share/SKILL.md +262 -0
- package/dist/skills/hor-resolver-validator/SKILL.md +194 -0
- package/dist/skills/hor-resolver-validator/references/inspector-api.md +115 -0
- package/dist/skills/hor-resolver-validator/references/validator-pattern.md +281 -0
- package/dist/skills/hor-restfulapi-architecture/SKILL.md +275 -0
- package/dist/skills/hor-restfulapi-architecture/references/engine-and-context.md +192 -0
- package/dist/skills/hor-restfulapi-architecture/references/renderers.md +204 -0
- package/dist/skills/hor-restfulapi-architecture/references/response-and-flusher.md +118 -0
- package/dist/skills/hor-restfulapi-architecture/references/validation.md +229 -0
- package/dist/skills/hor-security-audit/SKILL.md +110 -0
- package/dist/skills/hor-security-audit/references/application-surface.md +90 -0
- package/dist/skills/hor-security-audit/references/auth-and-transport.md +147 -0
- package/dist/skills/hor-security-audit/references/code-safety.md +74 -0
- package/dist/skills/hor-security-audit/references/dependencies.md +72 -0
- package/dist/skills/hor-security-audit/references/network-and-logging.md +56 -0
- package/dist/skills/hor-security-audit/references/secrets.md +95 -0
- package/dist/skills/hor-sequelize-migration/SKILL.md +336 -0
- package/dist/skills/hor-sequelize-migration/references/alter-table.md +147 -0
- package/dist/skills/hor-sequelize-migration/references/foreign-keys.md +107 -0
- package/dist/skills/hor-sequelize-migration/references/indexes.md +149 -0
- package/dist/skills/hor-sequelize-migration/references/notation.md +215 -0
- package/dist/skills/hor-sequelize-model/SKILL.md +69 -0
- package/dist/skills/hor-sequelize-model/references/associations.md +218 -0
- package/dist/skills/hor-sequelize-model/references/default-methods.md +244 -0
- package/dist/skills/hor-sequelize-model/references/mixins.md +247 -0
- package/dist/skills/hor-sequelize-model/references/notation.md +225 -0
- package/dist/skills/hor-sequelize-model/references/timestamps.md +74 -0
- package/dist/skills/hor-sequelize-seeder/SKILL.md +275 -0
- package/dist/skills/hor-sequelize-seeder/references/development-coverage.md +74 -0
- package/dist/skills/hor-sequelize-seeder/references/directory-structure.md +113 -0
- package/dist/skills/hor-sequelize-seeder/references/id-numbering.md +133 -0
- package/dist/skills/hor-sequelize-seeder/references/naming.md +59 -0
- package/dist/skills/hor-sequelize-seeder/references/notation.md +170 -0
- package/dist/skills/hor-sequelize-subquery/SKILL.md +369 -0
- package/dist/skills/hor-strategy-pattern/SKILL.md +371 -0
- package/dist/skills/hor-stub-api/SKILL.md +330 -0
- package/dist/skills/hor-subscription-resolver/SKILL.md +105 -0
- package/dist/skills/hor-subscription-resolver/references/authentication.md +99 -0
- package/dist/skills/hor-subscription-resolver/references/basic-notation.md +116 -0
- package/dist/skills/hor-subscription-resolver/references/design-philosophy.md +68 -0
- package/dist/skills/hor-type-interface/SKILL.md +200 -0
- package/docs/skills.ja.md +40 -0
- package/docs/skills.md +40 -0
- package/lib/equip/CommandLineArguments.js +178 -0
- package/lib/equip/HoraSkillsCli.js +590 -0
- package/lib/equip/SkillsInstaller.js +443 -0
- package/lib/equip/SkillsManifestFile.js +260 -0
- package/lib/equip/constants/CLI_COMMAND.js +8 -0
- package/lib/equip/hora-skills-ort-renchan.js +8 -0
- package/package.json +51 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hor-sequelize-seeder
|
|
3
|
+
description: >
|
|
4
|
+
Write and edit renchan/Sequelize seeder files (sequelize/seeders/**/*.cjs). Use this
|
|
5
|
+
skill whenever the user asks to create or update a seeder — inserting master or
|
|
6
|
+
development data with bulkInsert / bulkDelete, choosing which directory
|
|
7
|
+
(master / dev-master / development), naming a seeder file, allocating seed-row ids,
|
|
8
|
+
or wiring TimestampSeedsSupplier. Covers the three-directory split and the db:seed:*
|
|
9
|
+
scripts, the file skeleton, filename / numbering, and the per-file id-block
|
|
10
|
+
numbering rule.
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Sequelize Seeders
|
|
14
|
+
|
|
15
|
+
A skill for writing the `sequelize/seeders/**/*.cjs` files. Where
|
|
16
|
+
`hor-sequelize-migration` builds the **physical schema** (tables,
|
|
17
|
+
columns, indexes), a seeder **fills those tables with rows** via `bulkInsert`. A seed row is a plain
|
|
18
|
+
object keyed by the **physical (snake_case) column names** — the same names the migration declares
|
|
19
|
+
as `field:` — so a seeder is coupled to the migration, not to the model's camelCase attributes.
|
|
20
|
+
|
|
21
|
+
> A concise overview. Each numbered section links to a detail file under `references/` for depth.
|
|
22
|
+
|
|
23
|
+
## Core principle: a seeder is a filled-in template
|
|
24
|
+
|
|
25
|
+
Every seeder has the **same skeleton**: `'use strict'` → `require` `TimestampSeedsSupplier` (+ any
|
|
26
|
+
domain constants) → an intent comment → `TABLE_NAME` → one or more `seeds` arrays → `module.exports
|
|
27
|
+
= { up, down }`, where `up` is `bulkInsert(TABLE_NAME, TimestampSeedsSupplier.supplyAll(seeds), {})`
|
|
28
|
+
and `down` is `bulkDelete(TABLE_NAME, { id: seeds.map(it => it.id) })`. Keep the skeleton identical
|
|
29
|
+
across files (the same idea as in `hor-sequelize-migration` and
|
|
30
|
+
`hor-sequelize-model`) so review attention goes to the **data**, not the
|
|
31
|
+
plumbing.
|
|
32
|
+
|
|
33
|
+
- **Deterministic, explicit ids.** Every seed row carries an explicit `id` (never rely on
|
|
34
|
+
auto-increment), so `down` can `bulkDelete` exactly the rows `up` inserted, and so foreign-key
|
|
35
|
+
columns in other seeds can point at a known id. The id scheme is the heart of this skill (§4).
|
|
36
|
+
- **Rows use physical (snake_case) column names** (`customer_id`, `unit_rate`, `is_active`) — the
|
|
37
|
+
migration's `field:` names, not the model's camelCase. `bulkInsert` writes raw columns.
|
|
38
|
+
- **Comments**: structural comments in English (matching the model / migration skills); the
|
|
39
|
+
domain-explanation comments in the real seeders of this repo are often Japanese (they cite the
|
|
40
|
+
design doc / implementation plan) — match the surrounding files.
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// Good example (a whole single-table master seeder)
|
|
44
|
+
'use strict'
|
|
45
|
+
|
|
46
|
+
const TimestampSeedsSupplier = require('@openreachtech/renchan-sequelize/lib/tools/TimestampSeedsSupplier.cjs')
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Development sample: content plan rates (dev-master).
|
|
50
|
+
* In production these are created via the admin CRUD. 3 plans × 3 tiers (JPY, per month).
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
const TABLE_NAME = 'content_plan_rates'
|
|
54
|
+
|
|
55
|
+
const EFFECTIVE_AT = new Date('2024-01-01T00:00:00.000Z')
|
|
56
|
+
|
|
57
|
+
const seeds = [
|
|
58
|
+
{ id: 500001, plan: 'basic', tier: 'small', unit_rate: 50000, currency: 'JPY', effective_at: EFFECTIVE_AT, is_active: true },
|
|
59
|
+
{ id: 500002, plan: 'basic', tier: 'medium', unit_rate: 70000, currency: 'JPY', effective_at: EFFECTIVE_AT, is_active: true },
|
|
60
|
+
{ id: 500003, plan: 'basic', tier: 'large', unit_rate: 100000, currency: 'JPY', effective_at: EFFECTIVE_AT, is_active: true },
|
|
61
|
+
// ...
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
up: async (queryInterface, Sequelize) => {
|
|
66
|
+
await queryInterface.bulkInsert(TABLE_NAME, TimestampSeedsSupplier.supplyAll(seeds), {})
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
down: async (queryInterface, Sequelize) => {
|
|
70
|
+
await queryInterface.bulkDelete(TABLE_NAME, { id: seeds.map(it => it.id) })
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 1. Directory structure (release-split master / dev-master / development)
|
|
76
|
+
|
|
77
|
+
Seeders live under `sequelize/seeders/` in three kinds of directory, each seeded by its own
|
|
78
|
+
`db:seed:*` script (`--seeders-path` picks the directory). What separates them is **environment**
|
|
79
|
+
(production vs dev / CI) and **kind of data** (canonical master vs operational fixtures).
|
|
80
|
+
|
|
81
|
+
| Directory | Script | Environment | Purpose |
|
|
82
|
+
| --- | --- | --- | --- |
|
|
83
|
+
| `master-000001/`, `master-000002/`, … | `db:seed:prod` | production | **Production canonical master** data, split **one directory per release** (6-digit sequence). Applied in ascending release order. Ids are stable / meaningful, often from `app/constants/*` or small sequential. |
|
|
84
|
+
| `dev-master/` | `db:seed:dev-master` | dev / CI (local + CI tests) | The **master** data used in the dev / CI environment. Re-exports the production master files (DRY), plus a few dev-only master samples that production creates via admin CRUD. |
|
|
85
|
+
| `development/` | `db:seed:dev` | dev / CI (local + CI tests) | **Operational fixture** data for unit tests — rows that in production are created at runtime through operations (user lists, payment lists, …), **not** master data. Organized as `*-suite` bundles. Large blocked ids (§4). |
|
|
86
|
+
|
|
87
|
+
- **Release-split master.** Each release gets its own `master-<6-digit>/` directory holding the
|
|
88
|
+
master data introduced or changed in that release; `db:seed:prod` applies the `master-*`
|
|
89
|
+
directories in ascending order, so later releases build on earlier ones and each release's master
|
|
90
|
+
additions are isolated and traceable. (The repo currently has a single pre-split `master/`; the
|
|
91
|
+
release split is the convention from here on.)
|
|
92
|
+
- **dev-master vs development.** `dev-master` is the *same kind of canonical / config data as
|
|
93
|
+
production master*, just loaded for dev / CI. `development` is *operationally-created data* (users,
|
|
94
|
+
payments, …) that production never seeds — it exists only to give unit tests (local + CI)
|
|
95
|
+
something to read. Both run only in dev / CI, never in production.
|
|
96
|
+
- `.directorykeeper.cjs` — a noop seeder (`up`/`down` do nothing) that keeps an otherwise-empty
|
|
97
|
+
directory tracked and safe for the runner. Do not delete it.
|
|
98
|
+
- **`db:refresh` (alias `npm run r`)** rebuilds the local DB: `NODE_ENV=development` → teardown →
|
|
99
|
+
migrate → **seed:dev-master** → **seed:dev**. It does **not** run `seed:prod` — the `master-*`
|
|
100
|
+
set is for production.
|
|
101
|
+
- **Re-export for DRY**: a `dev-master/` file that must be identical to production is just
|
|
102
|
+
`module.exports = require('../master-<release>/<same-name>.cjs')`, with a comment naming the
|
|
103
|
+
production master as the source of truth. Do not copy-paste the data.
|
|
104
|
+
|
|
105
|
+
Details — the `.directorykeeper` no-op, the `db:seed:*` scripts table, and the full re-export
|
|
106
|
+
example — are in [directory-structure.md](./references/directory-structure.md).
|
|
107
|
+
|
|
108
|
+
## 2. File notation (skeleton)
|
|
109
|
+
|
|
110
|
+
- **Require `TimestampSeedsSupplier`** from `@openreachtech/renchan-sequelize/lib/tools/...` (a
|
|
111
|
+
`.cjs`; seeders are CommonJS). Optionally `require` domain constants (`app/constants/*.cjs`) for
|
|
112
|
+
ids / names, so the seed and the app share one source of truth.
|
|
113
|
+
- **Intent comment** (`/* ... */`) near the top: what this seed is, and its design-doc / plan
|
|
114
|
+
reference. Domain prose is Japanese in this repo.
|
|
115
|
+
- **`TABLE_NAME`** is a string for a single table, or an **object** (`{ CUSTOMERS: 'customers', ...
|
|
116
|
+
}`) when one seeder fills several related tables (a "suite").
|
|
117
|
+
- **`seeds` arrays** hold plain row objects: explicit `id` first, then snake_case columns. Do **not**
|
|
118
|
+
put `created_at` / `updated_at` in the rows (§5).
|
|
119
|
+
- **`up`** runs `bulkInsert(TABLE, TimestampSeedsSupplier.supplyAll(seeds), {})`; **`down`** runs
|
|
120
|
+
`bulkDelete(TABLE, { id: seeds.map(it => it.id) })`.
|
|
121
|
+
- **Suites insert parent → child and delete child → parent** (reverse order), so a child's FK column
|
|
122
|
+
always sees its parent row, and deletes don't orphan. (There are no DB FK constraints —
|
|
123
|
+
`hor-sequelize-migration` — but ordering still keeps the data
|
|
124
|
+
coherent and mirrors real usage.)
|
|
125
|
+
- **Async fulfillment**: when a value must be computed (e.g. hashing a password via `Encipher`),
|
|
126
|
+
build the fulfilled array with `await Promise.all(seeds.map(fulfillX))` inside `up` before
|
|
127
|
+
`bulkInsert`; keep the plain `seeds` array for `down`'s id list.
|
|
128
|
+
|
|
129
|
+
The full skeleton, the suite example (parent → child insert / child → parent delete), and the
|
|
130
|
+
async-fulfillment example (e.g. password hashing) are in [notation.md](./references/notation.md).
|
|
131
|
+
|
|
132
|
+
## 3. Naming
|
|
133
|
+
|
|
134
|
+
A new seeder filename is `{timestamp}-{6-digit-seq}-{table_name}.cjs`, matching the migration
|
|
135
|
+
convention (e.g. `20260717135803-000001-customers.cjs`,
|
|
136
|
+
`20260717141020-000002-customers_suite.cjs`).
|
|
137
|
+
|
|
138
|
+
- **`{timestamp}`** is the creation time `YYYYMMDDHHmmss` (14 digits; `date +%Y%m%d%H%M%S`); files
|
|
139
|
+
run in **ascending timestamp = creation order** (same as migrations). **`{6-digit-seq}`** is a
|
|
140
|
+
zero-padded running number (`000001`, …). **`{table_name}`** is the physical table name in
|
|
141
|
+
snake_case (a suite uses `<domain>_suite`).
|
|
142
|
+
- **Order parents before children**: within a suite the file inserts parent → child; across files,
|
|
143
|
+
create the parent's seeder first so its timestamp is earlier and it runs first.
|
|
144
|
+
- **Older seeders** use the previous `<8-digit-seq>-<kebab-entity>.cjs` form; leave them, and write
|
|
145
|
+
new files in the timestamp form (the
|
|
146
|
+
`hor-sequelize-migration`
|
|
147
|
+
skill made the same transition).
|
|
148
|
+
- A `dev-master/` re-export **keeps the same filename** as the `master-*/` file it re-exports.
|
|
149
|
+
|
|
150
|
+
Details in [naming.md](./references/naming.md).
|
|
151
|
+
|
|
152
|
+
## 4. Id numbering (a 10,000-wide id block per seeder / per table)
|
|
153
|
+
|
|
154
|
+
**Every seed row has an explicit `id`, and each table's rows are given a distinct id block whose
|
|
155
|
+
step is 10,000.** Bases are 6-digit multiples of 10,000 **starting at `100000`** (`100000`,
|
|
156
|
+
`110000`, `120000`, …); rows increment by 1 within the block, so one block holds up to ~10,000 rows.
|
|
157
|
+
The same base may be reused across different suites — safe, because the rows land in different
|
|
158
|
+
tables.
|
|
159
|
+
|
|
160
|
+
**Development suites (`development/`)** give each table *within the suite* its own 10,000-step base
|
|
161
|
+
(reused across suites):
|
|
162
|
+
|
|
163
|
+
| Table position in the suite | id base | example |
|
|
164
|
+
| --- | --- | --- |
|
|
165
|
+
| 1st (root, e.g. `customers` / `admins`) | `100000` | `100001`, `100002`, … |
|
|
166
|
+
| 2nd (`*_basics`) | `110000` | `110001`, … |
|
|
167
|
+
| 3rd (`*_secrets`) | `120000` | `120001`, … |
|
|
168
|
+
| 4th (`*_password_hashes`) | `130000` | `130001`, … |
|
|
169
|
+
| 5th (`*_access_tokens`) | `140000` | `140101`, `140201`, … |
|
|
170
|
+
|
|
171
|
+
**dev-master master samples** get one 6-digit, 10,000-wide block per file (`100000`, `110000`, …); a
|
|
172
|
+
child table's block sits above its parent's so its FK ids stay readable.
|
|
173
|
+
|
|
174
|
+
**Production master (`master-*/`)** is exempt from blocks: ids are small sequential (`1`…`7`) or
|
|
175
|
+
taken from `app/constants` (`AI_PROVIDER.DEFAULT.ID`), because canonical data ids are stable and
|
|
176
|
+
meaningful.
|
|
177
|
+
|
|
178
|
+
Rules that hold across all of these:
|
|
179
|
+
|
|
180
|
+
- **Bases are 6 digits (`≥ 100000`).** A `≥ 100000` id exceeds `SMALLINT`'s max (32,767 signed /
|
|
181
|
+
65,535 unsigned), so a column wrongly declared `SMALLINT` in the migration **overflows and fails
|
|
182
|
+
at seed time** — the schema mistake is caught while seeding, not in production. Never use a
|
|
183
|
+
sub-100,000 base.
|
|
184
|
+
- **The step is 10,000.** Allocate the next free 6-digit multiple of 10,000 as a new seeder/table's
|
|
185
|
+
base; never overlap two blocks that could collide within a single table.
|
|
186
|
+
- **A foreign-key column in a seed holds an id from the referenced table's block**
|
|
187
|
+
(`software_package_id` → the packages block, `customer_id: 100001`). This is why bases must be
|
|
188
|
+
predictable.
|
|
189
|
+
- **Rows increment by 1 within a block**; for hierarchical data, use a **structured id** that still
|
|
190
|
+
fits inside the 10,000 block (access tokens use `14` + 2-digit customer + 2-digit sequence →
|
|
191
|
+
`140101`, `140201`, `140202`, all inside the `140000` block).
|
|
192
|
+
- **Why**: ids stay deterministic and non-colliding within a table, so `down` deletes exactly what
|
|
193
|
+
`up` inserted, cross-seed FKs resolve, and a row's origin is readable from its id. (Blocks are
|
|
194
|
+
per-table, so reusing `100000` in both `customers` and `admins` is safe.)
|
|
195
|
+
|
|
196
|
+
Details — the FK-reference and structured-id examples, and the legacy sub-6-digit `dev-master`
|
|
197
|
+
blocks — are in [id-numbering.md](./references/id-numbering.md).
|
|
198
|
+
|
|
199
|
+
## 5. Timestamps come from TimestampSeedsSupplier
|
|
200
|
+
|
|
201
|
+
Do **not** put `created_at` / `updated_at` in seed rows. `TimestampSeedsSupplier.supplyAll(seeds)`
|
|
202
|
+
injects both (set to "now") for every row; `deleted_at` defaults to null.
|
|
203
|
+
|
|
204
|
+
- `supplyOne` returns `{ created_at: now, updated_at: now, ...seed }`, so a row **can override** the
|
|
205
|
+
timestamps by including its own — but normally you don't.
|
|
206
|
+
- **Business datetimes are different** — a column that means something in the domain
|
|
207
|
+
(`registered_at`, `saved_at`, `effective_at`, `generated_at`, `expired_at`) **is** written
|
|
208
|
+
explicitly in the seed (it is not an audit column). This matches the model/migration split where
|
|
209
|
+
audit timestamps come from the framework and business datetimes are their own columns.
|
|
210
|
+
|
|
211
|
+
Details in [notation.md](./references/notation.md).
|
|
212
|
+
|
|
213
|
+
## 6. Development fixtures cover the app's operational cases
|
|
214
|
+
|
|
215
|
+
A `development/` seeder is not just "some rows to read" — it must **comprehensively cover the cases
|
|
216
|
+
that arise in the app's operation**, because a unit test can only exercise a branch if a matching
|
|
217
|
+
fixture row exists. Cover, at minimum:
|
|
218
|
+
|
|
219
|
+
- **Success cases** — normal, valid operations that go through.
|
|
220
|
+
- **Failure cases** — operations rejected by a business rule (validation, insufficient balance,
|
|
221
|
+
expired, over-limit, …).
|
|
222
|
+
- **Error cases** — abnormal / inconsistent states the code must still handle.
|
|
223
|
+
- **Status variety within the success cases** — one row per **distinct status** an entity defines
|
|
224
|
+
(`pending` / `active` / `suspended` / `withdrawn`, …), so every status branch has a fixture.
|
|
225
|
+
|
|
226
|
+
- **Why**: happy-path-only fixtures leave the failure / error / status branches with nothing to
|
|
227
|
+
read, so each test fabricates ad-hoc rows that drift from real data. Label each row's case with a
|
|
228
|
+
comment and keep it in the suite / id-block scheme (§1, §4) so the block reads as a case list.
|
|
229
|
+
- This applies to `development/` (operational fixtures) only — **not** to master / dev-master, which
|
|
230
|
+
hold canonical config data, not operational case variety.
|
|
231
|
+
|
|
232
|
+
Details — the case taxonomy, per-row labeling, and scoping coverage to what the app branches on —
|
|
233
|
+
are in [development-coverage.md](./references/development-coverage.md).
|
|
234
|
+
|
|
235
|
+
## 7. Keep every value distinct within a seeder (so a test mix-up is caught)
|
|
236
|
+
|
|
237
|
+
Choose seed values so that **the same value never appears in two different columns**. When a unit
|
|
238
|
+
test fails, distinct values make it obvious which column / seeder is involved, and they stop a
|
|
239
|
+
column mix-up from passing silently.
|
|
240
|
+
|
|
241
|
+
- **id vs FK / related columns**: never let a row's `id` and one of its other columns share a value.
|
|
242
|
+
The 6-digit 10,000-wide id blocks (§4) already put each table's ids in a different range, so a
|
|
243
|
+
row's `id` and its FK columns (which hold the *parent* table's block ids) never collide — keep it
|
|
244
|
+
that way. If `id` is `100001`, a `user_id` on the same row must sit in a different block (e.g. from
|
|
245
|
+
`110001`), never `100001`.
|
|
246
|
+
- **text columns**: columns like `username` and `name` must always hold **different** strings — do
|
|
247
|
+
not reuse one value for both.
|
|
248
|
+
- **Why**: if `id` and `user_id` are both `100001`, a test that accidentally reads `user_id` where it
|
|
249
|
+
meant `id` still finds a matching row and **passes** — a false positive. Distinct values make that
|
|
250
|
+
mistake fail loudly and point straight at the offending seeder (the same reasoning as keeping
|
|
251
|
+
test-case values unique).
|
|
252
|
+
|
|
253
|
+
Details in [id-numbering.md](./references/id-numbering.md).
|
|
254
|
+
|
|
255
|
+
## Applying to the local DB
|
|
256
|
+
|
|
257
|
+
After adding or changing a seeder, rebuild the local DB with **`npm run r`** (`db:refresh`:
|
|
258
|
+
teardown → migrate → seed:dev-master → seed:dev). To seed a single set without a full teardown, run
|
|
259
|
+
the matching script directly (`npm run db:seed:dev-master`, `db:seed:dev`, or `db:seed:prod`).
|
|
260
|
+
|
|
261
|
+
## Detail files
|
|
262
|
+
|
|
263
|
+
- [directory-structure.md](./references/directory-structure.md) — release-split master / dev-master
|
|
264
|
+
/ development, `.directorykeeper`, the `db:seed:*` scripts and `db:refresh` flow, the re-export
|
|
265
|
+
DRY pattern (§1)
|
|
266
|
+
- [notation.md](./references/notation.md) — file skeleton, `TimestampSeedsSupplier`, `TABLE_NAME`
|
|
267
|
+
string vs object, `seeds` arrays, `bulkInsert` / `bulkDelete`, suites and insert/delete order,
|
|
268
|
+
async fulfillment, timestamps (§2, §5)
|
|
269
|
+
- [naming.md](./references/naming.md) — `{timestamp}-{6-digit-seq}-{table_name}.cjs`, timestamp /
|
|
270
|
+
creation-order ordering, `_suite`, release-dir naming (§3)
|
|
271
|
+
- [id-numbering.md](./references/id-numbering.md) — the 10,000-wide id-block rule, the block tables,
|
|
272
|
+
FK references, structured ids, master exemption, legacy blocks (§4); keeping every value distinct
|
|
273
|
+
across columns so a test mix-up is caught (§7)
|
|
274
|
+
- [development-coverage.md](./references/development-coverage.md) — what rows a `development/` seeder
|
|
275
|
+
must hold: success / failure / error cases and status variety, and per-row case labeling (§6)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Development fixtures cover the app's operational cases
|
|
2
|
+
|
|
3
|
+
How to decide *what rows* a `development/` seeder holds. Referenced from §6 of `SKILL.md`.
|
|
4
|
+
For where `development/` sits among the directories see
|
|
5
|
+
[directory-structure.md](./directory-structure.md); for the suite / id-block mechanics see
|
|
6
|
+
[naming.md](./naming.md) and [id-numbering.md](./id-numbering.md).
|
|
7
|
+
|
|
8
|
+
## Seed every case the app can produce, not just the happy path
|
|
9
|
+
|
|
10
|
+
`development/` fixtures exist so unit tests (local + CI) have realistic rows to read
|
|
11
|
+
([directory-structure.md](./directory-structure.md)). A test can only exercise a branch if a row
|
|
12
|
+
matching that branch already exists. So a `development/` seeder must **comprehensively cover the
|
|
13
|
+
cases that arise in the app's operation**, not only the normal success path:
|
|
14
|
+
|
|
15
|
+
- **Success cases** — valid, normal operations that go through.
|
|
16
|
+
- **Failure cases** — operations rejected by a business rule (validation failure, insufficient
|
|
17
|
+
balance, expired window, over-limit, …). The row is well-formed but represents a "no" outcome.
|
|
18
|
+
- **Error cases** — abnormal / exceptional states the code must still handle gracefully
|
|
19
|
+
(inconsistent or partially-written data, a record whose expected relation is missing, an
|
|
20
|
+
unexpected status, …).
|
|
21
|
+
- **Status variety within the success cases** — even among rows that "succeed", prepare a row for
|
|
22
|
+
**every distinct status** the entity defines (e.g. a user in `pending` / `active` / `suspended` /
|
|
23
|
+
`withdrawn`), so each status branch has a fixture to read. (Those status values are illustrative;
|
|
24
|
+
use the statuses the entity actually defines.)
|
|
25
|
+
|
|
26
|
+
- **Why**: if the fixtures hold only happy-path rows, tests for failure / error / status-specific
|
|
27
|
+
behavior have nothing to read, and each such test ends up fabricating its own rows inline —
|
|
28
|
+
repetitive, and drifting from the shape of real data. Comprehensive fixtures let a test pick the
|
|
29
|
+
row that matches the case under test. A missing case means that branch is either untested or
|
|
30
|
+
tested against ad-hoc data. This is the same QA stance the rest of these skills take: do not let
|
|
31
|
+
coverage be decided by whatever the fixtures happen to contain.
|
|
32
|
+
|
|
33
|
+
## Make each row's case readable
|
|
34
|
+
|
|
35
|
+
Because one table now holds rows for several different cases, label which case each row represents
|
|
36
|
+
so a test author can pick the right one at a glance.
|
|
37
|
+
|
|
38
|
+
- Add a short comment per row (or per group of rows) naming the case
|
|
39
|
+
(`// active`, `// suspended`, `// payment failed`, `// orphaned — error path`).
|
|
40
|
+
- Keep the rows inside the suite structure and the 10,000-wide id block
|
|
41
|
+
([id-numbering.md](./id-numbering.md)); group a status's rows on adjacent ids so the block reads as
|
|
42
|
+
a case list.
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// Good example (a customers suite covering the status range, plus a failure / error row)
|
|
46
|
+
const seeds = [
|
|
47
|
+
{ id: 100001, status: 'active', /* ... */ }, // active — normal
|
|
48
|
+
{ id: 100002, status: 'pending', /* ... */ }, // pending — awaiting approval
|
|
49
|
+
{ id: 100003, status: 'suspended', /* ... */ }, // suspended — blocked by an admin
|
|
50
|
+
{ id: 100004, status: 'withdrawn', /* ... */ }, // withdrawn — soft-left
|
|
51
|
+
{ id: 100005, status: 'active', /* ... */ }, // active but a downstream op will fail (failure-case source)
|
|
52
|
+
{ id: 100006, status: 'active', /* ... */ }, // relation intentionally missing (error path)
|
|
53
|
+
]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
// Bad example (only the happy path — suspended / withdrawn / failure / error branches have no fixture)
|
|
58
|
+
const seeds = [
|
|
59
|
+
{ id: 100001, status: 'active', /* ... */ },
|
|
60
|
+
{ id: 100002, status: 'active', /* ... */ },
|
|
61
|
+
]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Scope it to what the app actually branches on
|
|
65
|
+
|
|
66
|
+
"Comprehensive" means every case the code distinguishes — not a combinatorial explosion. Enumerate
|
|
67
|
+
the statuses / outcomes the app's logic actually branches on and seed one representative row per
|
|
68
|
+
branch, plus the failure / error rows the paths must handle.
|
|
69
|
+
|
|
70
|
+
- Where two axes interact (status × plan, say) and a test needs the combination, add that
|
|
71
|
+
combination as its own labelled row — do not try to seed every possible pair.
|
|
72
|
+
- This coverage rule is for `development/` (operational fixtures) only. It does **not** apply to
|
|
73
|
+
master / dev-master, which hold canonical config data, not operational case variety
|
|
74
|
+
([directory-structure.md](./directory-structure.md)).
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Directory structure (release-split master / dev-master / development)
|
|
2
|
+
|
|
3
|
+
The three kinds of seeder directory, what each is for, the `db:seed:*` scripts, and the re-export
|
|
4
|
+
DRY pattern. Referenced from §1 of `SKILL.md`.
|
|
5
|
+
|
|
6
|
+
## Two axes: environment, and kind of data
|
|
7
|
+
|
|
8
|
+
Every seeder directory is classified by **environment** (production vs dev / CI) and **kind of
|
|
9
|
+
data** (canonical master vs operational fixtures). This is what tells you where a new seeder
|
|
10
|
+
belongs.
|
|
11
|
+
|
|
12
|
+
| Directory | Script (`--seeders-path`) | Environment | Kind of data |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| `master-000001/`, `master-000002/`, … | `db:seed:prod` | production | Canonical **master** (reference / config) data. |
|
|
15
|
+
| `dev-master/` | `db:seed:dev-master` | dev / CI (local + CI tests) | The **master** data for dev / CI. |
|
|
16
|
+
| `development/` | `db:seed:dev` | dev / CI (local + CI tests) | **Operational fixtures** for unit tests. |
|
|
17
|
+
|
|
18
|
+
- **Deciding where a seeder goes**: is it canonical data the running product depends on (providers,
|
|
19
|
+
models, tools, agents, JSON schemas, wizard templates, day-rates, packages)? → master. Is it data
|
|
20
|
+
a user / operator would create at runtime (customers, admins, payments, orders)? → `development`,
|
|
21
|
+
and only to give tests something to read.
|
|
22
|
+
|
|
23
|
+
## Production master is split one directory per release
|
|
24
|
+
|
|
25
|
+
Production master seeders are organized into **release-numbered directories**
|
|
26
|
+
`master-<6-digit>/` — `master-000001/`, `master-000002/`, `master-000003/`, … — each holding the
|
|
27
|
+
master data introduced or changed in that release.
|
|
28
|
+
|
|
29
|
+
- `db:seed:prod` applies the `master-*` directories **in ascending order**, so a later release
|
|
30
|
+
builds on the state left by earlier ones. Each release's master additions stay isolated and
|
|
31
|
+
traceable to the release that shipped them.
|
|
32
|
+
- **Current state**: the repo still has a single, pre-split `sequelize/seeders/master/`, and
|
|
33
|
+
`db:seed:prod` targets it directly. The release split is the **convention from here on**; the
|
|
34
|
+
`db:seed:prod` script is updated to enumerate `master-*` in order when the split lands.
|
|
35
|
+
- Within a release dir, files keep the normal seeder skeleton and the standard seeder filename
|
|
36
|
+
([naming.md](./naming.md)).
|
|
37
|
+
|
|
38
|
+
## dev-master vs development — the key distinction
|
|
39
|
+
|
|
40
|
+
Both run **only in dev / CI** (local machines and CI test runs), never in production. What differs
|
|
41
|
+
is the *kind* of data:
|
|
42
|
+
|
|
43
|
+
- **`dev-master/`** — the **same kind of canonical / config data as production master**, just loaded
|
|
44
|
+
into the dev / CI database. It mostly **re-exports** the production master files (so dev / CI sees
|
|
45
|
+
exactly production's master state), plus a few dev-only master samples for data that production
|
|
46
|
+
creates through the admin CRUD rather than through a seeder (e.g. `content-plan-rates`,
|
|
47
|
+
`software-packages`).
|
|
48
|
+
- **`development/`** — **operationally-created data**: rows that in production come into existence at
|
|
49
|
+
runtime through normal operation (customer lists, admin lists, payment lists, orders, …).
|
|
50
|
+
Production never seeds these. They exist purely to give **unit tests** (local + CI) realistic rows
|
|
51
|
+
to read. They are organized as `*-suite` bundles ([naming.md](./naming.md)) and use the large
|
|
52
|
+
10,000-wide id blocks ([id-numbering.md](./id-numbering.md)).
|
|
53
|
+
|
|
54
|
+
- **Why keep them separate**: master data is part of the product and ships to production; fixture
|
|
55
|
+
data is test scaffolding and must never reach production. Splitting the directories keeps that
|
|
56
|
+
boundary unambiguous, and lets `db:seed:prod` load master alone while `db:refresh` loads master +
|
|
57
|
+
fixtures for local work.
|
|
58
|
+
|
|
59
|
+
## The `.directorykeeper.cjs` no-op
|
|
60
|
+
|
|
61
|
+
Each directory contains a `.directorykeeper.cjs` whose `up` / `down` do nothing.
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
'use strict'
|
|
65
|
+
|
|
66
|
+
module.exports = {
|
|
67
|
+
async up () {
|
|
68
|
+
// noop
|
|
69
|
+
},
|
|
70
|
+
async down () {
|
|
71
|
+
// noop
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- **Why**: it keeps an otherwise-empty directory tracked in git and gives the seeder runner a valid
|
|
77
|
+
file to load even before any real seeder exists in that directory. Do not delete it.
|
|
78
|
+
|
|
79
|
+
## Scripts and the refresh flow
|
|
80
|
+
|
|
81
|
+
| Script | What it does |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `db:seed:prod` | seed the production `master-*` set (`--seeders-path` at the master dirs) |
|
|
84
|
+
| `db:seed:dev-master` | seed `sequelize/seeders/dev-master` |
|
|
85
|
+
| `db:seed:dev` | seed `sequelize/seeders/development` |
|
|
86
|
+
| `db:refresh` (alias `npm run r`) | `NODE_ENV=development` → teardown → migrate → **seed:dev-master** → **seed:dev** |
|
|
87
|
+
|
|
88
|
+
- `db:refresh` deliberately runs **dev-master + development** and **not** `seed:prod` — dev / CI
|
|
89
|
+
wants the master config plus the test fixtures, and the release-split `master-*` set is for
|
|
90
|
+
production.
|
|
91
|
+
- After changing any seeder, run `npm run r` to rebuild the local DB (or run the single matching
|
|
92
|
+
`db:seed:*` script to load just that set without a full teardown).
|
|
93
|
+
|
|
94
|
+
## Re-export a production master file (DRY)
|
|
95
|
+
|
|
96
|
+
When a `dev-master/` file must be byte-for-byte the same as a production master file, do not
|
|
97
|
+
copy-paste — **re-export** it. Keep the same filename ([naming.md](./naming.md)).
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
// dev-master/20260717135803-000001-ai_models.cjs
|
|
101
|
+
'use strict'
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* dev-master duplicate: apply the same AI config as the production master in dev / CI (db:refresh).
|
|
105
|
+
* The real data/logic lives in the production master release dir (DRY).
|
|
106
|
+
*/
|
|
107
|
+
module.exports = require('../master-000001/20260717135803-000001-ai_models.cjs')
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- **Why**: dev / CI must exercise the *exact* master rows production ships. Re-exporting keeps a
|
|
111
|
+
single source of truth (the `master-*` file); copy-pasting would let the two drift silently.
|
|
112
|
+
- A `dev-master/` file that is **not** in production master (a dev-only sample) is a normal seeder,
|
|
113
|
+
not a re-export.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Id numbering (6-digit, 10,000-wide blocks)
|
|
2
|
+
|
|
3
|
+
How seed-row ids are allocated. Referenced from §4 of `SKILL.md`.
|
|
4
|
+
|
|
5
|
+
## The rule: a 6-digit, 10,000-wide id block per seeder / per table
|
|
6
|
+
|
|
7
|
+
**Every seed row has an explicit `id`, and each table's rows occupy a distinct id block whose step
|
|
8
|
+
is 10,000.** Bases are multiples of 10,000 **at or above `100000`** (6 digits): `100000`, `110000`,
|
|
9
|
+
`120000`, … Rows increment by 1 inside the block, so a block holds up to ~10,000 rows.
|
|
10
|
+
|
|
11
|
+
- **Explicit ids, never auto-increment.** `down` deletes by the exact id list
|
|
12
|
+
(`seeds.map(it => it.id)`), and other seeds' FK columns point at known ids — both need the id to
|
|
13
|
+
be fixed in the source.
|
|
14
|
+
- **Bases are 6 digits (`≥ 100000`).** Never use a sub-100,000 base (`1000`, `10000`, …). A 6-digit
|
|
15
|
+
id is larger than `SMALLINT`'s maximum (32,767 signed / 65,535 unsigned), so if a column was
|
|
16
|
+
mistakenly declared `SMALLINT` in the migration, the seed insert **overflows and fails at seed
|
|
17
|
+
time** — you catch the schema mistake while running the seeders, not later in production. This is
|
|
18
|
+
why ids go in the 100,000+ range rather than smaller blocks.
|
|
19
|
+
- **The step is 10,000.** Allocate the next free multiple of 10,000 (at or above 100,000) as a new
|
|
20
|
+
seeder / table's base; never let two blocks overlap in a way that could collide within a single
|
|
21
|
+
table.
|
|
22
|
+
- **A base may be reused across suites.** `customers` and `admins` both start at `100000` — safe,
|
|
23
|
+
because the rows land in different tables. Uniqueness only has to hold *within one table*.
|
|
24
|
+
|
|
25
|
+
## Development suites: a base per table within the suite
|
|
26
|
+
|
|
27
|
+
A `development/` suite gives each table *within the suite* its own 10,000-step base, and the same
|
|
28
|
+
bases recur across suites:
|
|
29
|
+
|
|
30
|
+
| Table position in the suite | id base | example rows |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
| 1st (root — `customers` / `admins`) | `100000` | `100001`, `100002`, … |
|
|
33
|
+
| 2nd (`*_basics`) | `110000` | `110001`, `110002`, … |
|
|
34
|
+
| 3rd (`*_secrets`) | `120000` | `120001`, … |
|
|
35
|
+
| 4th (`*_password_hashes`) | `130000` | `130001`, … |
|
|
36
|
+
| 5th (`*_access_tokens`) | `140000` | `140101`, `140201`, … |
|
|
37
|
+
|
|
38
|
+
## FK columns reference the parent block's ids
|
|
39
|
+
|
|
40
|
+
A seed's foreign-key column holds an id drawn from the referenced table's block, so the reference is
|
|
41
|
+
readable and stable.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
// software_package_options rows point at software_packages rows by their block ids
|
|
45
|
+
{ id: 530001, software_package_id: 520001, /* ... */ }
|
|
46
|
+
{ id: 530002, software_package_id: 520002, /* ... */ }
|
|
47
|
+
|
|
48
|
+
// customer_basics rows point at customers rows
|
|
49
|
+
{ id: 110001, customer_id: 100001, /* ... */ }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- This is why bases must be **predictable**: you allocate the parent's block first, then reference
|
|
53
|
+
those exact ids from the child block.
|
|
54
|
+
|
|
55
|
+
## Hierarchical rows: a structured id inside the block
|
|
56
|
+
|
|
57
|
+
For rows that fan out per parent, encode the hierarchy into the id while staying **inside the
|
|
58
|
+
10,000 block**. Access tokens use `14` + a 2-digit customer number + a 2-digit sequence:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
{ id: 140101, customer_id: 100001, /* first token of customer 01 */ }
|
|
62
|
+
{ id: 140201, customer_id: 100002, /* first token of customer 02 */ }
|
|
63
|
+
{ id: 140202, customer_id: 100002, /* second token of customer 02 */ }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `140101` … `143001` all sit inside the `140000` block, so the structuring does not break the
|
|
67
|
+
block rule.
|
|
68
|
+
|
|
69
|
+
## Production master is exempt
|
|
70
|
+
|
|
71
|
+
`master-*/` canonical data does **not** use the 6-digit 10,000-wide blocks. Its ids are small
|
|
72
|
+
sequential (`1`…`7`) or taken from `app/constants` (`AI_PROVIDER.DEFAULT.ID`).
|
|
73
|
+
|
|
74
|
+
- **Why exempt**: master ids are part of the product — stable, meaningful, and often referenced by
|
|
75
|
+
application code through a constant. A big fixture block would obscure that. Blocks are for
|
|
76
|
+
*fixture* data (`development/`, and dev-only samples in `dev-master/`), where the goal is
|
|
77
|
+
non-collision, traceability, and (via the 6-digit range) catching a `SMALLINT` mistake, rather
|
|
78
|
+
than a meaningful value.
|
|
79
|
+
|
|
80
|
+
## Why 6-digit blocks at all
|
|
81
|
+
|
|
82
|
+
- **SMALLINT detection**: a `≥ 100000` id overflows a `SMALLINT` column, so a wrong column type
|
|
83
|
+
fails at seed time instead of silently truncating.
|
|
84
|
+
- **Deterministic**: `down` removes exactly what `up` inserted.
|
|
85
|
+
- **Non-colliding within a table**: two seeders never fight over an id in the same table.
|
|
86
|
+
- **Cross-seed FKs resolve**: a child seed can hard-reference a parent id because the parent's block
|
|
87
|
+
is known.
|
|
88
|
+
- **Traceable**: a row's id tells you which seeder / table it came from at a glance.
|
|
89
|
+
|
|
90
|
+
## Keep different columns' values distinct (so a test mix-up is caught)
|
|
91
|
+
|
|
92
|
+
Beyond ids, choose seed values so that **the same value never appears in two different columns**. The
|
|
93
|
+
block scheme already does this for ids — a row's `id` (its own table's block) and its FK columns
|
|
94
|
+
(the *parent* table's block) always fall in different ranges, so they never share a value. Extend the
|
|
95
|
+
same discipline to every column.
|
|
96
|
+
|
|
97
|
+
- **id vs same-row FK / numeric columns**: keep them in different ranges. If a row's `id` is
|
|
98
|
+
`100001`, a `user_id` on that row must sit in a different block (e.g. from `110001`), never
|
|
99
|
+
`100001`. With the 6-digit 10,000-wide blocks this is automatic (`id: 110001` alongside
|
|
100
|
+
`customer_id: 100001`) — do not flatten them back onto the same value.
|
|
101
|
+
- **text columns**: give `username` and `name` (or any two string columns) **different** values;
|
|
102
|
+
never reuse one string for both.
|
|
103
|
+
- **Why**: if `id` and `user_id` are both `100001`, a unit test that accidentally reads `user_id`
|
|
104
|
+
where it meant `id` still matches a row and **passes** — a false positive that hides the bug.
|
|
105
|
+
Distinct values make the mistake fail loudly, and make it obvious, from the value in the failure
|
|
106
|
+
output, which seeder and column are involved. (This is the seeder counterpart of keeping test-case
|
|
107
|
+
values unique.)
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
// Bad example (id == user_id, and username == name — a column mix-up would pass silently)
|
|
111
|
+
{ id: 100001, user_id: 100001, username: 'taro', name: 'taro' }
|
|
112
|
+
|
|
113
|
+
// Good example (every column in its own value range / space)
|
|
114
|
+
{ id: 110001, user_id: 100001, username: 'user-110001', name: 'Alpha Taro' }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Blocks already in use
|
|
118
|
+
|
|
119
|
+
These tables already occupy the following 6-digit blocks; do not reuse a base for a new seeder in
|
|
120
|
+
the same table:
|
|
121
|
+
|
|
122
|
+
| Table | id base |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| `content_plan_rates` | `500000` |
|
|
125
|
+
| `content_benchmark_samples` | `510000` |
|
|
126
|
+
| `software_packages` | `520000` |
|
|
127
|
+
| `software_package_options` | `530000` |
|
|
128
|
+
| `integration_clients` | `600000` |
|
|
129
|
+
|
|
130
|
+
- A child table's block sits above its parent's so FK ids stay readable
|
|
131
|
+
(`software_package_options` `530000` references `software_packages` `520000`).
|
|
132
|
+
- Older seeders that were written before the 6-digit rule and still sit on a narrower / sub-6-digit
|
|
133
|
+
block should be renumbered into a 6-digit block (above) the next time they are touched.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Naming (filename, ordering, suites)
|
|
2
|
+
|
|
3
|
+
How to name a seeder file and why the ordering matters. Referenced from §3 of `SKILL.md`.
|
|
4
|
+
|
|
5
|
+
## Filename `{timestamp}-{6-digit-seq}-{table_name}.cjs`
|
|
6
|
+
|
|
7
|
+
A new seeder filename is a creation timestamp, a 6-digit running sequence, then the table name:
|
|
8
|
+
`20260717135803-000001-customers.cjs`, `20260717140512-000002-content_plan_rates.cjs`.
|
|
9
|
+
|
|
10
|
+
- **`{timestamp}`** is the creation time `YYYYMMDDHHmmss` (14 digits; `date +%Y%m%d%H%M%S`), matching
|
|
11
|
+
the migration convention
|
|
12
|
+
(`hor-sequelize-migration`).
|
|
13
|
+
Files are applied in **ascending timestamp order** — i.e. in creation-time order.
|
|
14
|
+
- **`{6-digit-seq}`** is a zero-padded running number (`000001`, `000002`, …). It orders files that
|
|
15
|
+
share a timestamp and doubles as a human-facing identifier.
|
|
16
|
+
- **`{table_name}`** is the physical table name in **snake_case** — the same name as the seeder's
|
|
17
|
+
`TABLE_NAME` and the migration's table. For a **suite** that fills several related tables, use the
|
|
18
|
+
domain root + `_suite` (`customers_suite`, `admin_roles_suite`).
|
|
19
|
+
- Examples: `20260717135803-000001-customers.cjs`,
|
|
20
|
+
`20260717141020-000002-customers_suite.cjs`,
|
|
21
|
+
`20260717142230-000003-ai_model_tool_assignments.cjs`.
|
|
22
|
+
- **Older seeders** predate this and use the `<8-digit-seq>-<kebab-entity>.cjs` form
|
|
23
|
+
(`00050002-ai-models.cjs`). Leave them as-is; write **new** files in the timestamp form above.
|
|
24
|
+
|
|
25
|
+
## Ordering is by timestamp (creation order) — seed parents before children
|
|
26
|
+
|
|
27
|
+
sequelize-cli runs seeders in **filename order**, which under this scheme is **ascending timestamp =
|
|
28
|
+
creation order** (the same as migrations). A child seed can only reference a parent id that already
|
|
29
|
+
exists, so the parent's rows must be inserted first.
|
|
30
|
+
|
|
31
|
+
- **Within a suite**, the file itself inserts parent → child (and deletes child → parent), so most
|
|
32
|
+
FK dependencies are satisfied inside the one file ([notation.md](./notation.md)).
|
|
33
|
+
- **Across files**, create the parent's seeder **before** the child's, so its timestamp is earlier
|
|
34
|
+
and it runs first. (This replaces the older scheme, where an 8-digit prefix mirrored the migration
|
|
35
|
+
domain group to force the order; with timestamps, creation order does the same job.)
|
|
36
|
+
|
|
37
|
+
## Suites bundle a domain's tables under one `_suite` file
|
|
38
|
+
|
|
39
|
+
A `*_suite.cjs` file seeds a whole cluster of related tables in one place (root + its dependent
|
|
40
|
+
tables), with `TABLE_NAME` as an object and parent→child insert / child→parent delete
|
|
41
|
+
([notation.md](./notation.md)).
|
|
42
|
+
|
|
43
|
+
- Use a suite when the tables are only meaningful together (a customer plus its basics, secrets,
|
|
44
|
+
password hash, access tokens). Use a plain single-table name otherwise.
|
|
45
|
+
|
|
46
|
+
## Production master: release directory naming
|
|
47
|
+
|
|
48
|
+
Production master files live under a release-numbered directory `master-<6-digit>/`
|
|
49
|
+
(`master-000001/`, `master-000002/`, …) — [directory-structure.md](./directory-structure.md). The
|
|
50
|
+
release number lives on the **directory**; the **file** inside uses the standard seeder filename.
|
|
51
|
+
|
|
52
|
+
## A dev-master re-export keeps the same filename
|
|
53
|
+
|
|
54
|
+
A `dev-master/` file that re-exports a production master file
|
|
55
|
+
([directory-structure.md](./directory-structure.md)) **keeps the identical filename** as the
|
|
56
|
+
`master-*/` file it points at.
|
|
57
|
+
|
|
58
|
+
- **Why**: matching filenames make the correspondence obvious and keep the two directories aligned
|
|
59
|
+
file-for-file, so it is easy to see which production master files have a dev / CI counterpart.
|