Skip to main content

Friend Import & Mapping

Overview​

This domain has three tables covering two mechanisms. line_user_import and line_user_import_detail handle importing new friends from a file (job header plus per-row detail), while import_mapping_job handles updating existing friends from a CSV by matching rows on a chosen unique key.

Table line_user_import​

ColumnTypeNullableDefaultDescription
idINTEGERNOT NULLnextval (serial)Primary key of the import job
line_oa_idINTEGERNOT NULL–Target LINE OA channel for the import
titleTEXTNOT NULL–User-supplied name for the import job
file_nameTEXTNOT NULL–Original uploaded file name
file_pathTEXTNOT NULL–Storage path of the uploaded file
archive_pathTEXTNULL–Path the file is moved to once processing completes
created_byINTEGERNOT NULL0User id who started the import
total_recordsINTEGERNOT NULL0Total number of records in the file
total_processedINTEGERNOT NULL0Number of records processed so far
process_attemptINTEGERNOT NULL0Number of processing attempts (used to cap retries)
statusLineUserImportStatus (enum)NOT NULLnewJob status: new, processing, completed, failed
summary_statsJSONBNULL–Import summary, e.g. counts of inserted / duplicate / malformed rows
noteTEXTNULL–Free-text note about the import job
organization_idINTEGERNOT NULL–Organization owning the job
created_dateTIMESTAMPTZ(3)NOT NULLCURRENT_TIMESTAMPJob creation timestamp
updated_dateTIMESTAMPTZ(3)NULL–Last update timestamp
deleted_dateTIMESTAMPTZ(3)NULL–Soft-delete timestamp

Table line_user_import_detail​

ColumnTypeNullableDefaultDescription
idUUIDNOT NULLgen_random_uuid()Primary key of the detail row
import_idINTEGERNOT NULL–Import job this row belongs to (FK to line_user_import.id)
line_oa_idINTEGERNOT NULL–Target LINE OA channel
line_user_idTEXTNOT NULL–LINE user ID read from the file
line_user_profileJSONBNULL–Profile fetched from the LINE API for this user ID
statusLineUserImportDetailStatus (enum)NOT NULLnewRow outcome: new, insert (added), exist (already present), undefined (not found on LINE), error_format (malformed)
error_messageTEXTNULL–Error description for this row
organization_idINTEGERNOT NULL–Organization owning the data
created_dateTIMESTAMPTZ(3)NOT NULLCURRENT_TIMESTAMPCreation timestamp
updated_dateTIMESTAMPTZ(3)NULL–Last update timestamp
deleted_dateTIMESTAMPTZ(3)NULL–Soft-delete timestamp

Table import_mapping_job​

ColumnTypeNullableDefaultDescription
idINTEGERNOT NULLnextval (serial)Primary key of the mapping job
line_oa_idINTEGERNOT NULL–LINE OA channel whose friend data will be updated
organization_idINTEGERNOT NULL–Organization owning the job
file_nameTEXTNOT NULL–Original CSV file name
file_pathTEXTNOT NULL–Storage path of the uploaded file
statusVARCHAR(20)NOT NULL'pending'Job status: pending, processing, success, partial, failed
unique_keyJSONBNOT NULL–Key used to match CSV rows against line_user
mappingsJSONBNOT NULL–CSV-column-to-target-field mappings (JSON array)
validationJSONBNULL–Pre-import validation summary (total / will update / no match / errors)
statsJSONBNULL–Final counts after processing (total, updated, skipped, errors)
error_log_pathTEXTNULL–Path to the per-row error log file
created_byINTEGERNULL–User id who started the job
created_dateTIMESTAMPTZNOT NULLnow()Job creation timestamp
updated_dateTIMESTAMPTZNULL–Last update timestamp
deleted_dateTIMESTAMPTZNULL–Soft-delete timestamp

Notes​

  • Foreign key: line_user_import_detail.import_id -> line_user_import.id. import_mapping_job has no FK constraints — its references are logical only.
  • Indexes: line_user_import is indexed on line_oa_id; import_mapping_job has import_mapping_job_oa_idx on (line_oa_id, status).
  • import_mapping_job is absent from schema.prisma. It was created via manual SQL (manual-sql/9.import_mapping.sql) and is processed asynchronously by worker-go through a queue of the same name. That is why its timestamps are plain TIMESTAMPTZ and status is a VARCHAR(20) rather than an enum.
  • unique_key is a JSON object shaped like {"field":"mobile_no","csvColumn":"Phone Number"}, where field may be a line_user column or a custom attribute in the form custom.<key>.
  • mappings is a JSON array shaped like [{"csvColumn":"Member Tier","target":"custom.member_tier"}], where target points at a line_user column or a key inside custom_attribute.
  • The import-mapping module is registered in system_module with full grants for roles 1-2 and readAll,read only for role 3, as defined in manual-sql/9.import_mapping.sql.