Alter table add column at plugin installation time

Alter table add column at plugin installation time

by Rajesh Pant -
Number of replies: 2
Thanks in advance.

I am creating my own plugin. i have to create one more field in assignment table(eg. alter table add column) how do i create.

i also need the setting for it in the admin section, how do i create it?
Average of ratings: -
In reply to Rajesh Pant

Re: Alter table add column at plugin installation time

by Sam Hemelryk -
Hi Rajesh,

Could you please tell us what sort of plugin you are trying to create?

Off the bat I would question whether modifying the assignment table was the best way to do whatever you are attempting to achieve. But I suppose that depends on what you are trying to achieve smile

Cheers
Sam
In reply to Rajesh Pant

Re: Alter table add column at plugin installation time

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Don't do that. At least, not if you can avoid it!

At the OU we have many modifications to core tables, but we are planning to move toward a situation where instead of modifying the core tables, if we really really need the change, we instead add a new table with _ou at the end of the name and with one field which is the id from the original table (mod_assignment_ou and assignmentid in this case). We can make functions which will retrieve and set this information when needed.

This is a bit harder to do (and it may mean that, for example, we probably aren't going to make it handle deletes properly, so over the years we'll build up some unnecessary rows) but I think we decided it's better if at least our core database tables are completely unchanged.

Apart from clarity (being easily able to tell what is core and what isn't) one advantage of separating the two is that changes to install.xml files really don't merge well.

So for your case, you could just create a table called mod_mymodule_assignmentdata and stick the data in there.

As for admin settings (site-wide) just make a settings.php file inside your module - look at existing ones to see how this works.

--sam