HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Ability to add a new Database Table?

MrCaspanMrCaspan
edited February 2020 in Vanilla 3.x Help

I can see in the developer documentation here https://docs.vanillaforums.com/developer/framework/database/ that you can structure a database table. But it gives no code on how to create a new table?

I could just add a comma separated varchar column to my discussion row but that is not proper database format to store comma separated data in a single filed it should have it's own look up table. Is there a way to create tables in Vanilla?

Comments

  • tables or columns?

  • I want to add a new table

  • I suggest you take a look at the /applications/dashboard/settings/structure.php and /applications/vanilla/settings/structure.php files to find examples.

    But an example looks like that:


       public function setup() {
           $this->structure();
       }
    
       public function structure() {
           Gdn::structure()->table('Something')
                ->primaryKey('SomethingID')
               ->column('Name', 'varchar(255)', false)
               ->column('Default', 'text', false)
               ->column('Result', 'text', false)
               ->set();
       }
    
  • Look in here for some nice fun facts

    \applications\dashboard\settings\structure.php

    https://github.com/vanilla/vanilla/blob/master/applications/dashboard/settings/structure.php#L29


    $Database = Gdn::database();
    $SQL = $Database->sql();
    $Construct = $Database->structure();
    $Px = $Database->DatabasePrefix;
    
    
    // Role Table
    $Construct->table('Role');
    
    
    $RoleTableExists = $Construct->tableExists();
    $RoleTypeExists = $Construct->columnExists('Type');
    
  • Or just take a look at some plugins that already do that...

    All the above answers are great but when I started I found existing plugins a treasure trove for learning...

Sign In or Register to comment.