<commit_before>#!/usr/bin/env node
import '../../server/env';

import { sequelize } from '../../server/models';

// we have to use raw sql query today
// https://github.com/sequelize/sequelize/issues/3957

// Mark all Manual Payments as ERROR after 2 months
// Make sure to not include pledges
sequelize.query(
  `UPDATE "Orders"
  SET "status" = 'ERROR', "updatedAt" = NOW()
  FROM "Collectives"
  WHERE "Orders"."status" = 'PENDING'
  AND "Orders"."PaymentMethodId" IS NULL
  AND "Collectives"."id" = "Orders"."CollectiveId"
  AND "Collectives"."isPledged" = FALSE
  AND "Collectives"."HostCollectiveId" IS NOT NULL
  AND "Orders"."createdAt" <  (NOW() - interval '2 month')`,
);

// Mark all PENDING errors that are not Manual Payments or Pledge as ERROR after 1 day
sequelize.query(
  `UPDATE "Orders"
  SET "status" = 'ERROR', "updatedAt" = NOW()
  FROM "Collectives"
  WHERE "Orders"."status" = 'PENDING'
  AND "Orders"."PaymentMethodId" IS NOT NULL
  AND "Collectives"."id" = "Orders"."CollectiveId"
  AND "Collectives"."isPledged" = FALSE
  AND "Collectives"."HostCollectiveId" IS NOT NULL
  AND "Orders"."createdAt" <  (NOW() - interval '1 day')`,
);<commit_msg>fix: better use promise in clean-orders<commit_after>#!/usr/bin/env node
import '../../server/env';

import { sequelize } from '../../server/models';

// we have to use raw sql query today
// https://github.com/sequelize/sequelize/issues/3957

Promise.all([
  // Mark all Manual Payments as ERROR after 2 months
  // Make sure to not include pledges
  sequelize.query(
    `UPDATE "Orders"
  SET "status" = 'ERROR', "updatedAt" = NOW()
  FROM "Collectives"
  WHERE "Orders"."status" = 'PENDING'
  AND "Orders"."PaymentMethodId" IS NULL
  AND "Collectives"."id" = "Orders"."CollectiveId"
  AND "Collectives"."isPledged" = FALSE
  AND "Collectives"."HostCollectiveId" IS NOT NULL
  AND "Orders"."createdAt" <  (NOW() - interval '2 month')`,
  ),

  // Mark all PENDING errors that are not Manual Payments or Pledge as ERROR after 1 day
  sequelize.query(
    `UPDATE "Orders"
  SET "status" = 'ERROR', "updatedAt" = NOW()
  FROM "Collectives"
  WHERE "Orders"."status" = 'PENDING'
  AND "Orders"."PaymentMethodId" IS NOT NULL
  AND "Collectives"."id" = "Orders"."CollectiveId"
  AND "Collectives"."isPledged" = FALSE
  AND "Collectives"."HostCollectiveId" IS NOT NULL
  AND "Orders"."createdAt" <  (NOW() - interval '1 day')`,
  ),
]).then(() => {
  console.log('>>> Clean Orders: done');
  process.exit(0);
});
{'fraction_non_alphanumeric': 0.16411290322580646, 'fraction_numerical': 0.0068548387096774195, 'mean_word_length': 3.8742632612966603, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7189813', 'n_tokens_mistral': 876, 'n_tokens_neox': 829, 'n_words': 246}