Converting from V1 to V2: Collections

Hello everyone,

I am a new team at a company that uses Cockpit CMS (V1) for our local/internal business application. My long-term project is to upgrade our current Cockpit version (and our custom add-on) to the latest version. I am breaking this project down into two main parts:

  1. Migrating our existing collections to ensure that there is no data loss.
  2. Rebuilding/tweaking our add-on to work with the new interface.
  • Our add-on consists of 10 custom pages that are navigable from the menu bar.

Currently, I am seeking guidance on the first step of migrating our collections. I have attempted to copy all of the collections from the /storage/collections directory to the new V2 installation, but the collections are not appearing. Any advice or guidance would be greatly appreciated. Thank you!

Note: If you have any suggestions/thoughts on how to best migrate an add-on/how to rebuild the custom pages, it I’m all ears!

I attempted to migrate from v1 to v2 a week ago,
and I posted an article about migrating Cockpit v1 to v2.

I hope it helps you.

1 Like

Thanks for sharing the post. Unfortunately, we use MongoDB as our database so it isn’t as relevant. I’ve made a little bit of progress myself.

Here are the high level steps I have for migrating your existing MongoDB collections over to a new V2 instance.

  1. Install your desired version (core for me)
  2. Add your existing config.php file to the config folder (this has your mongodb server details)
  3. Navigate to the /install url to ensure all dependencies are installed.
  4. Create a new model, which should match one of your old collections that you’re trying to migrate

Note: This is the part that I"m hoping to get a little more clarity on… when you create a new model and then your first item the new collection is added to your database. For example, if your model is title “CockpitTest” your collection will show up as “content_collections_CockpitTest”. In the associated CockPitTest.model.php file, there is no reference to that collection name. In V1 you could add a line like “_uid” => ‘CockpitTest’ which would correspond to the default collection name of “collections_CockPitTest”. If I add the “_id” line with my old collections name it doesn’t work.

  1. The workaround, after you create your first item and the associated collection is created in MongoDB. Rename (or delete?) the recently created collection to anything else. Then rename your old collection to match the automatically generated collection name you just changed.

For example, if your old collection is called “collections_CockpitTest” rename it to “content_collections_CockpitTest” and all of your items will show up in the V2 instance. They will be unpublished to start.

Edit: You don’t need to create an item after creating the model, you can then rename your old collection to the new naming convention.

Is there a way to point to the existing collections names or do we have to rename them to the new schema?

1 Like

Its pretty straightforward to rename all the collections. I just wrote a simple python script to rename them. The issue I’m running into now is that previous collection links aren’t showing up. For example, if I have a “Content Link” (previously “CollectionLink” in V1) to a specific document in another collection it doesn’t show the content. It only shows a button “Link Collection Item” which opens up a dialog to select the specific item, which is obviously not going to work for over tens of thousands of items.

I’ve copied over the same JSON options from V1 to V2, such as:

  link: 'Customers',
  display: 'Name',
  multiple: true,
  limit: false,
  filter: null,

I’m wondering if the expected MongoDB structure has changed? For example, if I query a specific document in my collection I get:

  _id: ObjectId("5db1e5206c11890231685138"),
  Name: 'Part XYZ',
  ShortName: 'XYZ',
  CustomerSpecific: true,
  Customer: [
      _id: '5d262b2ff22765286848c965',
      link: 'Customers',
      display: 'Cockpit CMS'

When I load this specific document in the V2 Cockpit Admin interface I’m expecting to have a link ready to click saying “Cockpit CMS” that takes me to the associated document.

Anyone aware of anything that has changed around the expected structure in MongoDB or JSON settings to get this to link correctly?

Showing view in admin interface

Showing settings of specific field item in the model
CleanShot 2023-04-12 at 14.04.07

Edit 1: It looks like if I use the admin interface to make a new connection it updates the mongodb structure to:

Customer: { _model: 'Customers', _id: '5cdb2debf257657a85226862' }

Which means I need to write some scripts that look for all links and change them to _model in my collections. The last thing here I need to figure out is how to display the name of the linked item. In a forum search it looks like using a syntax similar to ${Name} in the Display input will solve the problem, but I still haven’t cracked the code.

Edit 2: It was in the documentation (kind of)! For me, I’m trying to show the “Name” field so modifying my JSON options to the below works:

  link: 'Customers',
  display: '${data.Name}',
  multiple: true,
  limit: false,
  filter: null,

Removing the JSON options and only putting ${data.Name} in the Display field didn’t work.

1 Like

Hi :wave:

I saw that there is a multiple option set to true. In v2 you don’t need that as any field can set to have multiple values.

Just check the checkbox “Allow multiple values” in the general field settings. That way the display value should work again if you have a list|array of customers.

1 Like