Skip to content

Conversation

@haroun
Copy link
Contributor

@haroun haroun commented Oct 9, 2025

Summary

Adds @apostrophecms/migration:add-missing-schema-fields task

What are the specific steps to test this change?

  1. Go to the Checks tab, all tests must be green.
  2. Manually test @apostrophecms/migration:add-missing-schema-fields and @apostrophecms/migration:migrate tasks maybe.

What kind of change does this PR introduce?

(Check at least one)

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Build-related changes
  • Other

Make sure the PR fulfills these requirements:

  • It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • The changelog is updated
  • Related documentation has been updated
  • Related tests have been updated

If adding a new feature without an already open issue, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

@haroun haroun self-assigned this Oct 9, 2025
Base automatically changed from pro-8255-manager-locale-switcher to main October 21, 2025 08:10
…ation

* main: (23 commits)
  PRO-8538: fix layout bug in mobile breakpoint preview that causes tiny collapsed columns (#5127)
  give color button a testable data attr (#5124)
  PRO-8530 autodetect ES bundles (#5120)
  Emphasize but unfocus in layout mode (#5125)
  Simplify layout max width (#5123)
  max width, anchors, labels (#5122)
  refactor and inject admin UI styles for layout (#5116)
  Color field swatches (#5118)
  Pro 8285 login case insensitive (#5100)
  fix paste bug (#5119)
  Implement change outlined on Discord (#5117)
  PRO-8374: Mute tooltip when edit is disabled (#5114)
  fix sticky when controls are disabled (#5115)
  enable logout and whoami routes if localLogin is false (#5098)
  add locale picker (#5090)
  enforce empty state font (#5113)
  sticky controls (#5106)
  Layout widget icon (#5112)
  Feature layout widget (#5031)
  PRO-8435: log what widget type was missing (#5110)
  ...

### Fixes

## UNRELEASED
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recreating the section because this is not part of today's release, easier for me to handle future conflict.

@haroun haroun requested a review from boutell October 30, 2025 17:15
@haroun haroun marked this pull request as ready for review October 30, 2025 17:23
Copy link
Member

@boutell boutell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change request

// Perform the actual migrations. Implementation of
// the @apostrophecms/migration:migrate task
async migrate(options) {
await self.emit('before');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should skip this line too, even though it means your task will have to explicitly call addMissingSchemaFields.

This is appropriate because:

  • We used the before hook to implement addMissingSchemaFields, which is a special kind of migration
  • Other people and other modules will likely do the same thing
  • Michelin doesn't want anything else that smells like a migration at all to happen in this task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the following code

    await self.apos.lock.withLock('@apostrophecms/migration:migrate', async () => {
      await self.apos.migration.migrate(self.argv);
      // Inserts the global doc in the default locale if it does not exist;
      // same for other singleton piece types registered by other modules
      for (const apostropheModule of Object.values(self.modules)) {
        if (self.instanceOf(apostropheModule, '@apostrophecms/piece-type') && apostropheModule.options.singletonAuto) {
          await apostropheModule.insertIfMissing();
        }
      }
      await self.apos.page.implementParkAllInDefaultLocale();
      await self.apos.doc.replicate(); // emits beforeReplicate and afterReplicate events
      // Replicate will have created the parked pages across locales if needed,
      // but we may still need to reset parked properties
      await self.apos.page.implementParkAllInOtherLocales();
    });

Should I skip all apostropheModule.insertIfMissing + page.implementParkAllInDefaultLocale, doc.replicate & page.implementParkAllInOtherLocales too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense.

@haroun haroun requested a review from boutell November 6, 2025 10:44
await self.addMissingSchemaFields();
}
},
after: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you did this, but previously, these "requirements" were guaranteed to come last, even after the after event. And changing that is an unnecessary risk.

So, please make them individual handlers on a new requirements event which is fired after the after event has been safely awaited.

// This is the right time to park pages, for instance, because the
// database is guaranteed to be in a stable state, whether because the
// site is new or because migrations ran successfully.
await self.emit('after');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emit a new requirements event "after after" 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants