XF 2.0 Database query

abdfahim

Well-known member
Is this object-oriented style a MySql syntax or XF-specific syntax?

SQL:
$table->addColumn('demo_portal_auto_feature', 'tinyint')->setDefault(0);

I usually use the Procedural style

SQL:
ALTER TABLE mytable ADD COLUMN demo_portal_auto_feature .......

If it is XF-specific, where can I find a reference of all supported methods? I want to perform below queries:

Code:
$db->query("ALTER TABLE `xf_user_field` CHANGE `display_group` `display_group` ENUM('personal','contact','preferences','myaddon_new_column')
                       CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'personal';");

$db->query("UPDATE xf_user_field SET display_group = 'myaddon_new_column' WHERE field_id IN ('myaddon_my_field')");
 
That's part of the schema manager system. See XF\Db\SchemaManager and the namespace XF\Db\Schema. I'd strongly recommend using an IDE that can support autocomplete and inspections. You'll instantly be able to see what methods are available, for example.
 
The codes in XF/Db are very much insightful and PhpStorm also is awesome (never used a PHP IDE before).

However, when I tried the following code, for some reason all the options of enum() gets converted to UPPERCASE
SQL:
public function installStep1()
{
        $this->schemaManager()->alterTable('xf_user_field', function(Alter $table)
        {
            $table->changeColumn('display_group', 'enum(\'personal\',\'contact\',\'preferences\',\'myaddon_new_column\')');
        });
}

Before:
1507462254934.webp

After:
1507462480985.webp
 
Top Bottom