Scaffold the app and define the schema
3 min
After you complete the prerequisites:
- Register the app by specifying a unique ID and name. You should also mark it as a personal app so that it does not count towards the vendor's app limit. Ensure you select Data Platform for the target product.
> ocp app register
Active environment: production
App id to reserve: ocp_quickstart
Display name of the app: OCP Quickstart
Target product for the app > Data Platform
Keep this app private and not share it with other developers in your organization: Yes
Registered app ocp_quickstart with name "OCP Quickstart" in us, au, and eu - Scaffold the app. The Basic Sample template contains example code to get you started, but for now, use the Empty Project template. This initializes the app directory.
> ocp app init
Active environment: production
Name of your app (e.g., My App): OCP Quickstart
ID of your app [ocp_quickstart]: ocp_quickstart
Version [1.0.0-dev.1]: 1.0.0-dev.1
App Summary (brief): Syncs offline store orders and customer data to ODP.
Support URL: https://www.acme.com/
Contact email address: [email protected]
Select the category for the app: Testing & Utilities
Select a template project: Empty Project
Creating directory C:\Users\me\ocp-apps\ocp_quickstart
Performing initial Yarn install
...- Open it in your preferred editor and run git init to prepare the environment.
Define the schema
Optimizely Data Platform (ODP) comes with pre-defined objects (database tables) you can work with, such as Customers and Products. However, the data model for this app does not quite fit ODP's pre-defined model, so you need to add custom objects and fields. To do this, define a schema in src/schema/. All .yml files within refer to objects in ODP.
- Define a new identifier, ocp_quickstart_clubcard_id, in the ODP Customers object (including its creation date). You must prepend the app's ID to custom field names. The src/schema/customers.yml file should look like the following:
name: customers
identifiers:
- name: ocp_quickstart_clubcard_id
display_name: OCP Quickstart Clubcard ID
merge_confidence: high
fields:
- name: ocp_quickstart_clubcard_creation_date
type: timestamp
display_name: OCP Quickstart Clubcard Creation Date
description: Creation date of this Customer's Clubcard- Also create an Offline Stores custom object, with ID marked as a primary key. Because it is a custom object, prepend the app ID to its name. The src/schema/ocp_quickstart_offline_stores.yml file should look like the following:
name: ocp_quickstart_offline_stores
display_name: OCP Quickstart Offline Stores
fields:
- name: ocp_quickstart_offline_store_id
type: string
display_name: OCP Quickstart Offline Store ID
description: ID of the Offline Store
primary: true
- name: ocp_quickstart_offline_store_name
type: string
display_name: OCP Quickstart Offline Store Name
description: The name of the Offline Store
- name: ocp_quickstart_offline_store_location
type: string
display_name: OCP Quickstart Offline Store Location
description: Where the Offline Store is located- Finally, add an association between the Orders and Offline Stores objects. The src/schema/orders.yml file should look like the following:
name: orders
fields:
- name: ocp_quickstart_offline_store_id
type: string
display_name: OCP Quickstart Order Offline Store ID
description: The Quickstart Offline Store this Order originated from
relations:
- name: ocp_quickstart_offline_store
display_name: OCP Quickstart Offline Store
child_object: ocp_quickstart_offline_stores
join_fields:
- parent: ocp_quickstart_offline_store_id
child: ocp_quickstart_offline_store_id- Confirm your schema is valid by running ocp app validate in the Connect Platform for ODP command-line interface (CLI).