edinburgh 0.4.4 → 0.4.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.
Files changed (53) hide show
  1. package/README.md +58 -101
  2. package/build/src/migrate-cli.d.ts +1 -16
  3. package/build/src/migrate-cli.js +56 -42
  4. package/build/src/migrate-cli.js.map +1 -1
  5. package/build/src/migrate.d.ts +15 -11
  6. package/build/src/migrate.js +53 -39
  7. package/build/src/migrate.js.map +1 -1
  8. package/build/src/models.d.ts +1 -1
  9. package/build/src/models.js +2 -2
  10. package/build/src/models.js.map +1 -1
  11. package/package.json +6 -4
  12. package/skill/BaseIndex.md +16 -0
  13. package/skill/BaseIndex_batchProcess.md +10 -0
  14. package/skill/BaseIndex_find.md +7 -0
  15. package/skill/DatabaseError.md +9 -0
  16. package/skill/Model.md +22 -0
  17. package/skill/Model_delete.md +14 -0
  18. package/skill/Model_findAll.md +12 -0
  19. package/skill/Model_getPrimaryKeyHash.md +5 -0
  20. package/skill/Model_isValid.md +14 -0
  21. package/skill/Model_migrate.md +34 -0
  22. package/skill/Model_preCommit.md +28 -0
  23. package/skill/Model_preventPersist.md +15 -0
  24. package/skill/Model_replaceInto.md +16 -0
  25. package/skill/Model_validate.md +21 -0
  26. package/skill/PrimaryIndex.md +8 -0
  27. package/skill/PrimaryIndex_get.md +17 -0
  28. package/skill/PrimaryIndex_getLazy.md +13 -0
  29. package/skill/SKILL.md +90 -720
  30. package/skill/SecondaryIndex.md +9 -0
  31. package/skill/UniqueIndex.md +9 -0
  32. package/skill/UniqueIndex_get.md +17 -0
  33. package/skill/array.md +23 -0
  34. package/skill/dump.md +8 -0
  35. package/skill/field.md +29 -0
  36. package/skill/index.md +32 -0
  37. package/skill/init.md +17 -0
  38. package/skill/link.md +27 -0
  39. package/skill/literal.md +22 -0
  40. package/skill/opt.md +22 -0
  41. package/skill/or.md +22 -0
  42. package/skill/primary.md +26 -0
  43. package/skill/record.md +21 -0
  44. package/skill/registerModel.md +26 -0
  45. package/skill/runMigration.md +10 -0
  46. package/skill/set.md +23 -0
  47. package/skill/setMaxRetryCount.md +10 -0
  48. package/skill/setOnSaveCallback.md +12 -0
  49. package/skill/transact.md +49 -0
  50. package/skill/unique.md +32 -0
  51. package/src/migrate-cli.ts +44 -46
  52. package/src/migrate.ts +64 -46
  53. package/src/models.ts +2 -2
@@ -0,0 +1,9 @@
1
+ ### SecondaryIndex · class
2
+
3
+ Secondary index for non-unique lookups.
4
+
5
+ **Type Parameters:**
6
+
7
+ - `M extends typeof Model` - The model class this index belongs to.
8
+ - `F extends readonly (keyof InstanceType<M> & string)[]` - The field names that make up this index.
9
+ - `ARGS extends readonly any[] = IndexArgTypes<M, F>`
@@ -0,0 +1,9 @@
1
+ ### UniqueIndex · class
2
+
3
+ Unique index that stores references to the primary key.
4
+
5
+ **Type Parameters:**
6
+
7
+ - `M extends typeof Model` - The model class this index belongs to.
8
+ - `F extends readonly (keyof InstanceType<M> & string)[]` - The field names that make up this index.
9
+ - `ARGS extends readonly any[] = IndexArgTypes<M, F>`
@@ -0,0 +1,17 @@
1
+ #### uniqueIndex.get · method
2
+
3
+ Get a model instance by unique index key values.
4
+
5
+ **Signature:** `(...args: ARGS) => InstanceType<M>`
6
+
7
+ **Parameters:**
8
+
9
+ - `args: ARGS` - - The unique index key values.
10
+
11
+ **Returns:** The model instance if found, undefined otherwise.
12
+
13
+ **Examples:**
14
+
15
+ ```typescript
16
+ const userByEmail = User.byEmail.get("john@example.com");
17
+ ```
package/skill/array.md ADDED
@@ -0,0 +1,23 @@
1
+ ### array · function
2
+
3
+ Create an array type wrapper with optional length constraints.
4
+
5
+ **Signature:** `<const T>(inner: TypeWrapper<T>, opts?: { min?: number; max?: number; }) => TypeWrapper<T[]>`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T` - The element type.
10
+
11
+ **Parameters:**
12
+
13
+ - `inner: TypeWrapper<T>` - - Type wrapper for array elements.
14
+ - `opts: {min?: number, max?: number}` (optional) - - Optional constraints (min/max length).
15
+
16
+ **Returns:** An array type instance.
17
+
18
+ **Examples:**
19
+
20
+ ```typescript
21
+ const stringArray = E.array(E.string);
22
+ const boundedArray = E.array(E.number, {min: 1, max: 10});
23
+ ```
package/skill/dump.md ADDED
@@ -0,0 +1,8 @@
1
+ ### dump · function
2
+
3
+ Dump database contents for debugging.
4
+
5
+ Prints all indexes and their data to the console for inspection.
6
+ This is primarily useful for development and debugging purposes.
7
+
8
+ **Signature:** `() => void`
package/skill/field.md ADDED
@@ -0,0 +1,29 @@
1
+ ### field · function
2
+
3
+ Create a field definition for a model property.
4
+
5
+ This function uses TypeScript magic to return the field configuration object
6
+ while appearing to return the actual field value type to the type system.
7
+ This allows for both runtime introspection and compile-time type safety.
8
+
9
+ **Signature:** `<T>(type: TypeWrapper<T>, options?: Partial<FieldConfig<T>>) => T`
10
+
11
+ **Type Parameters:**
12
+
13
+ - `T` - The field type.
14
+
15
+ **Parameters:**
16
+
17
+ - `type: TypeWrapper<T>` - - The type wrapper for this field.
18
+ - `options: Partial<FieldConfig<T>>` (optional) - - Additional field configuration options.
19
+
20
+ **Returns:** The field value (typed as T, but actually returns FieldConfig<T>).
21
+
22
+ **Examples:**
23
+
24
+ ```typescript
25
+ class User extends E.Model<User> {
26
+ name = E.field(E.string, {description: "User's full name"});
27
+ age = E.field(E.opt(E.number), {description: "User's age", default: 25});
28
+ }
29
+ ```
package/skill/index.md ADDED
@@ -0,0 +1,32 @@
1
+ ### index · function
2
+
3
+ Create a secondary index on model fields, or a computed secondary index using a function.
4
+
5
+ For field-based indexes, pass a field name or array of field names.
6
+ For computed indexes, pass a function that takes a model instance and returns an array of
7
+ index keys. Return `[]` to skip indexing for that instance. Each array element creates a
8
+ separate index entry, enabling multi-value indexes (e.g., indexing by each word in a name).
9
+
10
+ **Signature:** `{ <M extends typeof Model, V>(MyModel: M, fn: (instance: InstanceType<M>) => V[]): SecondaryIndex<M, [], [V]>; <M extends typeof Model, const F extends (keyof InstanceType<M> & string)>(MyModel: M, field: F): SecondaryIndex<...>; <M extends typeof Model, const FS extends readonly (keyof InstanceType<M> & string)[]>(...`
11
+
12
+ **Type Parameters:**
13
+
14
+ - `M extends typeof Model` - The model class.
15
+ - `V` - The computed index value type (for function-based indexes).
16
+
17
+ **Parameters:**
18
+
19
+ - `MyModel: M` - - The model class to create the index for.
20
+ - `fn: (instance: InstanceType<M>) => V[]`
21
+
22
+ **Returns:** A new SecondaryIndex instance.
23
+
24
+ **Examples:**
25
+
26
+ ```typescript
27
+ class User extends E.Model<User> {
28
+ static byAge = E.index(User, "age");
29
+ static byTagsDate = E.index(User, ["tags", "createdAt"]);
30
+ static byWord = E.index(User, (u: User) => u.name.split(" "));
31
+ }
32
+ ```
package/skill/init.md ADDED
@@ -0,0 +1,17 @@
1
+ ### init · function
2
+
3
+ Initialize the database with the specified directory path.
4
+ This function may be called multiple times with the same parameters. If it is not called before the first transact(),
5
+ the database will be automatically initialized with the default directory.
6
+
7
+ **Signature:** `(dbDir: string) => void`
8
+
9
+ **Parameters:**
10
+
11
+ - `dbDir: string`
12
+
13
+ **Examples:**
14
+
15
+ ```typescript
16
+ init("./my-database");
17
+ ```
package/skill/link.md ADDED
@@ -0,0 +1,27 @@
1
+ ### link · function
2
+
3
+ Create a link type wrapper for model relationships.
4
+
5
+ **Signature:** `<const T extends typeof Model<any>>(TargetModel: T) => TypeWrapper<InstanceType<T>>`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T extends typeof Model<any>` - The target model class.
10
+
11
+ **Parameters:**
12
+
13
+ - `TargetModel: T` - - The model class this link points to.
14
+
15
+ **Returns:** A link type instance.
16
+
17
+ **Examples:**
18
+
19
+ ```typescript
20
+ class User extends E.Model<User> {
21
+ posts = E.field(E.array(E.link(Post, 'author')));
22
+ }
23
+
24
+ class Post extends E.Model<Post> {
25
+ author = E.field(E.link(User));
26
+ }
27
+ ```
@@ -0,0 +1,22 @@
1
+ ### literal · function
2
+
3
+ Create a literal type wrapper for a constant value.
4
+
5
+ **Signature:** `<const T>(value: T) => TypeWrapper<T>`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T` - The literal type.
10
+
11
+ **Parameters:**
12
+
13
+ - `value: T` - - The literal value.
14
+
15
+ **Returns:** A literal type instance.
16
+
17
+ **Examples:**
18
+
19
+ ```typescript
20
+ const statusType = E.literal("active");
21
+ const countType = E.literal(42);
22
+ ```
package/skill/opt.md ADDED
@@ -0,0 +1,22 @@
1
+ ### opt · function
2
+
3
+ Create an optional type wrapper (allows undefined).
4
+
5
+ **Signature:** `<const T extends TypeWrapper<unknown> | BasicType>(inner: T) => TypeWrapper<T extends TypeWrapper<infer U> ? U : T>`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T extends TypeWrapper<unknown>|BasicType` - Type wrapper or basic type to make optional.
10
+
11
+ **Parameters:**
12
+
13
+ - `inner: T` - - The inner type to make optional.
14
+
15
+ **Returns:** A union type that accepts the inner type or undefined.
16
+
17
+ **Examples:**
18
+
19
+ ```typescript
20
+ const optionalString = E.opt(E.string);
21
+ const optionalNumber = E.opt(E.number);
22
+ ```
package/skill/or.md ADDED
@@ -0,0 +1,22 @@
1
+ ### or · function
2
+
3
+ Create a union type wrapper from multiple type choices.
4
+
5
+ **Signature:** `<const T extends (TypeWrapper<unknown> | BasicType)[]>(...choices: T) => TypeWrapper<UnwrapTypes<T>>`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T extends (TypeWrapper<unknown>|BasicType)[]` - Array of type wrapper or basic types.
10
+
11
+ **Parameters:**
12
+
13
+ - `choices: T` - - The type choices for the union.
14
+
15
+ **Returns:** A union type instance.
16
+
17
+ **Examples:**
18
+
19
+ ```typescript
20
+ const stringOrNumber = E.or(E.string, E.number);
21
+ const status = E.or("active", "inactive", "pending");
22
+ ```
@@ -0,0 +1,26 @@
1
+ ### primary · function
2
+
3
+ Create a primary index on model fields.
4
+
5
+ **Signature:** `{ <M extends typeof Model, const F extends (keyof InstanceType<M> & string)>(MyModel: M, field: F): PrimaryIndex<M, [F]>; <M extends typeof Model, const FS extends readonly (keyof InstanceType<M> & string)[]>(MyModel: M, fields: FS): PrimaryIndex<...>; }`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `M extends typeof Model` - The model class.
10
+ - `F extends (keyof InstanceType<M> & string)` - The field name (for single field index).
11
+
12
+ **Parameters:**
13
+
14
+ - `MyModel: M` - - The model class to create the index for.
15
+ - `field: F` - - Single field name for simple indexes.
16
+
17
+ **Returns:** A new PrimaryIndex instance.
18
+
19
+ **Examples:**
20
+
21
+ ```typescript
22
+ class User extends E.Model<User> {
23
+ static pk = E.primary(User, ["id"]);
24
+ static pkSingle = E.primary(User, "id");
25
+ }
26
+ ```
@@ -0,0 +1,21 @@
1
+ ### record · function
2
+
3
+ Create a Record type wrapper for key-value objects with string or number keys.
4
+
5
+ **Signature:** `<const T>(inner: TypeWrapper<T>) => TypeWrapper<Record<string | number, T>>`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T` - The value type.
10
+
11
+ **Parameters:**
12
+
13
+ - `inner: TypeWrapper<T>` - - Type wrapper for record values.
14
+
15
+ **Returns:** A record type instance.
16
+
17
+ **Examples:**
18
+
19
+ ```typescript
20
+ const scores = E.record(E.number); // Record<string | number, number>
21
+ ```
@@ -0,0 +1,26 @@
1
+ ### registerModel · function
2
+
3
+ Register a model class with the Edinburgh ORM system.
4
+
5
+ **Signature:** `<T extends typeof Model<unknown>>(MyModel: T) => T`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T extends typeof Model<unknown>` - The model class type.
10
+
11
+ **Parameters:**
12
+
13
+ - `MyModel: T` - - The model class to register.
14
+
15
+ **Returns:** The enhanced model class with ORM capabilities.
16
+
17
+ **Examples:**
18
+
19
+ ```typescript
20
+ ⁣@E.registerModel
21
+ class User extends E.Model<User> {
22
+ static pk = E.index(User, ["id"], "primary");
23
+ id = E.field(E.identifier);
24
+ name = E.field(E.string);
25
+ }
26
+ ```
@@ -0,0 +1,10 @@
1
+ ### runMigration · function
2
+
3
+ Run database migration: populate secondary indexes for old-version rows,
4
+ convert old primary indices, rewrite row data, and clean up orphaned indices.
5
+
6
+ **Signature:** `(options?: MigrationOptions) => Promise<MigrationResult>`
7
+
8
+ **Parameters:**
9
+
10
+ - `options: MigrationOptions` (optional)
package/skill/set.md ADDED
@@ -0,0 +1,23 @@
1
+ ### set · function
2
+
3
+ Create a Set type wrapper with optional length constraints.
4
+
5
+ **Signature:** `<const T>(inner: TypeWrapper<T>, opts?: { min?: number; max?: number; }) => TypeWrapper<Set<T>>`
6
+
7
+ **Type Parameters:**
8
+
9
+ - `T` - The element type.
10
+
11
+ **Parameters:**
12
+
13
+ - `inner: TypeWrapper<T>` - - Type wrapper for set elements.
14
+ - `opts: {min?: number, max?: number}` (optional) - - Optional constraints (min/max length).
15
+
16
+ **Returns:** A set type instance.
17
+
18
+ **Examples:**
19
+
20
+ ```typescript
21
+ const stringSet = E.set(E.string);
22
+ const boundedSet = E.set(E.number, {min: 1, max: 10});
23
+ ```
@@ -0,0 +1,10 @@
1
+ ### setMaxRetryCount · function
2
+
3
+ Set the maximum number of retries for a transaction in case of conflicts.
4
+ The default value is 6. Setting it to 0 will disable retries and cause transactions to fail immediately on conflict.
5
+
6
+ **Signature:** `(count: number) => void`
7
+
8
+ **Parameters:**
9
+
10
+ - `count: number` - The maximum number of retries for a transaction.
@@ -0,0 +1,12 @@
1
+ ### setOnSaveCallback · function
2
+
3
+ Set a callback function to be called after a model is saved and committed.
4
+
5
+ **Signature:** `(callback: (commitId: number, items: Map<Model<any>, Change>) => void) => void`
6
+
7
+ **Parameters:**
8
+
9
+ - `callback: ((commitId: number, items: Map<Model<any>, Change>) => void) | undefined` - The callback function to set. It gets called after each successful
10
+ `transact()` commit that has changes, with the following arguments:
11
+ - A sequential number. Higher numbers have been committed after lower numbers.
12
+ - A map of model instances to their changes. The change can be "created", "deleted", or an object containing the old values.
@@ -0,0 +1,49 @@
1
+ ### transact · function
2
+
3
+ Executes a function within a database transaction context.
4
+
5
+ Loading models (also through links in other models) and changing models can only be done from
6
+ within a transaction.
7
+
8
+ Transactions have a consistent view of the database, and changes made within a transaction are
9
+ isolated from other transactions until they are committed. In case a commit clashes with changes
10
+ made by another transaction, the transaction function will automatically be re-executed up to 6
11
+ times.
12
+
13
+ **Signature:** `<T>(fn: () => T) => Promise<T>`
14
+
15
+ **Type Parameters:**
16
+
17
+ - `T` - The return type of the transaction function.
18
+
19
+ **Parameters:**
20
+
21
+ - `fn: () => T` - - The function to execute within the transaction context. Receives a Transaction instance.
22
+
23
+ **Returns:** A promise that resolves with the function's return value.
24
+
25
+ **Throws:**
26
+
27
+ - With code "RACING_TRANSACTION" if the transaction fails after retries due to conflicts.
28
+ - With code "TXN_LIMIT" if maximum number of transactions is reached.
29
+ - With code "LMDB-{code}" for LMDB-specific errors.
30
+
31
+ **Examples:**
32
+
33
+ ```typescript
34
+ const paid = await E.transact(() => {
35
+ const user = User.pk.get("john_doe");
36
+ if (user.credits > 0) {
37
+ user.credits--;
38
+ return true;
39
+ }
40
+ return false;
41
+ });
42
+ ```
43
+ ```typescript
44
+ // Transaction with automatic retry on conflicts
45
+ await E.transact(() => {
46
+ const counter = Counter.pk.get("global") || new Counter({id: "global", value: 0});
47
+ counter.value++;
48
+ });
49
+ ```
@@ -0,0 +1,32 @@
1
+ ### unique · function
2
+
3
+ Create a unique index on model fields, or a computed unique index using a function.
4
+
5
+ For field-based indexes, pass a field name or array of field names.
6
+ For computed indexes, pass a function that takes a model instance and returns an array of
7
+ index keys. Return `[]` to skip indexing for that instance. Each array element creates a
8
+ separate index entry, enabling multi-value indexes (e.g., indexing by each word in a name).
9
+
10
+ **Signature:** `{ <M extends typeof Model, V>(MyModel: M, fn: (instance: InstanceType<M>) => V[]): UniqueIndex<M, [], [V]>; <M extends typeof Model, const F extends (keyof InstanceType<M> & string)>(MyModel: M, field: F): UniqueIndex<...>; <M extends typeof Model, const FS extends readonly (keyof InstanceType<M> & string)[]>(MyMode...`
11
+
12
+ **Type Parameters:**
13
+
14
+ - `M extends typeof Model` - The model class.
15
+ - `V` - The computed index value type (for function-based indexes).
16
+
17
+ **Parameters:**
18
+
19
+ - `MyModel: M` - - The model class to create the index for.
20
+ - `fn: (instance: InstanceType<M>) => V[]`
21
+
22
+ **Returns:** A new UniqueIndex instance.
23
+
24
+ **Examples:**
25
+
26
+ ```typescript
27
+ class User extends E.Model<User> {
28
+ static byEmail = E.unique(User, "email");
29
+ static byNameAge = E.unique(User, ["name", "age"]);
30
+ static byFullName = E.unique(User, (u: User) => [`${u.firstName} ${u.lastName}`]);
31
+ }
32
+ ```
@@ -1,22 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * migrate-edinburgh CLI tool
5
- *
6
- * Runs database migrations: upgrades all rows to the latest schema version,
7
- * converts old primary indices, and cleans up orphaned secondary indices.
8
- *
9
- * Usage:
10
- * npx migrate-edinburgh --import ./src/models.ts [options]
11
- *
12
- * Options:
13
- * --import <path> Path to the module that registers all models (required)
14
- * --db <path> Database directory (default: .edinburgh)
15
- * --tables <names> Comma-separated list of table names to migrate
16
- * --batch-size <n> Number of rows per transaction batch (default: 500)
17
- * --no-convert Skip converting old primary indices
18
- * --no-cleanup Skip deleting orphaned secondary indices
19
- * --no-upgrade Skip upgrading rows to latest version
4
+ * See `npx migrate-edinburgh --help` for usage.
20
5
  */
21
6
 
22
7
  import { runMigration, type MigrationOptions } from './migrate.js';
@@ -24,43 +9,49 @@ import { runMigration, type MigrationOptions } from './migrate.js';
24
9
  function parseArgs(args: string[]): { importPath: string, options: MigrationOptions & { dbDir?: string } } {
25
10
  let importPath = '';
26
11
  const options: MigrationOptions & { dbDir?: string } = {};
12
+ const tables: string[] = [];
27
13
 
28
14
  for (let i = 0; i < args.length; i++) {
29
- switch (args[i]) {
30
- case '--import':
31
- importPath = args[++i];
32
- break;
15
+ const arg = args[i];
16
+ switch (arg) {
33
17
  case '--db':
34
18
  options.dbDir = args[++i];
35
19
  break;
36
- case '--tables':
37
- options.tables = args[++i].split(',').map(s => s.trim());
38
- break;
39
- case '--no-convert':
40
- options.convertOldPrimaries = false;
41
- break;
42
- case '--no-cleanup':
43
- options.deleteOrphanedIndexes = false;
44
- break;
45
- case '--no-upgrade':
46
- options.upgradeVersions = false;
47
- break;
20
+ case '+secondaries': options.populateSecondaries = true; break;
21
+ case '-secondaries': options.populateSecondaries = false; break;
22
+ case '+primaries': options.migratePrimaries = true; break;
23
+ case '-primaries': options.migratePrimaries = false; break;
24
+ case '+data': options.rewriteData = true; break;
25
+ case '-data': options.rewriteData = false; break;
26
+ case '+orphans': options.removeOrphans = true; break;
27
+ case '-orphans': options.removeOrphans = false; break;
48
28
  default:
49
- if (args[i].startsWith('-')) {
50
- console.error(`Unknown option: ${args[i]}`);
29
+ if (arg.startsWith('-') || arg.startsWith('+')) {
30
+ console.error(`Unknown option: ${arg}`);
51
31
  process.exit(1);
52
32
  }
33
+ if (!importPath) {
34
+ importPath = arg;
35
+ } else {
36
+ tables.push(arg);
37
+ }
53
38
  }
54
39
  }
55
40
 
41
+ if (tables.length > 0) options.tables = tables;
42
+
56
43
  if (!importPath) {
57
- console.error('Usage: npx migrate-edinburgh --import <path> [options]');
58
- console.error(' --import <path> Module that registers all models (required)');
59
- console.error(' --db <path> Database directory (default: .edinburgh)');
60
- console.error(' --tables <names> Comma-separated table names');
61
- console.error(' --no-convert Skip old primary conversion');
62
- console.error(' --no-cleanup Skip orphaned index cleanup');
63
- console.error(' --no-upgrade Skip version upgrades');
44
+ console.error('Usage: npx migrate-edinburgh <import_path> [<table> ...] [options]');
45
+ console.error('');
46
+ console.error(' <import_path> Module that registers all models (required)');
47
+ console.error(' <table> Table names to migrate (default: all)');
48
+ console.error('');
49
+ console.error('Options:');
50
+ console.error(' --db <path> Database directory (default: .edinburgh)');
51
+ console.error(' -secondaries Skip populating secondary indexes');
52
+ console.error(' -primaries Skip migrating old primary indexes');
53
+ console.error(' -orphans Skip removing orphaned index entries');
54
+ console.error(' +data Rewrite all row data to latest schema version');
64
55
  process.exit(1);
65
56
  }
66
57
 
@@ -99,14 +90,21 @@ async function main() {
99
90
 
100
91
  // Report results
101
92
  if (Object.keys(result.secondaries).length > 0) {
102
- console.log('Upgraded rows:');
93
+ console.log('Populated secondary indexes:');
103
94
  for (const [table, count] of Object.entries(result.secondaries)) {
104
95
  console.log(` ${table}: ${count}`);
105
96
  }
106
97
  }
107
98
 
99
+ if (Object.keys(result.rewritten).length > 0) {
100
+ console.log('Rewritten rows:');
101
+ for (const [table, count] of Object.entries(result.rewritten)) {
102
+ console.log(` ${table}: ${count}`);
103
+ }
104
+ }
105
+
108
106
  if (Object.keys(result.primaries).length > 0) {
109
- console.log('Converted old primary rows:');
107
+ console.log('Migrated old primary rows:');
110
108
  for (const [table, count] of Object.entries(result.primaries)) {
111
109
  console.log(` ${table}: ${count}`);
112
110
  }
@@ -121,11 +119,11 @@ async function main() {
121
119
  }
122
120
  }
123
121
 
124
- if (result.orphaned > 0) {
125
- console.log(`Deleted ${result.orphaned} orphaned index entries`);
122
+ if (result.orphans > 0) {
123
+ console.log(`Deleted ${result.orphans} orphaned index entries`);
126
124
  }
127
125
 
128
- if (Object.keys(result.secondaries).length === 0 && Object.keys(result.primaries).length === 0 && result.orphaned === 0) {
126
+ if (Object.keys(result.secondaries).length === 0 && Object.keys(result.primaries).length === 0 && Object.keys(result.rewritten).length === 0 && result.orphans === 0) {
129
127
  console.log('No migration needed - database is up to date.');
130
128
  }
131
129