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?

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?


  • Options

    tables or columns?

  • Options

    I want to add a new table

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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() {
       public function structure() {
               ->column('Name', 'varchar(255)', false)
               ->column('Default', 'text', false)
               ->column('Result', 'text', false)
  • Options

    Look in here for some nice fun facts



    $Database = Gdn::database();
    $SQL = $Database->sql();
    $Construct = $Database->structure();
    $Px = $Database->DatabasePrefix;
    // Role Table
    $RoleTableExists = $Construct->tableExists();
    $RoleTypeExists = $Construct->columnExists('Type');
  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    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.