| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_Employees_Migration |
| 3 |
{ |
| 4 |
public $dbForge, $migrationService; |
| 5 |
|
| 6 |
public function __construct( |
| 7 |
HC3_Hooks $hooks, |
| 8 |
HC3_MigrationService $migrationService, |
| 9 |
?HC3_Database_DbForge $dbForge = NULL |
| 10 |
) |
| 11 |
{ |
| 12 |
$this->dbForge = $dbForge; |
| 13 |
$this->migrationService = $migrationService; |
| 14 |
} |
| 15 |
|
| 16 |
public function up() |
| 17 |
{ |
| 18 |
$currentVersion = $this->migrationService->getVersion( 'employees' ); |
| 19 |
|
| 20 |
if( $currentVersion < 1 ){ |
| 21 |
$this->version1(); |
| 22 |
$this->migrationService->saveVersion( 'employees', 1 ); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
public function version1() |
| 27 |
{ |
| 28 |
if( $this->dbForge ){ |
| 29 |
$this->dbForge->add_field( |
| 30 |
array( |
| 31 |
'id' => array( |
| 32 |
'type' => 'INT', |
| 33 |
'null' => FALSE, |
| 34 |
'unsigned' => TRUE, |
| 35 |
'auto_increment' => TRUE |
| 36 |
), |
| 37 |
'title' => array( |
| 38 |
'type' => 'VARCHAR(255)', |
| 39 |
'null' => FALSE, |
| 40 |
), |
| 41 |
'description' => array( |
| 42 |
'type' => 'TEXT', |
| 43 |
'null' => TRUE, |
| 44 |
), |
| 45 |
'show_order' => array( |
| 46 |
'type' => 'INT', |
| 47 |
'null' => FALSE, |
| 48 |
'default' => 0, |
| 49 |
), |
| 50 |
'status' => array( |
| 51 |
'type' => 'VARCHAR(16)', |
| 52 |
'null' => FALSE, |
| 53 |
'default' => 'active', |
| 54 |
), |
| 55 |
'user_id' => array( |
| 56 |
'type' => 'INT', |
| 57 |
'null' => TRUE, |
| 58 |
), |
| 59 |
) |
| 60 |
); |
| 61 |
$this->dbForge->add_key('id', TRUE); |
| 62 |
$this->dbForge->create_table('employees'); |
| 63 |
} |
| 64 |
} |
| 65 |
} |