Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
What is the right approach creating a Knex migration UP/DOWN which has a TRIM function

I created a Knex migration whose purpose is to update 2 tables records to TRIM white spaces. My concern and doubt are what should be the down part of the migration.

Also if the UP part is right in the way I did.

The TRIM function is not reversible as I understand so the down section, what should be inside that function?

What I did is as follows the up part works well but then we need a down part and so I don't know what could be the best approach here

exports.up = (knex) =>
  Promise.all(
    [knex.raw(`UPDATE sites SET site_id = TRIM(site_id)`)],
    [
      knex.raw(`
    UPDATE
        institutional_review_boards AS i0
        SET
          attached_sites = (
            SELECT
              ARRAY_AGG(TRIM(e))
            FROM (
              SELECT
                UNNEST(attached_sites) e
              FROM
                institutional_review_boards AS i1
              WHERE
                i1.attached_sites = i0.attached_sites) AS i)`),
    ]
  );

exports.down = (knex) => Promise.resolve(knex);
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!