Advanced

Models & Database

Tapix database models, their properties, relationships, and table schema.

Tapix uses three Eloquent models to track the state of an import throughout its lifecycle. All database tables are prefixed with the configured table_prefix (default: tapix_).

Import

Tapix\Core\Models\Import

The primary model representing an import session. Tracks the overall status, column mappings, and row counters.

Properties

ColumnTypeDescription
idULIDPrimary key
tenant_idnullableTenant scoping identifier
user_idstringThe user who initiated the import
importerstringFully qualified class name of the importer
file_namestringOriginal uploaded file name
statusImportStatusCurrent import status
headersJSON arrayDetected CSV column headers
column_mappingsJSON arrayUser-defined column-to-field mappings
total_rowsintegerTotal number of rows in the CSV
created_rowsintegerRows that created new records
updated_rowsintegerRows that updated existing records
skipped_rowsintegerRows that were skipped
failed_rowsintegerRows that failed during processing
completed_attimestampWhen the import finished

The status column uses the ImportStatus enum with the following values: Uploading, Mapping, Reviewing, Previewing, Importing, Completed, Failed.

Relationships

  • user() -- BelongsTo the user who initiated the import.
  • rows() -- HasMany ImportRow records.
  • failedRows() -- HasMany FailedImportRow records.

Key Methods

  • columnMappings(): Collection<ColumnData> -- Returns the column mappings as a hydrated collection of ColumnData objects.
  • getImporter(): Importer -- Instantiates and returns the importer class.
  • transitionToImporting(): bool -- Performs an atomic status transition to Importing using a cache lock to prevent race conditions.

Scopes

  • completed() -- Filters imports with status Completed.
  • failed() -- Filters imports with status Failed.

ImportRow

Tapix\Core\Models\ImportRow

Represents a single row from the CSV file. Stores the raw data, validation errors, user corrections, and processing state.

Properties

ColumnTypeDescription
idULIDPrimary key
import_idstringForeign key to the parent import
row_numberintegerPosition in the original CSV file
raw_dataJSONOriginal row data from the CSV
validationJSONValidation errors per column
correctionsJSONUser corrections per column
skippedJSONColumns marked as skipped
match_actionRowMatchActionWhether to create, update, or skip
matched_idnullableID of the existing record (for updates)
relationshipsJSONResolved relationship matches
processedbooleanWhether the row has been processed

Key Methods

  • getFinalValue(string $column) -- Returns the corrected value if one exists, the raw value otherwise, or null if the column is skipped or has errors.
  • getFinalData(): array -- Returns merged raw data with corrections applied.
  • hasErrors(): bool -- Whether the row has any validation errors.
  • hasCorrections(): bool -- Whether the row has any user corrections.
  • isCreate(), isUpdate(), isSkip() -- Check the row's match action.

Scopes

  • withErrors($column) -- Rows with validation errors on a specific column.
  • valid() -- Rows without validation errors.
  • toCreate() -- Rows with Create match action.
  • toUpdate() -- Rows with Update match action.
  • toSkip() -- Rows with Skip match action.
  • uniqueValuesFor($column) -- Distinct values for a given column.
  • searchValue($column, $search) -- Search rows by column value.
  • forFilter(ReviewFilter, $column) -- Apply a review filter for a specific column.

FailedImportRow

Tapix\Core\Models\FailedImportRow

Records rows that failed during the execution phase. Uses Laravel's MassPrunable trait for automatic cleanup.

Properties

ColumnTypeDescription
idULIDPrimary key
import_idstringForeign key to the parent import
dataJSONThe row data that failed processing
validation_errorstringThe error message

The MassPrunable trait defines a prunable query that removes rows older than the cleanup_after_days config value. Run php artisan model:prune to clean them up.

Database Tables

Three tables are created by Tapix migrations:

  1. tapix_imports -- Main import records.
  2. tapix_import_rows -- Individual row state during import.
  3. tapix_failed_import_rows -- Rows that failed processing.

Table Prefix

All table names are prefixed with the value of the table_prefix config option (default: tapix_). Each model reads the prefix dynamically via getTable(), so changing the config value is all that is needed to use a custom prefix.

Copyright © 2026