Files
alrahma_sunday_school/app/Database/Migrations/2026-08-20-010000_CreateSettingsAndUserPreferencesTables.php
root d3da699e55
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 47s
Tests / PHPUnit (push) Failing after 1m19s
fix deployment db issue and widthrawal administration page
2026-08-20 20:18:00 -04:00

189 lines
6.5 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
/**
* Ensures production has the settings and user_preferences tables that
* TimeService / PreferencesModel expect. These tables historically came from
* SQL dumps rather than migrations, so some hosts never received them.
*/
class CreateSettingsAndUserPreferencesTables extends Migration
{
public function up()
{
if (! $this->db->tableExists('settings')) {
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'timezone' => [
'type' => 'VARCHAR',
'constraint' => 255,
'default' => 'America/New_York',
],
'updated_by' => [
'type' => 'INT',
'constraint' => 11,
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('settings', true);
$this->db->table('settings')->insert([
'name' => 'default',
'timezone' => 'America/New_York',
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
} elseif (! $this->db->fieldExists('timezone', 'settings')) {
$this->forge->addColumn('settings', [
'timezone' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => true,
'default' => 'America/New_York',
'after' => 'name',
],
]);
}
if (! $this->db->tableExists('user_preferences')) {
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'user_id' => [
'type' => 'INT',
'constraint' => 11,
],
'notification_email' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 1,
],
'notification_sms' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 1,
],
'theme' => [
'type' => 'VARCHAR',
'constraint' => 50,
'default' => 'light',
],
'language' => [
'type' => 'VARCHAR',
'constraint' => 50,
'default' => 'en',
],
'timezone' => [
'type' => 'VARCHAR',
'constraint' => 64,
'null' => true,
],
'style_color' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_color' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_custom_bg' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_custom_text' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_custom_mode' => [
'type' => 'VARCHAR',
'constraint' => 16,
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('user_id');
$this->forge->createTable('user_preferences', true);
} else {
$optionalColumns = [
'timezone' => [
'type' => 'VARCHAR',
'constraint' => 64,
'null' => true,
],
'style_color' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_color' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_custom_bg' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_custom_text' => [
'type' => 'VARCHAR',
'constraint' => 32,
'null' => true,
],
'menu_custom_mode' => [
'type' => 'VARCHAR',
'constraint' => 16,
'null' => true,
],
];
foreach ($optionalColumns as $column => $definition) {
if (! $this->db->fieldExists($column, 'user_preferences')) {
$this->forge->addColumn('user_preferences', [$column => $definition]);
}
}
}
}
public function down()
{
// Do not drop tables that may contain production preference data.
}
}