Command Models
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Command Models in flext-target-oracle provide a structured, object-oriented approach to executing operational tasks within the Singer target ecosystem. These models encapsulate the logic for common lifecycle actions such as metadata retrieval, target initialization, and configuration validation. By inheriting from base command structures provided by the flext-meltano framework, they ensure consistency across the FLEXT integration suite.
The primary goal of these models is to decouple the invocation of target actions from the underlying implementation details. They leverage the r[str].Result pattern for error handling, allowing for predictable execution flows and robust error reporting during data loading operations.
Sources: src/flext_target_oracle/_models/commands.py:1-25, src/flext_target_oracle/models.py:10-25
Architecture and Command Types
The command architecture is centered around the FlextTargetOracleModelsCommands mixin, which defines specific inner classes for different operational requirements. Each command class implements an execute() method that returns a result object.
Command Hierarchy
The following class diagram illustrates the relationship between the command factory and the individual command implementations:
The diagram shows how the OracleTargetCommandFactory serves as the entry point for instantiating specific command objects.
Sources: src/flext_target_oracle/_models/commands.py:22-110
Key Command Classes
| Command Class | Purpose | Primary Inputs |
|---|---|---|
OracleTargetAboutCommand | Returns target metadata (name, description, capabilities) in JSON or Text format. | format (json/text) |
OracleTargetLoadCommand | Initializes the target by loading settings and preparing for incremental data loads. | config_file, state_file |
OracleTargetValidateCommand | Performs business rule validation on the provided configuration file. | config_file |
Sources: src/flext_target_oracle/_models/commands.py:26-95
Command Execution Logic
Commands follow a "Railway-Oriented" execution pattern where the result of an operation is either a success (ok) or a failure (fail) containing an error message.
Validation Flow
The OracleTargetValidateCommand demonstrates the multi-stage validation logic used to ensure target stability before data processing begins:
This flowchart represents the sequential validation of technical settings followed by domain-specific business rules.
Sources: src/flext_target_oracle/_models/commands.py:75-95
Information Retrieval (About Command)
The OracleTargetAboutCommand handles metadata reporting. It supports conditional output formatting based on FlextTargetOracleConstants.
- JSON Format: Dumps a payload containing the name (
flext-target-oracle) and description. - Text Format: Returns the plain string name of the package.
Sources: src/flext_target_oracle/_models/commands.py:30-55
Implementation via Factory
The OracleTargetCommandFactory provides static methods to instantiate commands with standardized IDs (e.g., cmd_oracle_about, cmd_oracle_load). This ensures that commands are created with the correct command_type constants defined in the target's registry.
# Example of Factory Usage
cmd = OracleTargetCommandFactory.create_validate_command(
config_file="config.json"
)
result = cmd.execute()
Sources: src/flext_target_oracle/_models/commands.py:97-128
Integration with Error Handling
Command execution is tightly integrated with the FlextTargetOracleExceptions hierarchy. If a command fails during the settings load or business rule validation, it utilizes the result pattern to propagate errors which can then be mapped to specific exception types like ConfigurationError or ValidationError.
Sources: src/flext_target_oracle/_utilities/errors.py:65-100, src/flext_target_oracle/_models/commands.py:82-93
Conclusion
Command Models serve as the functional interface for flext-target-oracle, encapsulating complex setup and validation logic into discrete, testable units. By utilizing the OracleTargetCommandFactory and adhering to the Result pattern, the system maintains a high degree of operational reliability and clear separation of concerns between CLI interactions and database loading logic.