Skip to main content

Column-mapped Data Import (Import Mapping)

Overview

Import Mapping imports CSV data in order to update line_user records that already exist in the system. This distinguishes it from Customer Database, which stores data in a separate table, and from the import-all-friends flow, which creates new friend records.

Customers upload a CSV in any layout and decide for themselves:

  • Which column acts as the unique key for matching against a LINE user — a phone number or membership ID, for example
  • Which columns map onto which standard fields or custom attributes

A validation step reports how many rows will match and how many will not before the user commits. The actual updates are handed off to worker-go and processed asynchronously through RabbitMQ.

Business Flow

  1. UploadPOST /api/import-mapping/upload accepts a multipart file, stores it in object storage, and returns the column headers it was able to read.
  2. Fetch mappable targetsGET /api/import-mapping/fields returns the fields and attributes data can be mapped onto: custom attributes from attribute_master combined with the standard line_user fields.
  3. Validate — after mapping the columns, the user calls POST /api/import-mapping/validate. The system checks each row against the current OA's line_user records and reports which rows matched a LINE user, which did not, and which contain values of the wrong type.
  4. ConfirmPOST /api/import-mapping creates a row in import_mapping_job with status pending and publishes the job id to the RabbitMQ queue import_mapping_job.
  5. Worker processing — worker-go picks up the job, applies the updates to line_user, and writes the job status back.
  6. Track progressGET /api/import-mapping returns a paginated list of all jobs with their current status, used to follow each import through to completion.

Every query is scoped by the CLS values lineOaId and organizationId, consistent with the rest of the system.

Key Files & Functions

The code lives in internal/modules/importmapping/, split across controller.go, service.go and dto.go.

MethodRouteHandlerPolicy
POST/api/import-mapping/uploadct.uploadcreate import-mapping
GET/api/import-mapping/fieldsct.fieldsread import-mapping
POST/api/import-mapping/validatect.validatecreate import-mapping
POST/api/import-mappingct.createJobcreate import-mapping
GET/api/import-mappingct.listreadAll import-mapping

Every route is wrapped in modulegate.ModuleGate(d, "import-mapping").

Connections to Other Services

  • Permissions — requires ModuleGate("import-mapping") and carries PolicyModuleImportMapping as metadata.
  • Tablesimport_mapping_job, line_user, attribute_master and line_oa.
  • RabbitMQ — jobs are dispatched on the import_mapping_job queue, configured through the RABBITMQ_QUEUE_IMPORT_MAPPING_JOB environment variable, with the consumer living in line-management-worker-go.
  • Storage — the original CSV files are kept in object storage.
  • Related modules — LINE User Management as the destination for the data, Attribute Master which defines the target fields, Customer Database, and All Friend Listing where import history is reviewed.