Sync schemas between two environments

This guide shows you how to update one schema with the other, for example, when you have a development and production environment with the same schema that is out of sync.

Introduction

In the event that you have separate environments, for example, Development, Testing, Acceptance, and Production, you may need to sync the schemas in these environments. You can do this automatically by running a schema sync in Prepr.

Schema sync modal

There are a few schema sync processes you can choose from:

  • Direct schema sync - Use this process to directly compare and sync your schema between two environments in the same organization.
  • GitHub schema sync - Export to a GitHub repository or import from a GitHub repository to keep your schema in sync between environments.
  • GitLab schema sync - Export to a GitLab project or import from a GitLab project to keep your schema in sync between environments.
  • Bitbucket schema sync - Export to a Bitbucket repository or import from a Bitbucket repository to keep your schema in sync between environments.

Use cases

See the following use cases for when you may need to synchronize your schema:

  • Sync production to development An example DTAP strategy is to maintain the schema in the Production environment and when the same content structure is needed for realistic test cases this schema needs to be copied to the Development, Test, or Acceptance environment. Learn more on how to set up a DTAP configuration.

  • Sync development to production After testing your development on the latest schema version in the Development or Test environments, it's possible that you may need to make changes to the live schema. In this case, you could copy these changes to the Production environment.

  • Share a schema between environments Use the Shared schema feature to maintain one schema across multiple environments, for example, for multiple brands. Check out more details in the environments doc. A schared schema can also be imported from GitHub or GitLab or exported to GitHub or GitLab. This could be useful for agencies when you want to do testing with client's shared schema in your own organization instead of in the client organization.

Prerequisites

Make sure to enable the Schema permission for the user roles who will sync schemas.

schema permissions

Check out roles and permissions in Prepr for more details.

Direct schema sync

Use the direct schema sync process if you choose not to use the GitHub sync, GitLab sync or Bitbucket sync. The direct schema sync needs no external tools, whereas the GitHub and GitLab syncs give you more flexibility and the added benefit of version control.

Note the list of constraints below before triggering the direct schema sync process.

Constraints

  • This process only works between environments in the same organization.

  • Models in your target environment will be overwritten with the models from the current environment if their Singular names match. Fields will be added or deleted to match the updated structure.

Even if a model has the same Name, but different Singular name in the current and target environments, it's treated as a new model for the target environment. To ensure models are matched and updated successfully make sure the Singular name matches.

  • Components, enumerations and remote sources in your target environment will be overwritten with the components, enumerations and remote sources from the current environment if their Type name values match. Fields will be added or deleted to match the updated structure.

Even if a component, enumeration or remote source has the same Name, but different Type name in the current and target environments, it's treated as a new component, enumeration, or remote source for the target environment. To ensure they are matched and updated successfully make sure the Type name matches.

  • Models, components, enumerations or remote sources that are not in the current environment, but present in the target environment will be deleted if they are unused.
⚠️

Once the sync has finished successfully, the changes cannot be undone. Make sure to preview the changes carefully for any discrepancies before confirming the schema sync.

The process below shows you how to sync your schema from one environment (current environment) to another (target environment).

Choose the source schema

First, decide on the source schema and navigate to the environment in which it was created. This will be your current environment. For example, if you want to copy your Development schema to Production, navigate to the Development environment.

Run the schema sync process

Once you’ve opened the chosen environment with the source schema, do as follows:

  1. Go to the Schema tab and click the Sync schema link at the top right to open the Sync schema modal.

  2. Click the Direct sync link to open the Direct schema sync modal.

    Direct schema sync

  3. Review the conditions before checking the I understand, continue checkbox. Then, select the Target environment you want to sync your schema to. Here you can only choose an environment in the same organization.

  4. Click the Preview changes button to review the upcoming changes.

    Sync schema preview

  5. If needed, click the Check Json diff button to review a more detailed comparison.

  6. When you're happy with the upcoming changes, click the Sync schema button to start the sync process.

Check the result

After the sync is done, you'll get a Sync completed status message.

Click the See sync overview link to open an overview of the changes made.

Sync schema overview

You can then confirm the models, components, enumerations and remote sources that were added, updated or deleted by navigating to your target environment.

That's it! You‘ve successfully synchronized the schema from your current environment to the target environment.

GitHub schema sync

The process below shows you how to connect to your GitHub account and sync a schema using a GitHub repository.

Generate a personal access token

To use a GitHub repository to sync schemas, follow the steps below to create a personal access token in your GitHub account.

  1. Log in to your GitHub account and follow the GitHub docs (opens in a new tab) to create a repository and necessary branches to manage your Prepr schema.
  2. In your GitHub account, click your profile photo to expand the sidebar menu on the right, and click the Settings link.
  3. From the side menu on the left, go to Developer Settings at the bottom. Expand the Personal access tokens option and click the Fine-grained tokens link.
  4. Click the Generate new token button, enter a Token name (Max. 40 characters) to indicate the purpose of the token like Prepr Schema sync and select an Expiration for the token.
  5. Under the Repository access section, choose the Only select repositories option and choose the repository you created earlier.
  6. Under the Permissions section, expand the Repository permissions link, go to the Contents subsection and select an access level of Read and write.
  7. Click the Generate token button and make sure to copy the generated token and save it somewhere safe. The token value will only be visible once.

Once done, you are ready to connect to your GitHub repository from Prepr CMS.

Connect to GitHub and trigger initial sync

The next step is to connect the Prepr CMS environment or organization to your GitHub account with the steps below.

  1. Navigate to each environment or organization where schemas need to be synced.

  2. Go to the Schema tab in the environment or the Shared schema tab in the organization and click the Sync schema link.

  3. Click the GitHub sync option and sign in to your GitHub account, if you are not yet signed in. Once signed in, an input screen appears.

    GitHub personal access token

  4. Paste the token that you copied in the previous step and click the Continue button. Another input screen appears to select the sync method.

    Choose export or import

  5. Select your preferred sync method for this environment and click the Complete button.

    • Choose Export only if this environment has the most up-to-date schema.
    • Choose Import only if the schema in this environment needs to be updated with a more up-to-date schema.
    • Choose Export & Import for the situation where you have schema updates from multiple development or testing environments.
  6. Depending on your chosen sync method, the schema sync will start in one of the following ways:

    • For Export only, the export process starts automatically.

    • For Import only, the import process starts automatically.

    • For Export & Import, you'll see the Sync with GitHub modal.

      Enable GitHub

      Choose the Export to GitHub option to start the export or click the Import from GitHub option to start the import process.

Once GitHub is connected, the Sync schema link text at the top of the Schema page is replaced with Export to GitHub, Import from GitHub or Sync with GitHub.

Export to GitHub

If your environment or organization has the most up-to-date schema, you can export it to a GitHub repository to make it available to other environments.

  1. If your GitHub account has previously been connected, go to the Schema tab and click the Export to GitHub link or click the Sync with GitHub link and choose the Export to GitHub option. When the export starts, you'll see the Export in progress modal.
  2. Once completed, the repository will be updated as follows:
    • If the repository is empty, the push request simply creates JSON files for each of the models, components, enumerations and remote sources in the schema.
      • The model JSON file names will match each model's Singular name in lowercase.
      • The component JSON file names will match their Type Name values in lower case.
      • The enumeration JSON file names will match their Type Name values in lower case.
      • The remote source JSON file names will match their Type Name values in lower case.
    • If the repository already has JSON files, expect the following behavior:
      • If the JSON files match models, components, enumerations, and remote sources in the schema, these JSON files will be overwritten.
      • If there are JSON files in the repository that don't have matching models, components, enumerations, or remote sources, these JSON files will be removed from the repository.
      • For models, components, enumerations, and remote sources that don't have matching JSON files, new JSON files will be created in the repository.

When successful, you'll see an Export complete status message. Now your GitHub repository is up to date with the latest schema. And you can use this repository to sync any other schema in your organization by triggering an import from GitHub.

Import from GitHub

If your environment or organization needs to be updated with a more up-to-date schema, you can do an import from a GitHub repository to update it.

  1. If your GitHub account has previously been connected, click the Import from GitHub link or click the Sync with GitHub link and choose the Import from GitHub option. When the import is triggered, you'll see the Validating GitHub Schema modal.

  2. When the schema validation completes, you can preview your changes.

    preview github import

  3. If needed, click the Check Json diff button to review a more detailed comparison.

  4. When you're happy with the changes, click the Import schema button.

  5. Once the import is completed, the schema is updated as follows:

    • Models, components, enumerations, and remote sources will be overwritten with the matching JSON files in the GitHub repository. The pull request will find matching models, components, enumerations, and remote sources using the model Singular name and the component and remote source Type name values in lower case.
    • If there are JSON files that don't have a match in your environment or organization schema, new models, components, enumerations, and remote sources will be created for each of these.
    • If there are models, components, enumerations and remote sources that don't have a matching JSON file, these will be automatically deleted if they are not in use by any content items.

That's it! You‘ve synchronized the schema using a GitHub repository.

You can disconnect a GitHub account from a Prepr environment. For example, if you need to switch to a different GitHub account. In this case, simply click go to the Settings → Integrations page and click the Deactivate link for the GitHub integration.

GitLab schema sync

The process below shows you how to connect to your GitLab account and sync a schema using a GitLab repository.

Generate a project access token

To use a GitLab project to sync schemas, follow the steps below to create a project access token in your GitLab account.

  1. Log in to your GitLab account and follow the GitLab docs (opens in a new tab) to create a project to manage your Prepr Schema.
  2. While in your project, expand the Settings in the side menu.
  3. Click the Access Tokens link and in the Project Access Tokens page, click the Add new token button.
  4. Enter a Token name to indicate the purpose of the token like Prepr Schema sync and select an Expiration for the token. Choose a role for the users who will be syncing schemas, for example: Maintainer.
  5. In the Select scopes section, check the api, read_repository and the write_repository options.
  6. Click the Create project access token button and make sure to copy the generated token and save it somewhere safe. The token value will only be visible once.
  7. To define the push and merge permissions for this project, expand the Settings in the side menu and click the Repository link. Expand the Protected branches section to define and set the role for the Allow to merge and the Allow to push and merge to the same role that you chose for the access token.
  8. Get and save the following values to connect to your GitLab project from Prepr:
    • In your project, expand the Settings in the side menu and click the General link. Copy and save the Project ID value.

Once done, you are ready to connect to your GitLab account from Prepr CMS.

Connect to GitLab and trigger initial sync

The next step is to connect the Prepr CMS environment or organization to your GitLab account with the steps below.

  1. Navigate to each environment or organization where schemas need to be synced.

  2. Go to the Schema tab in the environment or the Shared schema tab in the organization and click the Sync schema link.

  3. Click the GitLab sync option and sign in to your GitLab account, if you are not yet signed in. An input screen appears.

    GitLab form in Prepr

  4. Paste the GitLab Repository URL value (https://gitlab.com/), the GitLab Project ID, and the GitLab access token that you saved in the previous step and click the Continue button. Another input screen appears to select the sync method.

    Choose export or import

  5. Select your preferred sync method for this environment and click the Complete button.

    • Choose Export only if this environment has the most up-to-date schema.
    • Choose Import only if the schema in this environment needs to be updated with a more up-to-date schema.
    • Choose Export & Import for the situation where you have schema updates from multiple development or testing environments.
  6. Depending on your chosen sync method, the schema sync will start in one of the following ways:

    • For Export only, the export process starts automatically.

    • For Import only, the import process starts automatically.

    • For Export & Import, you'll see the Sync with GitLab modal.

      Enable GitLab

      Choose the Export to GitLab option to start the export or click the Import from GitLab option to start the import process.

Once GitLab is connected, the Sync schema link text is replaced with Export to GitLab, Import from GitLab, or Sync with GitLab.

Export to GitLab

  1. If your GitLab project has previously been connected, click the Sync with GitLab link and choose the Export to GitLab option. When the export is triggered, you'll see the Export in progress modal.
  2. Once completed, the repository will be updated as follows:
    • If the repository is empty, the push request simply creates JSON files for each of the models, components, enumerations and remote sources in the schema.
      • The model JSON file names will match each model's Singular name in lowercase.
      • The component JSON file names will match their Type Name values in lower case.
      • The enumeration JSON file names will match their Type Name values in lower case.
      • The remote source JSON file names will match their Type Name values in lower case.
      • If the repository already has JSON files, expect the following behavior:
        • If the JSON files match models, components, enumerations, and remote sources in the schema, these JSON files will be overwritten.
        • If there are JSON files in the repository that don't have matching models, components, enumerations, or remote sources, these JSON files will be removed from the repository.
        • For models, components, enumerations, and remote sources that don't have matching JSON files, new JSON files will be created in the repository.

When successful, you'll see an Export complete status message. Now your GitLab repository is up to date with the latest schema. And you can use this repository to sync any other schema in your organization by triggering an import from GitLab.

Import from GitLab

  1. If your GitLab has previously been connected, click the Sync with GitLab link and choose the Import from GitLab option. When the import is triggered, you'll see the Validating GitLab Schema modal.

  2. When the schema validation completes, you can preview your changes.

    preview gitlab import

  3. If needed, click the Check Json diff button to review a more detailed comparison.

  4. When you're happy with the changes, click the Import schema button. Once the import is completed, the schema is updated as follows:

    • Models, components, enumerations, and remote sources will be overwritten with the matching JSON files in the GitLab repository. The pull request will find matching models, components, enumerations, and remote sources using the model Singular name and the component and remote source Type name values in lower case.
    • If there are JSON files that don't have a match in your environment or organization schema, new models, components, enumerations, and remote sources will be created for each of these.
    • If there are models, components, enumerations and remote sources that don't have a matching JSON file, these will be automatically deleted if they are not in use by any content items.

That's it! You‘ve synchronized the schema using a GitLab repository.

You can disconnect a GitLab account from a Prepr environment. For example, if you need to switch to a different GitLab account. In this case, simply click go to the Settings → Integrations page and click the Deactivate link for the GitLab integration.

Bitbucket schema sync

The process below shows you how to connect to your Bitbucket account and sync a schema using a Bitbucket cloud repository.

Generate a repository access token

To use a Bitbucket repository to sync schemas, follow the steps below to create a repository access token in your Bitbucket account.

  1. Log in to your Bitbucket account and follow the Bitbucket docs (opens in a new tab) to create a repository to manage your Prepr Schema.
  2. While in your repository, click the Repository settings in the left side menu.
  3. Click the Access Tokens link and in the Access Tokens page, click the Create Repository Access Token button.
  4. Enter a Name to indicate the purpose of the token like Prepr Schema sync.
  5. In the Repositories section check the Read and Write options.
  6. Click the Create button and make sure to copy the generated token and save it somewhere safe. The token value will only be visible once.

Once done, you are ready to connect to your Bibucket account from Prepr CMS.

Connect to Bitbucket and trigger initial sync

The next step is to connect the Prepr CMS environment or organization to your Bitbucket account with the steps below.

  1. Navigate to each environment or organization where schemas need to be synced.

  2. Go to the Schema tab in the environment or the Shared schema tab in the organization and click the Sync schema link.

  3. Click the Bitbucket sync option and sign in to your Bitbucket account, if you are not yet signed in. An input screen appears.

    Bitbucket form in Prepr

  4. Paste the Bitbucket workspace name, Bitbucket Repository name, and the Bitbucket access token that you saved in the previous step and click the Continue button. Another input screen appears to select the sync method.

    Choose export or import

  5. Select your preferred sync method for this environment and click the Complete button.

    • Choose Export only if this environment has the most up-to-date schema.
    • Choose Import only if the schema in this environment needs to be updated with a more up-to-date schema.
    • Choose Export & Import for the situation where you have schema updates from multiple development or testing environments.
  6. Depending on your chosen sync method, the schema sync will start in one of the following ways:

    • For Export only, the export process starts automatically.

    • For Import only, the import process starts automatically.

    • For Export & Import, you'll see the Sync with Bitbucket modal.

      Enable Bitbucket

      Choose the Export to Bitbucket option to start the export or click the Import from Bitbucket option to start the import process.

Once Bitbucket is connected, the Sync schema link text is replaced with Export to Bitbucket, Import from Bitbucket, or Sync with Bitbucket.

Export to Bitbucket

  1. If your Bitbucket repository has previously been connected, click the Sync with Bitbucket link and choose the Export to Bitbucket option. When the export is triggered, you'll see the Export in progress modal.
  2. Once completed, the repository will be updated as follows:
    • If the repository is empty, the push request simply creates JSON files for each of the models, components, enumerations and remote sources in the schema.
      • The model JSON file names will match each model's Singular name in lowercase.
      • The component JSON file names will match their Type Name values in lower case.
      • The enumeration JSON file names will match their Type Name values in lower case.
      • The remote source JSON file names will match their Type Name values in lower case.
      • If the repository already has JSON files, expect the following behavior:
        • If the JSON files match models, components, enumerations, and remote sources in the schema, these JSON files will be overwritten.
        • If there are JSON files in the repository that don't have matching models, components, enumerations, or remote sources, these JSON files will be removed from the repository.
        • For models, components, enumerations, and remote sources that don't have matching JSON files, new JSON files will be created in the repository.

When successful, you'll see an Export complete status message. Now your Bitbucket repository is up to date with the latest schema. And you can use this repository to sync any other schema in your organization by triggering an import from Bitbucket.

Import from Bitbucket

  1. If your Bitbucket repository has previously been connected, click the Sync with Bitbucket link and choose the Import from Bitbucket option. When the import is triggered, you'll see the Validating Bitbucket Schema modal.

  2. When the schema validation completes, you can preview your changes.

    preview gitlab import

  3. If needed, click the Check Json diff button to review a more detailed comparison.

  4. When you're happy with the changes, click the Import schema button. Once the import is completed, the schema is updated as follows:

    • Models, components, enumerations, and remote sources will be overwritten with the matching JSON files in the Bitbucket repository. The pull request will find matching models, components, enumerations, and remote sources using the model Singular name and the component and remote source Type name values in lower case.
    • If there are JSON files that don't have a match in your environment or organization schema, new models, components, enumerations, and remote sources will be created for each of these.
    • If there are models, components, enumerations and remote sources that don't have a matching JSON file, these will be automatically deleted if they are not in use by any content items.

That's it! You‘ve synchronized the schema using a Bitbucket repository.

You can disconnect a Bitbucket account from a Prepr environment. For example, if you need to switch to a different Bitbucket account. In this case, simply click go to the Settings → Integrations page and click the Deactivate link for the Bitbucket integration.

If you have any questions about schema synchronization, please reach out to our Support team (opens in a new tab).

Was this article helpful?

We’d love to learn from your feedback