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. } }