Bulk Insert Fields into cms_accounts table

5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 7, 2019   (RSS)

By dm - March 6, 2019

Hi,

I have a very large list of extra textfields I would like to add to the cms_accounts table.

Can you advise on the best way of going about this with v3.50.

Many thanks for the help!

dm

By dm - March 7, 2019 - edited: March 7, 2019

Ok, so I installed the developer console plugin and found I can easily add additional fields using this code in the MYSQL Console:

ALTER TABLE `cmsb_accounts`
ADD COLUMN stage_1 MEDIUMTEXT,
ADD COLUMN stage_2 MEDIUMTEXT,
ADD COLUMN stage_3 MEDIUMTEXT,
ADD COLUMN stage_4 MEDIUMTEXT;

However I would also like to be able to specify the content for "Field Label" and "Field Type" for these new columns too... (field labels would be same as field names and all field types would be "textfield")

If someone can give me a few pointers on how to do this it would be much appreciated as my mysql skills are quite limited.

By Steve99 - March 7, 2019

Hi dm,

If you're comfortable working with multidimensional arrays, you could work directly with the schema ini file for the accounts table. CMSB has an internal function that creates "missing" table fields from the schema ini php files. So potentially you could add new field arrays to the ini php file, upload the modified file, then go to the section editors admin menu and it will automatically create the new fields.

Just make sure to download the current file(s) from the server before making any changes, and always make backups of your files and database.

You may find this method a little bit faster if you're simply adding a bunch of common text fields. However, the field types do have different array structures so be mindful of that.

If you are planning on adding a bunch of different field types then you're better off just creating them directly through the cms admin using the standard add field process. There's also a "quick add field" feature so you could rapidly create a series of fields. That way you know they're being created properly, and it's likely a faster process anyway. 

Hope this info helps.

Best,
Steve

By dm - March 7, 2019

Hi Steve, thanks very much for suggestion!

I will investigate the schema files. :)

By daniel - March 7, 2019

Hi dm,

As Steve mentioned, the two ways to add things like Field Label and Field Type to a field are either by modifying the schema file or through the Section Editor. If you attempt to edit the schema, a few additional notes:

  • They can be found in /cmsb/data/schema/ and will be named after the section
  • A simple method to make sure you have all the right options is to first create a field through the Section Editor which meets your needs, then find that definition in the schema file and duplicate it.
  • If the order of the fields is important, make sure to update the 'order' value; fields are sorted by this value in ascending order (smallest to biggest). 
  • After manually modifying a schema file, you must visit the main Section Editors page (http://example.com/cmsb/admin.php?menu=database) to trigger the database to sync the changes

Let me know if you have any further questions!

Thanks,

Daniel
Technical Lead
interactivetools.com