mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-25 22:27:05 -04:00
- Add `runPendingMigrations()` to `PluginManager` for executing plugin-specific migrations. - Create `PluginMigrationModel` for managing plugin migration versions. - Add migration for creating the `plugin_migrations` table to track migration states. Signed-off-by: objec <objecttothis@gmail.com>
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class PluginMigrationModel extends Model
|
|
{
|
|
protected $table = 'plugin_migrations';
|
|
protected $primaryKey = 'plugin_id';
|
|
protected $useAutoIncrement = false;
|
|
protected $useSoftDeletes = false;
|
|
protected $allowedFields = ['plugin_id', 'version', 'ran_at'];
|
|
|
|
public function getVersion(string $pluginId): int
|
|
{
|
|
$row = $this->db->table('plugin_migrations')
|
|
->where('plugin_id', $pluginId)
|
|
->get()
|
|
->getRow();
|
|
|
|
return $row ? (int) $row->version : 0;
|
|
}
|
|
|
|
public function setVersion(string $pluginId, int $version): bool
|
|
{
|
|
$builder = $this->db->table('plugin_migrations');
|
|
$exists = $builder->where('plugin_id', $pluginId)->countAllResults() > 0;
|
|
|
|
if (!$exists) {
|
|
return $builder->insert([
|
|
'plugin_id' => $pluginId,
|
|
'version' => $version,
|
|
'ran_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
}
|
|
|
|
return $builder->update(
|
|
['version' => $version, 'ran_at' => date('Y-m-d H:i:s')],
|
|
['plugin_id' => $pluginId]
|
|
);
|
|
}
|
|
}
|