Dev /

Adding a field to a SQL table

It's often needed to add a field, so DTC comes with a tool to do SQL upgrades from past versions at each upgrade.

First, at setup, each script written in admin/tables are called to create the tables. Consider them as scripts, and test it with:

   mysql -u root -p YourUsername <my-table.sql

Also, if you need to add a field in an already existing table, you will need to add it in the admin/tables script, and then in admin/dtc_db.php so the installer can do SQL upgrades on each installation (upgrades from previous version of the panel). admin/dtc_db.php is used by the installer to check for each field presence of it's content against the already installed database. If fields are not in the database, then the fields will be added to the tables using an ALTER TABLE sql statement generated automatically.

Take care not to mistake about the type of the feilds when you add them to admin/tables AND admin/dtc_db.php (I insist, insert your new fields in BOTH), because there is currently NO CODE to check for the type of field. That means that if you do a mistake with the field types and your code is commited to the Git, then the only way will be to add the code to bin/sources/restor_db.php for altering the text fields, and that's quite ugly code. A patch to check against fields type in restor_db.php would be much needed, feel free to contribute!

Page last modified on April 02, 2008, at 04:08 PM EST