feat(Deployment): Integrate Ansible deployment via PHP deployment pipeline
- Create AnsibleDeployStage using framework's Process module for secure command execution - Integrate AnsibleDeployStage into DeploymentPipelineCommands for production deployments - Add force_deploy flag support in Ansible playbook to override stale locks - Use PHP deployment module as orchestrator (php console.php deploy:production) - Fix ErrorAggregationInitializer to use Environment class instead of $_ENV superglobal Architecture: - BuildStage → AnsibleDeployStage → HealthCheckStage for production - Process module provides timeout, error handling, and output capture - Ansible playbook supports rollback via rollback-git-based.yml - Zero-downtime deployments with health checks
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\MachineLearning\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
use App\Framework\Database\Migration\MigrationVersion;
|
||||
use App\Framework\Database\Schema\Blueprint;
|
||||
use App\Framework\Database\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Create ML Confidence Baselines Table
|
||||
*
|
||||
* Stores historical confidence statistics for drift detection:
|
||||
* - Average confidence per model version
|
||||
* - Standard deviation for anomaly detection
|
||||
* - Last update timestamp
|
||||
*
|
||||
* Uses ON CONFLICT for upsert pattern - baselines are updated
|
||||
* as new predictions come in.
|
||||
*/
|
||||
final class CreateMlConfidenceBaselinesTable implements Migration
|
||||
{
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
$schema = new Schema($connection);
|
||||
|
||||
$schema->createIfNotExists('ml_confidence_baselines', function (Blueprint $table) {
|
||||
// Model identification
|
||||
$table->string('model_name', 255);
|
||||
$table->string('version', 50);
|
||||
|
||||
// Confidence statistics
|
||||
$table->decimal('avg_confidence', 5, 4); // Average confidence score
|
||||
$table->decimal('std_dev_confidence', 5, 4); // Standard deviation
|
||||
|
||||
// Tracking
|
||||
$table->timestamp('updated_at')->useCurrent();
|
||||
|
||||
// Primary key: model_name + version (one baseline per model version)
|
||||
$table->primary('model_name', 'version');
|
||||
|
||||
// Index for lookup by model
|
||||
$table->index(['model_name'], 'idx_ml_baselines_model');
|
||||
});
|
||||
|
||||
$schema->execute();
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
$schema = new Schema($connection);
|
||||
$schema->dropIfExists('ml_confidence_baselines');
|
||||
$schema->execute();
|
||||
}
|
||||
|
||||
public function getVersion(): MigrationVersion
|
||||
{
|
||||
return MigrationVersion::fromTimestamp("2025_01_26_100002");
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Create ML confidence baselines table for drift detection";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\MachineLearning\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
use App\Framework\Database\Migration\MigrationVersion;
|
||||
use App\Framework\Database\Schema\Blueprint;
|
||||
use App\Framework\Database\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Create ML Models Table
|
||||
*
|
||||
* Stores machine learning model metadata including:
|
||||
* - Model identification (name, version)
|
||||
* - Model type (supervised, unsupervised, reinforcement)
|
||||
* - Configuration and performance metrics (JSON)
|
||||
* - Deployment status and environment
|
||||
*/
|
||||
final class CreateMlModelsTable implements Migration
|
||||
{
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
$schema = new Schema($connection);
|
||||
|
||||
$schema->createIfNotExists('ml_models', function (Blueprint $table) {
|
||||
// Primary identification
|
||||
$table->string('model_name', 255);
|
||||
$table->string('version', 50);
|
||||
|
||||
// Model metadata
|
||||
$table->string('model_type', 50); // supervised, unsupervised, reinforcement
|
||||
$table->text('configuration'); // JSON: hyperparameters, architecture, etc.
|
||||
$table->text('performance_metrics'); // JSON: accuracy, precision, recall, etc.
|
||||
|
||||
// Deployment tracking
|
||||
$table->boolean('is_deployed')->default(false);
|
||||
$table->string('environment', 50); // development, staging, production
|
||||
|
||||
// Documentation
|
||||
$table->text('description')->nullable();
|
||||
|
||||
// Timestamps
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
|
||||
// Primary key: model_name + version
|
||||
$table->primary('model_name', 'version');
|
||||
|
||||
// Indexes for efficient queries
|
||||
$table->index(['model_type'], 'idx_ml_models_type');
|
||||
$table->index(['environment', 'is_deployed'], 'idx_ml_models_env');
|
||||
$table->index(['created_at'], 'idx_ml_models_created');
|
||||
});
|
||||
|
||||
$schema->execute();
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
$schema = new Schema($connection);
|
||||
$schema->dropIfExists('ml_models');
|
||||
$schema->execute();
|
||||
}
|
||||
|
||||
public function getVersion(): MigrationVersion
|
||||
{
|
||||
return MigrationVersion::fromTimestamp("2025_01_26_100000");
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Create ML models metadata table";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\MachineLearning\Migrations;
|
||||
|
||||
use App\Framework\Database\ConnectionInterface;
|
||||
use App\Framework\Database\Migration\Migration;
|
||||
use App\Framework\Database\Migration\MigrationVersion;
|
||||
use App\Framework\Database\Schema\Blueprint;
|
||||
use App\Framework\Database\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Create ML Predictions Table
|
||||
*
|
||||
* Stores individual prediction records for performance tracking:
|
||||
* - Prediction inputs and outputs
|
||||
* - Actual outcomes (when available)
|
||||
* - Confidence scores
|
||||
* - Correctness evaluation
|
||||
*
|
||||
* Performance optimizations:
|
||||
* - Composite index on (model_name, version, timestamp) for time-window queries
|
||||
* - Partitioning-ready for large-scale deployments
|
||||
*/
|
||||
final class CreateMlPredictionsTable implements Migration
|
||||
{
|
||||
public function up(ConnectionInterface $connection): void
|
||||
{
|
||||
$schema = new Schema($connection);
|
||||
|
||||
$schema->createIfNotExists('ml_predictions', function (Blueprint $table) {
|
||||
$table->id(); // Auto-incrementing primary key
|
||||
|
||||
// Model identification
|
||||
$table->string('model_name', 255);
|
||||
$table->string('version', 50);
|
||||
|
||||
// Prediction data (JSON)
|
||||
$table->text('prediction'); // JSON: model output
|
||||
$table->text('actual'); // JSON: actual outcome (when available)
|
||||
$table->text('features'); // JSON: input features
|
||||
|
||||
// Performance metrics
|
||||
$table->decimal('confidence', 5, 4); // 0.0000 to 1.0000
|
||||
$table->boolean('is_correct')->nullable(); // null until actual outcome known
|
||||
|
||||
// Timing
|
||||
$table->timestamp('timestamp')->useCurrent();
|
||||
|
||||
// Composite index for efficient time-window queries
|
||||
$table->index(['model_name', 'version', 'timestamp'], 'idx_ml_predictions_lookup');
|
||||
|
||||
// Index for cleanup operations
|
||||
$table->index(['timestamp'], 'idx_ml_predictions_timestamp');
|
||||
});
|
||||
|
||||
$schema->execute();
|
||||
}
|
||||
|
||||
public function down(ConnectionInterface $connection): void
|
||||
{
|
||||
$schema = new Schema($connection);
|
||||
$schema->dropIfExists('ml_predictions');
|
||||
$schema->execute();
|
||||
}
|
||||
|
||||
public function getVersion(): MigrationVersion
|
||||
{
|
||||
return MigrationVersion::fromTimestamp("2025_01_26_100001");
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Create ML predictions tracking table";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user