fix positions
This commit is contained in:
@@ -62,6 +62,7 @@ class CreateJobPostings extends Migration
|
||||
'requirements' => ['type' => 'TEXT', 'null' => true],
|
||||
'status' => ['type' => 'VARCHAR', 'constraint' => 20, 'default' => 'draft'],
|
||||
'posted_by' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true],
|
||||
'posted_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'created_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
'updated_at' => ['type' => 'DATETIME', 'null' => true],
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class AddPostedAtToJobPositions extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
if (!$this->db->tableExists('job_positions')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->db->fieldExists('posted_at', 'job_positions')) {
|
||||
$this->forge->addColumn('job_positions', [
|
||||
'posted_at' => [
|
||||
'type' => 'DATETIME',
|
||||
'null' => true,
|
||||
'after' => 'posted_by',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->db->table('job_positions')
|
||||
->whereIn('status', ['open', 'closed', 'filled'])
|
||||
->where('posted_at', null)
|
||||
->set('posted_at', 'COALESCE(created_at, updated_at)', false)
|
||||
->update();
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
if ($this->db->tableExists('job_positions') && $this->db->fieldExists('posted_at', 'job_positions')) {
|
||||
$this->forge->dropColumn('job_positions', 'posted_at');
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class BackfillPostedAtForClosedFilledJobPositions extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
if (!$this->db->tableExists('job_positions') || !$this->db->fieldExists('posted_at', 'job_positions')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->db->table('job_positions')
|
||||
->whereIn('status', ['closed', 'filled'])
|
||||
->where('posted_at', null)
|
||||
->set('posted_at', 'COALESCE(created_at, updated_at)', false)
|
||||
->update();
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
// Data-only fallback for legacy rows.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user