Files

Import Scripts

Units Import from XLSX

This script imports unit data from an Excel (XLSX) file into the database.

Usage

bun run import:units <path-to-xlsx-file>

Or directly:

bun run scripts/import-units.ts <path-to-xlsx-file>

Example

bun run import:units ./data/units.xlsx

Required XLSX Format

The Excel file must have the following columns (headers in first row):

Column Name Type Description
Project Name String Name of the project (required)
Floor Number Floor number (required)
Unit No. String Unit number/identifier (required)
Unit Series String Unit series identifier
No of Parking Space Number Number of parking spaces
Suits Area (sqft) Number Suite area in square feet
Balcony Area (sqft) Number Balcony area in square feet
Total Square Ft. Number Total area in square feet
Unit Type Variant String Unit type variant (e.g., "1BR", "2BR+Study")
Unit View String View description (e.g., "Marina View", "Sea View")

Features

  • Duplicate Detection: Checks if a unit already exists (by Project Name + Unit No.)
  • Update Existing: Updates existing units instead of creating duplicates
  • Auto-generation: Automatically generates:
    • Project slug (URL-friendly version of project name)
    • Unit type variant slug
    • Unit type (e.g., "1 Bedroom" from "1BR")
    • Number of bathrooms (inferred from bedroom count)
    • Unit number (extracted from Unit No.)
    • Wing (East/West, if mentioned in Unit View)
    • Side (left/right, based on unit number)

Default Values

The following fields are set to default values and may need to be updated separately:

  • salesPrice: 0 (not in XLSX format)
  • state: "available"
  • isLoft: false

Import Summary

After completion, the script displays:

  • Total rows processed
  • Number of new units imported
  • Number of existing units updated
  • Number of rows skipped (due to missing data)
  • Number of errors encountered

Notes

  1. Make sure your database connection is properly configured in .env
  2. The script uses the unique constraint on (project, unitNo) to prevent duplicates
  3. You may need to adjust the helper functions (getWing, getSide, etc.) based on your specific project requirements
  4. Review the imported data and update salesPrice and other fields as needed