Search code examples
sqlsynchronizationtransformationbeanshellsymmetricds

Symmetricds Transform Single Table to Multiple Tables Example


Please provide an example configuration of Transformation of a Single Table to Multiple Tables

Practical Scenario: I have a corp node and store node. I have two tables customers and imp_customers in the corp node, I have one table customers in the store node.

I have to do a transform from customers node in store to customers and imp_customers in cloud node. Please give an example configuration of the above transform in SymmetricDS 3.5 using sym_transfrom_table and sym_transform_column.


Solution

  • To do a transform from a single table to multiple tables,
    Step 1:- First setup a trigger for the table and link it to a router (Please ignore if already have triggers)
    Step 2:- Create a row in SYM_TRANSFORM_TABLE, where we specify the direction of data, when to perform the transform, and the tables involved.

     insert into SYM_TRANSFORM_TABLE(transform_id, source_node_group_id, 
        target_node_group_id, transform_point, source_table_name, target_table_name,
        delete_action, column_policy) values 
        ('customers_to_imp_customers', 'store', 'corp',
        'EXTRACT','customers', 'imp_customers', 'NONE', 'SPECIFIED'),
        ('customers_to_customers', 'store', 'corp',
        'EXTRACT','customers', 'customers', 'NONE', 'IMPLIED');
    

    Step 3:- Create rows in SYM_TRAMSFORM_COLUMN, where we specify the columns which we want to transform and the type of transform

    insert into SYM_TRANSFORM_COLUMN
    (transform_id, include_on, source_column_name, target_column_name, pk, transform_type)
    values
    ('customers_to_imp_customers', '*', 'id', 'id', 1, 'copy'),
    ('customers_to_imp_customers', '*', 'name', 'customer_name', 1, 'copy'),
    ('customers_to_customers', '*', 'id', 'id', 0, 'copy');