cloudlog/application/migrations/018_clubloguserfields.php
Peter Goodhall fe335e74bc Refactor user ClubLog fields migration
Update migration to use array definitions for new user ClubLog fields instead of raw SQL strings. This improves compatibility and clarity when adding columns to the 'users' table.
2025-11-09 15:43:20 +00:00

44 lines
No EOL
1.7 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_clubloguserfields extends CI_Migration {
public function up()
{
// Check and add each field only if it does not exist
$fields_to_add = array(
'user_clublog_name' => array(
'type' => 'VARCHAR',
'constraint' => 255,
'null' => TRUE,
),
'user_clublog_password' => array(
'type' => 'VARCHAR',
'constraint' => 255,
'null' => TRUE,
),
'user_clublog_callsign' => array(
'type' => 'VARCHAR',
'constraint' => 255,
'null' => TRUE,
),
);
// Get current columns in 'users' table
$fields = $this->db->list_fields('users');
foreach ($fields_to_add as $field => $definition) {
if (!in_array($field, $fields)) {
$this->dbforge->add_column('users', array($field => $definition));
}
}
}
public function down()
{
$this->dbforge->drop_column('users', 'user_clublog_name');
$this->dbforge->drop_column('users', 'user_clublog_password');
$this->dbforge->drop_column('users', 'user_clublog_callsign');
}
}