apache / incubator-devlake

Apache DevLake is an open-source dev data platform to ingest, analyze, and visualize the fragmented data from DevOps tools, extracting insights for engineering excellence, developer experience, and community growth.
https://devlake.apache.org/
Apache License 2.0
2.6k stars 526 forks source link

[Bug][Customize] customize plugin doesn't recognize array type #7999

Closed KyriosGN0 closed 2 months ago

KyriosGN0 commented 2 months ago

Search before asking

What happened

when trying to create a new custom field in the issues table, the docs mention that array is a supported type, but in the code it is not the oneof type.

What do you expect to happen

column of type array are created in issues table

How to reproduce

send a POST request https:///api/plugins/customize/issues/fields with a body like this { "columnName": "x_tags", "displayName": "Tags", "dataType": "array", "description": "Array of tags from jira" }

Anything else

No response

Version

v1.0.1-beta7@3f84bae

Are you willing to submit PR?

Code of Conduct

dosubot[bot] commented 2 months ago

Hey @KyriosGN0! I'm here to help you with any issues, answer questions, and guide you to become a contributor. Let me know how I can assist you!

The customize plugin does not recognize the array type when creating a new custom field in the issues table because, according to the latest documentation, only the following five types are supported for direct addition to the issues table:

While the array type is indeed supported, it is handled differently. For array types, a new table called issue_custom_array_fields is created, which contains issue_id, field_id, and value columns. This table has a one-to-many relationship with the issues table. Therefore, the array type cannot be directly added as a custom field in the issues table but is instead managed through this separate table.

For more details, you can refer to the Customize Plugin documentation [1][2][3][4][5].

To continue talking to Dosu, mention @dosu.

KyriosGN0 commented 2 months ago

@dosu how should i create this field in the issues table ?

dosubot[bot] commented 2 months ago

To create a custom field of type array in the issues table, you need to use the issue_custom_array_fields table instead of directly adding the array type to the issues table. Here are the steps:

  1. Define the Struct: Create a struct for the custom array field in your codebase. Here is an example in Go:

    package ticket
    
    import "github.com/apache/incubator-devlake/core/models/common"
    
    type IssueCustomArrayField struct {
        IssueId    string `gorm:"primaryKey;type:varchar(255)"`
        FieldId    string `gorm:"primaryKey;type:varchar(255)"`
        FieldValue string `gorm:"primaryKey;type:varchar(255)"`
    
        common.NoPKModel
    }
    
    func (IssueCustomArrayField) TableName() string {
        return "issue_custom_array_fields"
    }
  2. Create the Table: Ensure that the issue_custom_array_fields table is created in your database. This table will store the custom array fields.

  3. Link the Custom Field to an Issue: Use the issue_id to link the custom array field to an issue. Here is an example SQL query to join the issues table with the issue_custom_array_fields table:

    SELECT 
      issues.id, 
      issues.title, 
      issue_custom_array_fields.field_id, 
      issue_custom_array_fields.field_value
    FROM 
      issues
    JOIN 
      issue_custom_array_fields 
    ON 
      issues.id = issue_custom_array_fields.issue_id
    WHERE 
      issue_custom_array_fields.field_id = 'x_product_lines';
  4. Insert Data: Insert the custom array field values into the issue_custom_array_fields table. Here is an example SQL insert statement:

    INSERT INTO issue_custom_array_fields (issue_id, field_id, field_value)
    VALUES ('issue_123', 'x_tags', 'tag1'), ('issue_123', 'x_tags', 'tag2');

For more details, you can refer to the Apache DevLake documentation [1][2][3][4].

To continue talking to Dosu, mention @dosu.

KyriosGN0 commented 2 months ago

Thx!