Add a Data Collections Extension with the Wix CLI

The data collections extension lets your project automatically create data collections in your site's CMS. When you release a new version of your project, the collections are created with the configuration you define.

Follow the instructions below to:

  1. Generate the extension and 1 or more collections in your project.
  2. Configure each collection's schema, permissions, and initial data.
  3. Release a new version so the collections are created on your site.

Once complete, your project automatically creates the specified collections in the CMS whenever you release a new version.

Note: Your site must have the CMS added. Without the CMS, collections added by the extension won't appear.

Step 1 | Create the extension

In the terminal:

  1. Navigate to your project repo.
  2. Run the generate command.
  3. The CLI displays a menu of extensions to generate. Under Backend, select Data Collection and press Enter.
  4. Enter a collection name when prompted. The name must be 1–36 characters and can only contain letters, numbers, underscores, and hyphens. The name must also be unique in the data collections extension folder.

The first time you run this command, the CLI creates the shared extension file (data-collections.extension.ts) alongside the new collection's definition file. Subsequent runs add new collection definition files to the same shared extension and register them automatically.

Step 2 | Configure the collection

Each collection is defined in its own <your-collection-name>.ts file. The default export is an object that describes the collection's schema, permissions, indexes, and initial data. The object follows the schema documented in the data collections extension JSON reference.

You can add multiple collections with the generate command. The CLI generates each collection with default fields and permissions. Edit each collection's <your-collection-name>.ts file to fit your data model.

Learn more about data collections extension files and code.

Step 3 | Build and deploy your project

Release a new version, then build and deploy your project. Learn more about version updates.

Note: Collection changes only take effect when you release a new major version. Older versions retain their existing collections. Changes can take up to 5 minutes to propagate after an update.

Delete a collection or the entire extension

To delete a single collection from your extension:

  1. Delete the collection's <your-collection-name>.ts file.
  2. In data-collections.extension.ts, delete the matching import statement and the entry for that collection from the collections array.

To delete the entire data collections extension:

  1. Delete the src/extensions/backend/data-collections/ folder.
  2. Delete the import and .use() statements for the extension from your extensions.ts file.

Important: If you've already released a version of your project, you must build and deploy the project again after removing the data collection extension files.

See also

Did this help?