ObjectStackObjectStack

Migration

Migration protocol schemas

Source: packages/spec/src/system/migration.zod.ts

TypeScript Usage

import { AddFieldOperation, ChangeSet, CreateObjectOperation, DeleteObjectOperation, ExecuteSqlOperation, MigrationDependency, MigrationOperation, ModifyFieldOperation, RemoveFieldOperation, RenameObjectOperation } from '@objectstack/spec/system';
import type { AddFieldOperation, ChangeSet, CreateObjectOperation, DeleteObjectOperation, ExecuteSqlOperation, MigrationDependency, MigrationOperation, ModifyFieldOperation, RemoveFieldOperation, RenameObjectOperation } from '@objectstack/spec/system';

// Validate data
const result = AddFieldOperation.parse(data);

AddFieldOperation

Add a new field to an existing object

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringTarget object name
fieldNamestringName of the field to add
fieldObjectFull field definition to add

ChangeSet

A versioned set of atomic schema migration operations

Properties

PropertyTypeRequiredDescription
idstringUnique identifier for this change set
namestringHuman readable name for the migration
descriptionstringoptionalDetailed description of what this migration does
authorstringoptionalAuthor who created this migration
createdAtstringoptionalISO 8601 timestamp when the migration was created
dependenciesObject[]optionalMigrations that must run before this one
operationsObject | Object | Object | Object | Object | Object | Object[]Ordered list of atomic migration operations
rollbackObject | Object | Object | Object | Object | Object | Object[]optionalOperations to reverse this migration

CreateObjectOperation

Create a new object

Properties

PropertyTypeRequiredDescription
typestring
objectObjectFull object definition to create

DeleteObjectOperation

Delete an existing object

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringName of the object to delete

ExecuteSqlOperation

Execute a raw SQL statement

Properties

PropertyTypeRequiredDescription
typestring
sqlstringRaw SQL statement to execute
descriptionstringoptionalHuman-readable description of the SQL

MigrationDependency

Dependency reference to another migration that must run first

Properties

PropertyTypeRequiredDescription
migrationIdstringID of the migration this depends on
packagestringoptionalPackage that owns the dependency migration

MigrationOperation

Union Options

This schema accepts one of the following structures:

Option 1

Add a new field to an existing object

Type: add_field

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringTarget object name
fieldNamestringName of the field to add
fieldObjectFull field definition to add

Option 2

Modify properties of an existing field

Type: modify_field

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringTarget object name
fieldNamestringName of the field to modify
changesRecord<string, any>Partial field definition updates

Option 3

Remove a field from an existing object

Type: remove_field

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringTarget object name
fieldNamestringName of the field to remove

Option 4

Create a new object

Type: create_object

Properties

PropertyTypeRequiredDescription
typestring
objectObjectFull object definition to create

Option 5

Rename an existing object

Type: rename_object

Properties

PropertyTypeRequiredDescription
typestring
oldNamestringCurrent object name
newNamestringNew object name

Option 6

Delete an existing object

Type: delete_object

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringName of the object to delete

Option 7

Execute a raw SQL statement

Type: execute_sql

Properties

PropertyTypeRequiredDescription
typestring
sqlstringRaw SQL statement to execute
descriptionstringoptionalHuman-readable description of the SQL


ModifyFieldOperation

Modify properties of an existing field

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringTarget object name
fieldNamestringName of the field to modify
changesRecord<string, any>Partial field definition updates

RemoveFieldOperation

Remove a field from an existing object

Properties

PropertyTypeRequiredDescription
typestring
objectNamestringTarget object name
fieldNamestringName of the field to remove

RenameObjectOperation

Rename an existing object

Properties

PropertyTypeRequiredDescription
typestring
oldNamestringCurrent object name
newNamestringNew object name

On this page