2

I have developed a Joomla extension and in the newest version the need to delete one column from a table belonging to my plugin has arisen.

As far as I know there is no easy way to delete a column in Mysql only if it exists. Therefore, the only possibility I see at the moment to achieve that, would be to use custom php upgrade code, as shown here.

But this problem would seem so common to me, that I would suspect to be an easier solution? Is there maybe an easy way (provided through Joomla) to execute a schema change only when updating from a particular extension version?

Community
  • 1
  • 1
codeling
  • 11,056
  • 4
  • 42
  • 71

1 Answers1

1

Check Managing Component Updates with Joomla; starting with Joomla 1.6 there is a defined way to execute specific SQL instructions for an upgrade from one version to another. Basically, for each version an SQL file has to be created (even if it's empty or only contains comments) in a specific file structure. The linked article explains the details.

codeling
  • 11,056
  • 4
  • 42
  • 71
Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
  • So it doesn't matter if statements fail in the upgrade sql? Because I will probably want to keep that statement in, so that upgrading across multiple versions also works as expected... but definitely worth a try, I hadn't thought of that (and it somehow feels wrong to deliberately take errors into account) – codeling Dec 19 '12 at 21:49
  • see the link above, it may answer your questions. – Valentin Despa Dec 19 '12 at 22:03
  • Ah, thanks for the link, there it is explained very nicely! Seems the joomla doc is not too well ranked at google, or my google foo is starting to fade ;) – codeling Dec 19 '12 at 22:16
  • hm, I must still do something wrong, my update sql files doesn't seem to get executed, tho i created both one for the current and the previous version...maybe i should start a new question ;) – codeling Dec 20 '12 at 00:12
  • better create a new question and post your manifest file there. good luck. – Valentin Despa Dec 20 '12 at 07:10
  • The ALTER TABLE part of your answer actually didn't help me at all, so I took the liberty of removing it! Got it to work now finally, following the guide from the article you linked. The problem was that the schema file for an extension of course has to be included with the original version already, it's not enough to include both the one of the original version and the updated one in the new version (don't know if I made myself clear, it's complicated to explain ;) ) – codeling Jan 06 '13 at 21:54