Skip to content

Commit 9f228a8

Browse files
Copilothuangyiirene
andcommitted
Add migration types for object and field update/delete instructions
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 3be2c87 commit 9f228a8

3 files changed

Lines changed: 388 additions & 0 deletions

File tree

packages/foundation/types/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ npm install @objectql/types
6666
- `Driver` - Database driver interface
6767
- `DriverConfig` - Driver configuration
6868

69+
### Migration & Schema Evolution Types
70+
- `SchemaChangeType` - Types of schema change operations
71+
- `SchemaChangeInstruction` - Union of all schema change instructions
72+
- `FieldUpdateInstruction` - Instruction to update/modify a field
73+
- `FieldDeleteInstruction` - Instruction to delete/remove a field
74+
- `ObjectUpdateInstruction` - Instruction to update/modify an object
75+
- `ObjectDeleteInstruction` - Instruction to delete/remove an object
76+
- `MigrationConfig` - Complete migration configuration
77+
- `MigrationStep` - Single step in a migration
78+
- `MigrationStatus` - Execution status of a migration
79+
6980
## Usage Examples
7081

7182
### Object Definition with Validation
@@ -253,6 +264,128 @@ interface FieldValidation {
253264
}
254265
```
255266

267+
### Migration & Schema Evolution
268+
269+
Define schema changes declaratively for object and field updates/deletions:
270+
271+
```typescript
272+
import {
273+
MigrationConfig,
274+
FieldUpdateInstruction,
275+
FieldDeleteInstruction,
276+
ObjectUpdateInstruction,
277+
ObjectDeleteInstruction
278+
} from '@objectql/types';
279+
280+
// Define a migration with multiple schema changes
281+
const migration: MigrationConfig = {
282+
id: 'v1.2_refactor_user_fields',
283+
version: '1.2.0',
284+
name: 'Refactor User Fields',
285+
description: 'Update user object schema and remove deprecated fields',
286+
author: 'dev-team',
287+
created_at: '2026-01-14T00:00:00Z',
288+
steps: [
289+
{
290+
id: 'rename_username_field',
291+
name: 'Rename username to user_name',
292+
instruction: {
293+
type: 'field_update',
294+
object_name: 'users',
295+
field_name: 'username',
296+
new_field_name: 'user_name',
297+
changes: {
298+
label: 'User Name',
299+
description: 'Updated field name for consistency'
300+
},
301+
data_migration_strategy: 'auto'
302+
} as FieldUpdateInstruction,
303+
reversible: true
304+
},
305+
{
306+
id: 'update_email_field',
307+
name: 'Make email field required',
308+
instruction: {
309+
type: 'field_update',
310+
object_name: 'users',
311+
field_name: 'email',
312+
changes: {
313+
required: true,
314+
unique: true
315+
},
316+
data_migration_strategy: 'auto'
317+
} as FieldUpdateInstruction,
318+
reversible: true
319+
},
320+
{
321+
id: 'delete_legacy_field',
322+
name: 'Remove deprecated legacy_id field',
323+
instruction: {
324+
type: 'field_delete',
325+
object_name: 'users',
326+
field_name: 'legacy_id',
327+
deletion_strategy: 'archive',
328+
archive_location: 'backup/users_legacy_id'
329+
} as FieldDeleteInstruction,
330+
reversible: true
331+
},
332+
{
333+
id: 'update_object_label',
334+
name: 'Update Users object label',
335+
instruction: {
336+
type: 'object_update',
337+
object_name: 'users',
338+
changes: {
339+
label: 'System Users',
340+
description: 'Updated to reflect new naming convention'
341+
}
342+
} as ObjectUpdateInstruction,
343+
reversible: true
344+
}
345+
],
346+
reversible: true,
347+
tags: ['schema', 'refactor']
348+
};
349+
```
350+
351+
**Field Update Example (Type Change):**
352+
353+
```typescript
354+
const changeFieldType: FieldUpdateInstruction = {
355+
type: 'field_update',
356+
object_name: 'products',
357+
field_name: 'price',
358+
changes: {
359+
type: 'currency', // Changed from 'number' to 'currency'
360+
defaultValue: 0
361+
},
362+
data_migration_strategy: 'manual',
363+
transform_script: `
364+
// Custom transformation for price field
365+
return {
366+
amount: oldValue,
367+
currency: 'USD'
368+
};
369+
`,
370+
description: 'Convert price from number to currency type',
371+
reason: 'Support multi-currency pricing'
372+
};
373+
```
374+
375+
**Object Deletion Example:**
376+
377+
```typescript
378+
const deleteObject: ObjectDeleteInstruction = {
379+
type: 'object_delete',
380+
object_name: 'temp_imports',
381+
deletion_strategy: 'archive',
382+
archive_location: 'backups/temp_imports_archive',
383+
cascade_strategy: 'nullify',
384+
description: 'Remove temporary import table',
385+
reason: 'No longer needed after migration to new import system'
386+
};
387+
```
388+
256389
## See Also
257390

258391
- [@objectql/core](../core) - Core engine with Validator class

packages/foundation/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export * from './page';
1616
export * from './loader';
1717
export * from './application';
1818
export * from './menu';
19+
export * from './migration';

0 commit comments

Comments
 (0)