A Rails application to support for batch CSV imports and automatic record updates.
- Ruby version: 3.4.7
- Rails version: 8.1.1
- Database: SQLite3
bundle installbin/rails db:create
bin/rails db:migratebin/rails serverThe application will be available at http://localhost:3000
bundle exec rspecTo import properties using a CSV file:
- Navigate to the properties page at
/properties - Upload your CSV file using the file uploader
- The file will be processed through the
POST /properties/batchendpoint - View the results, including any validation errors for invalid records
Example of the batch upload interface showing successful processing and validation errors
Your CSV file must include the following headers in Japanese:
| Japanese Header | English Meaning | Mapped Column |
|---|---|---|
| ユニークID | Unique ID | custom_unique_id |
| 物件名 | Property Name | name |
| 住所 | Address | address |
| 部屋番号 | Room Number | room_number |
| 賃料 | Rent Fee | rent_fee |
| 広さ | Size | size |
| 建物の種類 | Building Type | category |
ユニークID,物件名,住所,部屋番号,賃料,広さ,建物の種類
1,サンプル物件1,東京都渋谷区1-1-1,101,100000,30,マンション
2,サンプル物件2,東京都新宿区2-2-2,202,120000,40,アパート
3,サンプル物件3,東京都目黒区3-3-3,,150000,100,一戸建てProperties have the following attributes:
id(UUID): Primary keycustom_unique_id(integer): Unique identifier for upsert operationsname(string): Property name (required)address(string): Property address (required)category(string): Building type - マンション (Apartment), アパート (Apartment), or 一戸建て (Detached House) (required)room_number(integer): Room number (required for マンション and アパート, optional for 一戸建て)rent_fee(integer): Monthly rentsize(float): Property size in square meterscreated_at,updated_at: Timestamps
The service handles batch imports of properties from CSV files and provides:
- CSV file and header validation
- Individual row validation with detailed error reporting
- Efficient batch processing (1,000 records per batch)
- Upsert operations: creates new properties or updates existing ones based on
custom_unique_id - Comprehensive error collection for invalid records
Properties must meet the following validation requirements:
- Required fields: All properties must have
custom_unique_id,name,address, andcategory - Category values: Must be one of the following:
マンション(Mansion),アパート(Apartment), or一戸建て(Detached House) - Room number: Required for
マンションandアパートproperties, but optional for一戸建て - Unique identifier: Each
custom_unique_idmust be unique across all properties (used for upsert operations)
-
Add CSV file size validation
- Add file size validation (e.g., 10MB limit) to the CSV uploader on the property index page and batch creating controller
-
Back up CSV files
- Upload CSV files to cloud storage (or save to local storage) with a standardized naming convention
- Example naming format:
{original_file_name}_{YYYYmmdd}-{HHMMSS}.csv
-
Add processing logs
- Create a new table (e.g.,
property_batch_logs) to track batch processing history - Store: file name, processed timestamp, and processing results
- Create a new table (e.g.,