Skip to main content
October 7, 2021
Solved

Migration

  • October 7, 2021
  • 11 replies
  • 0 views

Is it possible to migrate for instance a CDT but change the values to hide the real values?

    Best answer by csteward

    To randomize strings as such (and also apply the same to numeric values), create 2 helper rules:

    rule!chris_test_randomize_numeric(numeric)

    tointeger(
      joinarray(
        a!forEach(
          items: 1+enumerate(len(ri!numeric)),
          expression: {
            a!localVariables(
              local!random: tointeger(rand()*9-1)+1,
              if(
                and(
                  fv!isFirst,
                  local!random=0
                ),
                1, /* change to 1 to maintain length */
                local!random
              )
            )
          }
        )
      )
    )

    rule!chris_test_randomize_string(text)

    a!localVariables(
      local!alpha: "abcdefghijklmnopqrstuvwxyz",
      joinarray(
        a!forEach(
          items: code(ri!text),
          expression: {
            a!localVariables(
              local!random: index(local!alpha,tointeger(rand()*len(local!alpha)-1)+1,null),
              if(
                fv!item<97,
                upper(local!random),
                local!random
              )
            )
          }
        )
      )
    )

    Then call your new rules when converting your CDT:

    a!localVariables(
      local!data: {
        a!map(id: 1, firstName: "John", lastName: "Doe", salary: 50000),
        a!map(id: 2, firstName: "Jane", lastName: "Doe", salary: 55000),
        a!map(id: 3, firstName: "Timothy", lastName: "McDonald", salary: 45000)
      },
    
      a!forEach(
        items: local!data,
        expression: a!map(
          id: fv!item.id,
          firstName: rule!chris_test_randomize_string(text: fv!item.firstName),
          lastName: rule!chris_test_randomize_string(text: fv!item.lastName),
          salary: rule!chris_test_randomize_numeric(numeric: fv!item.salary)
        )
      )
    )

    11 replies

    csteward
    October 7, 2021

    What do you mean by "Migrate a CDT"?  Are you referring to having the fields in a CDT be different in /design than the fields in the DB, such as the difference here between element name and @Column name?

          
            
              @Column(name="LAST_NAME")
            
          

    October 7, 2021

    What I mean is, imagine you have bank account data about a number if clients and you want to migrate that data in order for other people to work on it, but you dont want them to work on the real data, just some transformed data of the real values

    csteward
    October 7, 2021

    Sure, if you want to migrate a static set of the data, create a new DB table and insert only the values you want over there, then create a new version of the CDT to point to the new table.  Similarly, you can create a view on the primary table which contains only columns/values or manipulated values from the underlying table.