Home

>

Tools

>

Payload CMS

>

Releases

>

3.0.0-beta.39

Payload CMS Release: 3.0.0-beta.39

Pre Release

Tag Name: v3.0.0-beta.39

Release Date: 5/30/2024

Payload CMS LogoPayload CMS

Payload CMS is a modern, self-hosted headless content management system built with TypeScript, Node.js, and MongoDB. It's designed specifically for developers who want full control over their content management system while maintaining a powerful admin interface for content editors.

TL;DR

Payload CMS v3.0.0-beta.39: Major Database Improvements for Postgres Users

This release introduces a significant architectural change for the Postgres database adapter, moving simple relationships from join tables to direct columns for improved performance and better alignment with relational database patterns. While this is a breaking change for Postgres users, a migration path is provided. The release also includes fixes for SSR live preview functionality.

Highlight of the Release

    • Simplified relationship storage in Postgres by moving simple relationships from join tables to direct columns
    • Improved database performance for Postgres users with more efficient relationship queries
    • Fixed SSR live preview document save event dispatching
    • Provided comprehensive migration path for Postgres users to preserve existing data

Migration Guide

for Postgres Users

If you're using the Postgres database adapter, you'll need to follow these steps to migrate your data:

Who needs to migrate:

  • Users with versions enabled on any collection/global
  • Users of the upload field
  • Users with relationship fields that are hasMany: false (default) and relationTo to a single collection

Migration Steps:

  1. Backup your database before performing any migration
  2. Create a pre-update migration snapshot:
    payload migrate:create
    
  3. If migrating a dev DB, delete the dev push row:
    DELETE FROM payload_migrations WHERE batch = -1
    
  4. Update Payload and Postgres packages to the latest versions
  5. Create the predefined migration:
    payload migrate:create --file @payloadcms/db-postgres/relationships-v2-v3
    
  6. Run the migration:
    payload migrate
    

Important: During these steps, don't start the dev server unless you have push: false set on your Postgres adapter.

Note that if two servers connect to the same database, only one should run migrations to avoid transaction conflicts.

Upgrade Recommendations

For Postgres Users:

This is a breaking change that requires careful migration. We recommend:

  1. Test the migration process in a development environment first
  2. Follow the migration guide precisely to ensure data integrity
  3. Backup your database before attempting the migration
  4. Plan for a maintenance window if upgrading in production

For Non-Postgres Users:

This update is safe to install as the breaking changes only affect Postgres database users.

The upgrade is recommended for all users to benefit from the SSR live preview fixes and to stay current with the latest beta release.

Bug Fixes

  • SSR Live Preview: Fixed an issue where server-side rendered live preview was not properly dispatching document save events, ensuring more reliable preview functionality.

New Features

Postgres Database Improvements

The most significant feature in this release is a major architectural improvement to how relationships are stored in the Postgres database adapter:

  • Simple relationships (has-one relationships with hasMany: false and relationTo: string) are now stored directly as columns rather than in join tables
  • Upload fields are now stored as direct columns rather than in relationship tables
  • This change aligns better with traditional relational database patterns and improves query performance
  • Foreign key constraints are now properly applied to these relationships

This change simplifies database structure and makes it easier to work directly with the database outside of Payload.

Security Updates

No security fixes were included in this release.

Performance Improvements

The relationship column changes for Postgres users bring significant performance benefits:

  • Simplified database queries for fetching related data
  • Reduced join complexity by storing simple relationships directly as columns
  • More efficient database structure with proper foreign key constraints
  • Improved query performance for relationship lookups
  • Reduced database size by eliminating unnecessary join tables for simple relationships

Impact Summary

This release introduces a significant architectural improvement for Postgres database users by changing how relationships are stored. Simple relationships and upload fields now use direct columns instead of join tables, which aligns better with traditional relational database patterns and improves performance.

While this is a breaking change for Postgres users, a comprehensive migration path is provided to preserve existing data. The migration process requires careful attention but results in a more efficient database structure.

The release also fixes an issue with SSR live preview not dispatching document save events, improving the reliability of the preview functionality.

Overall, this release represents an important step toward optimizing database performance and structure for Postgres users while maintaining backward compatibility through migration tools.

Full Release Notes

v3.0.0-beta.39 (2024-05-30)

Features

Bug Fixes

  • next: ssr live preview was not dispatching document save events (#6572) (e603c83)

BREAKING CHANGES 💥

Moves upload field and relationship fields with hasMany: false & relationTo: string from the many-to-many _rels join table to simple columns. This only affects Postgres database users.

TL;DR

We have dramatically simplified the storage of simple relationships in relational databases to boost performance and align with more expected relational paradigms. If you are using the beta Postgres adapter, and you need to keep simple relationship data, you'll need to run a migration script that we provide you.

Background

For example, prior to this update, a collection of "posts" with a simple hasMany: false and relationTo: 'categories' field would have a posts_rels table where the category relations would be stored.

This was somewhat unnecessary as simple relations like this can be expressed with a category_id column which is configured as a foreign key. This also introduced added complexity for dealing directly with the database if all you have are simple relations.

Who needs to migrate

You need to migrate if you are using the beta Postgres database adapter and any of the following applies to you.

  • If you have versions enabled on any collection / global
  • If you use the upload field
  • If you have relationship fields that are hasMany: false (default) and relationTo to a single category (has one) relations

We have a migration for you

Even though the Postgres adapter is in beta, we've prepared a predefined migration that will work out of the box for you to migrate from an earlier version of the adapter to the most recent version easily.

It makes the schema changes in step with actually moving the data from the old locations to the new before adding any null constraints and dropping the old columns and tables.

How to migrate

The steps to preserve your data while making this update are as follows. These steps are the same whether you are moving from Payload v2 to v3 or a previous version of v3 beta to the most recent v3 beta.

Important: during these steps, don't start the dev server unless you have push: false set on your Postgres adapter.

⚠️ Step 1 - backup

Always back up your database before performing big changes, especially in production cases.

⚠️ Step 2 - create a pre-update migration

Before updating to new Payload and Postgres adapter versions, run payload migrate:create without any other config changes to have a prior snapshot of the schema from the previous adapter version

⚠️ Step 3 - if you're migrating a dev DB, delete the dev push row from your payload_migrations table

If you're migrating a dev database where you have the default setting to push database changes directly to your DB, and you need to preserve data in your development database, then you need to delete a dev migration record from your database.

Connect directly to your database in any tool you'd like and delete the dev push record from the payload_migrations table using the following SQL statement:

DELETE FROM payload_migrations where batch = -1

⚠️ Step 4 - update Payload and Postgres versions to most recent

Update packages, making sure you have matching versions across all @payloadcms/* and payload packages (including @payloadcms/db-postgres)

⚠️ Step 5 - create the predefined migration

Run the following command to create the predefined migration we've provided:

payload migrate:create --file @payloadcms/db-postgres/relationships-v2-v3

⚠️ Step 6 - migrate!

Run migrations with the following command:

payload migrate

Assuming the migration worked, you can proceed to commit this change and distribute it to be run on all other environments.

Note that if two servers connect to the same database, only one should be running migrations to avoid transaction conflicts.

Related discussion:
#4163

Contributors

Statistics:

File Changed300
Line Additions21,039
Line Deletions11,818
Line Changes32,857
Total Commits250

User Affected:

  • Need to run a migration script to preserve relationship data
  • Will benefit from improved database performance with simplified relationship storage
  • Must follow specific migration steps to ensure data integrity

Contributors:

paulpopusdenolfeJarrodMFleschAlessioGrjacobsfletchjessrynkarMrFriggokendelljosephdavelsior1tsuuPatrikKozakLivogjmikrutfturmelDanRibbensandershermansenzvizvilinobino1