Migrating Cockpit CMS v1 to v2

Cockpit CMS
is an open-source, headless content management system that allows developers and content creators to easily manage and publish content for their websites and applications.
This article will explain the process of migrating from Cockpit CMS version 1 to version 2.
— — -
Disclaimer: This article is based on my own experience of migrating from Cockpit v1 to v2. Therefore, I recommend backing up your
storage
folder before attempting any changes, and note that this guide is only for the Collection Data and Cockpit default DB (SQLite).For the purposes of this guide, I will be using a collection called
contact
.
- 1. Prepare SQLite data
- 2. Create Models in v2
- 3. Delete newly created collection table
- 4. Rename SQLite table
- 5. Append “_state” property to collection document
1. Prepare SQLite data
First, copy the collections.sqlite
file from the storage/data
folder of v1, rename it content.sqlite
, and replace the content.sqlite
file in the storage/data
folder of v2.

Make sure to backup the
content.sqlite
file to avoid losing any data.
— — -
2. Create Models in v2

Unfortunately, you cannot automatically export and import your v1 collections/fields into Cockpit v2. You must manually create the collections and their fields in v2. After creating the model, PHP schemas will be generated in the storage/content
folder.
Ensure that the collection name and fields are the same as in v1.
— — -
3. Delete newly created collection table
Using a SQLite database browser, open the content.sqlite
file. In my case, the model name is contact
, so there will be two tables with similar names: contact
(v1 table) and collections_contact
(v2 table, created in step 2).
Delete the collections_contact
table as we only want the PHP schemas under storage/content
and will use the contact
table from v1.

— — -
4. Rename SQLite table
As we will be using the contact
table and its data from v1, we can now rename it to collections_contact
according to the v2 table format. In my case, I renamed the table from contact
to collections_contact
. If you have a different model name, it will be something like collections_{model_name}
.

— —
5. Append “_state” property to collection document
After renaming the table, you would see the collections data is in the Cockpit v2 dashboard.

However, if we try to get the data through API, it will only return a blank array because all content is in Draft
status.
This happens because _state
is a new property in Cockpit v2 that determines the status of content, such as Draft or Published.

As we are migrating the content from v1, all content objects are missing the _state
property, causing Cockpit to assume that the _state
value is false and keep all the content in draft status. To fix this, we need to append a key and value object to every content object (document under collections_contact
table).
We can achieve this by running the following SQLite query, replacing collections_contact
with your table name:
UPDATE collections_contact
SET document = substr(document, 1, length(document)-1) || ',"_state":1}';

This query updates the document
column for all rows in the collections_contact
table by replacing the last character }
with ,"_state":1}
.
This is a way of appending a key and value to a JSON object.
After adding "_state":1
to the documents, we can now get the content through API, and all the content will be in Published
status.
I hope this guide helps you migrate your Cockpit CMS from v1 to v2 successfully.