Adding a new data model with Tailor Platform
It is very easy to change data schema with Tailor Platform. In Tailor Platform, the main database is called Tailor DB. With Tailor DB, you will be able to modify the data model of our templates, or add new Types (new data model. Equivalent to Table in a Relational Database) very easily.
This tutorial demonstrates how to use Tailor DB to add a new data schema to an existing template.
- Complete Quickstart first If you haven't yet built the Inventory Management System app from our template.
- See Core concepts to get an overview of Workspace, Organization, Application and Service.
Tutorial steps
To create a Category
resource in Tailor DB, you'll need to:
- Define
Category
schema - Apply the change using
tailorctl
- Verify schema change through GraphQL
1. Define Category
schema
To add the Category
data schema, create a new file called category.tf
and define the schema.
In the file, design the details of the Category
object type, such as fields and permission.
resource "tailor_tailordb_type" "category" {
workspace_id = tailor_workspace.ims.id
namespace = tailor_tailordb.ims.namespace
name = "Category"
description = "Contains information about categories of products."
settings = {
publish_record_events = true
}
fields = {
name = {
type = "string"
description = "Name of the category."
}
description = {
type = "string"
description = "Description of the category."
}
createdAt = {
type = "datetime"
description = "Creation date of the category"
hooks = {
create = "(new Date()).toISOString()"
}
}
}
type_permission = local.permission_everyone
}
2. Apply the change using tailorctl
terraform apply
3. Verify schema change through GraphQL
Now, you can use the following generated GraphQL APIs to access Category
data.
- Query:
category
andcategories
- Mutation:
createCategory
,updateCategory
,deleteCategory
andchangeCategory
Try it out to see how easy it is to manage your data!
# Open the GraphQL playground in the browser
tailorctl workspace app open -n ims
Let's create a Category
resource with a specified name string.
query
# Create new Category data
mutation {
createCategory(input: { name: "Gloves" }) {
id
}
}
example response
{
"data": {
"createCategory": {
"id": "a80ccddb-2f42-4ac3-a298-a6a766a24316"
}
}
}
You can view the Category
resource values in the Console.
You can run the following query in the GraphQL playground. This will show you the values. Replace category's ID with ID obtained from the previous query.
query
# Get Category data
{
category(id: "a80ccddb-2f42-4ac3-a298-a6a766a24316") {
id
name
}
}
example response
{
"data": {
"category": {
"id": "a80ccddb-2f42-4ac3-a298-a6a766a24316",
"name": "Gloves"
}
}
}
Further information
- See Tailor DB page to learn more about schema design.
- Visit CUE basics page if you're new to cue format.