Operations

Schema Update

The Schema Update operation allows you to modify the database schema of your target sink using custom JavaScript code. This operation is applied to update table structures, add or remove columns, or make other schema changes before data loading.

Overview

The Schema Update operation enables you to:

  • Write custom JavaScript code to modify database schemas
  • Add, remove, or alter table columns and structures
  • Implement custom schema migration logic
  • Ensure your target database schema matches your transformed data structure

Configuration

JavaScript Code Editor

The Schema Update operation provides a code editor where you can write custom JavaScript functions for schema modifications:

  1. The code should be a valid JavaScript function that defines schema changes
  2. The function can reference the current data structure to determine needed schema updates
  3. You can use platform-supported JavaScript features for schema manipulation

Examples

Basic Schema Update

To add a new column to your database schema:

  1. Add the Schema Update operation to your rule
  2. Write JavaScript code like:
// Example: Add a full_name column if it doesn't exist
if (!schema.columns.find(col => col.name === 'full_name')) {
  schema.columns.push({
    name: 'full_name',
    type: 'string',
    length: 255
  });
}
return schema;

Complex Schema Modifications

For more complex schema changes:

  1. Add the Schema Update operation to your rule
  2. Write JavaScript code that modifies the schema structure:
// Example: Rename a column and change its type
const emailColumn = schema.columns.find(col => col.name === 'email_address');
if (emailColumn) {
  emailColumn.name = 'email';
  emailColumn.type = 'string';
  emailColumn.length = 320;
}
 
// Example: Add indexes for better query performance
schema.indexes = schema.indexes || [];
schema.indexes.push({
  name: 'idx_email',
  columns: ['email'],
  unique: true
});
 
return schema;

This operation is particularly useful when your data transformation pipeline creates new fields or modifies existing ones, and you need to ensure the target database schema can accommodate these changes.

Best Practices

  • Always test schema update code in a development environment before applying to production
  • Consider the impact of schema changes on existing data and applications
  • Use conditional logic to check if schema changes are needed before applying them
  • Document your schema changes for future reference and maintenance

Important Notes

  • This operation only affects the database schema, not the actual data
  • Schema changes are applied to the target sink, not the source data
  • Make sure you have appropriate permissions to modify the database schema

On this page