> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/graphql-api/mutations/deletedatatype.md).

# Delete Data Type

Delete DataType Mutation

Deletes an existing data type definition from the system.

## Arguments

| Name | Type  | Description                       |
| ---- | ----- | --------------------------------- |
| `id` | `ID!` | The ID of the data type to delete |

## Return Type

`DataTypeDeletePayload!` - Confirmation of the delete operation.

## Return Fields

`DataTypeDeletePayload`:

| Field       | Type | Description                     |
| ----------- | ---- | ------------------------------- |
| `deletedID` | `ID` | The ID of the deleted data type |

## Usage Example

```graphql
mutation {
  deleteDataType(id: "dt_123456789") {
    deletedID
  }
}
```

```graphql
mutation {
  # Delete multiple data types (requires multiple calls)
  deleteDataType1: deleteDataType(id: "dt_old_customer_schema") {
    deletedID
  }
  deleteDataType2: deleteDataType(id: "dt_deprecated_item_format") {
    deletedID
  }
  deleteDataType3: deleteDataType(id: "dt_legacy_supplier_data") {
    deletedID
  }
}
```

## JavaScript Example

```javascript
const DELETE_DATA_TYPE = gql`
  mutation DeleteDataType($id: ID!) {
    deleteDataType(id: $id) {
      deletedID
    }
  }
`;

// Using the mutation
const [deleteDataType] = useMutation(DELETE_DATA_TYPE);

const handleDeleteDataType = async (dataTypeId) => {
  try {
    // Check for dependencies first
    const entitiesUsingDataType = await checkDataTypeUsage(dataTypeId);
    
    if (entitiesUsingDataType.length > 0) {
      console.warn('Data type is in use by:', entitiesUsingDataType);
      return; // Don't delete if in use
    }
    
    const { data } = await deleteDataType({
      variables: { id: dataTypeId }
    });
    
    console.log('Data type deleted:', data.deleteDataType.deletedID);
    // Update UI to remove the deleted data type
  } catch (error) {
    console.error('Error deleting data type:', error);
  }
};
```

## Important Considerations

### Soft vs Hard Delete

The pyck system implements soft deletes by default, meaning:

* The data type record is marked as deleted (`deletedAt` timestamp is set)
* The data type definition remains in the database for audit purposes
* The data type will not appear in normal queries
* Entities using this data type retain their data but lose schema validation

### Dependency Impact

Before deleting a data type, consider:

* **Active Entities**: Customers, suppliers, items, or other entities using this data type
* **Forms and UI**: Frontend applications relying on the schema structure
* **Validation Rules**: Business logic that depends on the data type schema
* **Reports and Analytics**: Systems that query data based on the schema
* **API Integrations**: External systems expecting specific data formats

### Data Type Usage

Data types are referenced by entities through:

* `dataTypeID` - Direct reference to the data type
* `dataTypeSlug` - String-based reference for easier identification
* Schema validation applied to the `data` field of entities

## Permissions

Data type deletion typically requires:

* Administrative or system architect privileges
* Proper authorization for the tenant/organization
* Understanding of system-wide impact of the deletion
* Compliance with data governance policies

## Error Scenarios

The mutation may fail in these cases:

* **Not Found**: Data type ID doesn't exist
* **Permission Denied**: Insufficient privileges to delete data types
* **Constraint Violations**: Entities are actively using this data type
* **System Data Types**: Attempting to delete built-in or system data types
* **Default Data Types**: Trying to delete data types marked as default

## Pre-Deletion Checklist

Before deleting a data type:

1. **Identify Usage**: Query all entities using this data type
2. **Migration Plan**: Plan how to handle existing entities
3. **Backup Schema**: Save the JSON schema definition
4. **Stakeholder Approval**: Get approval from business stakeholders
5. **System Testing**: Test system behavior after deletion
6. **Rollback Plan**: Prepare to restore if issues arise

## Migration Strategies

### Entity Reassignment

```graphql
# Move entities to a different data type before deletion
mutation {
  updateCustomer(id: "cust_123", input: {
    dataTypeSlug: "standard_customer"
    clearDataTypeID: true
  }) {
    id dataTypeSlug
  }
}
```

### Data Preservation

```graphql
# Clear the data type reference but keep the data
mutation {
  updateSupplier(id: "supp_456", input: {
    clearDataTypeID: true
    clearDataTypeSlug: true
    # data remains intact without schema validation
  }) {
    id data
  }
}
```

## Best Practices

1. **Impact Analysis**: Thoroughly analyze dependencies before deletion
2. **Gradual Migration**: Move entities to other data types first
3. **Communication**: Notify all stakeholders of the planned deletion
4. **Documentation**: Document reasons for deletion and migration steps
5. **Testing**: Test system behavior in non-production environments
6. **Monitoring**: Monitor system health after deletion

## Alternative Approaches

Instead of deletion, consider:

* **Deprecation**: Mark data type as deprecated but keep it available
* **Versioning**: Create new versions instead of deleting old ones
* **Archiving**: Move unused data types to an archived status
* **Replacement**: Create replacement data types before deleting old ones

## Recovery Options

If a data type is accidentally deleted:

* **Soft Delete Recovery**: Clear the `deletedAt` timestamp to restore
* **Schema Restoration**: Recreate the data type with the same JSON schema
* **Entity Reassignment**: Update entities to use the restored data type
* **Validation Repair**: Fix any validation issues that occurred during the outage

## Related Operations

After data type deletion, you may need to:

* Update documentation and API references
* Modify form generation systems
* Update validation logic in applications
* Revise data import/export processes
* Adjust reporting and analytics queries

## Monitoring and Alerts

Consider setting up monitoring for:

* Entities without valid data type references
* Validation errors due to missing schemas
* Performance impacts from schema changes
* Failed operations due to missing data types


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/graphql-api/mutations/deletedatatype.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
