How to Update Extensions Table?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 6669
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

How to Update Extensions Table?

Post by HiFiKabin »

I know I am probably missing the obvious, but having created a database table in the extensions initial install how do I later add another column to it with a migration update file? I have tried all that I can think of, and can not find an existing extension that I can 'crib' from.

My existing migration file includes this

Code: Select all

	public function update_schema()
	{
		return array(
			'add_tables'	=> array(
			// ADD NEW TABLE STRUCTURE
				$this->table_prefix . 'randombanner'	=> array(
					'COLUMNS' => array(
					'randombanner_id'			=> array('UINT', null, 'auto_increment'),
					'randombanner_image'		=> array('VCHAR', ''),
					'randombanner_url'			=> array('VCHAR', ''),
					),
					'PRIMARY_KEY'	=> 'randombanner_id',
				),
			),
		);
	}
and I want to add

Code: Select all

					'randombanner_target'		=> array('UINT', '0')
As its not yet validated I could of course just re write the migration file, but there are some 80 people using the extension and I don't want to cause them any problems if I can avoid it.

TiA
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: How to Update Extensions Table?

Post by david63 »

This should do it - don't forget to check that the original is installed

Code: Select all

public function update_schema()
	{
		return array(
			'add_columns'	=> array(
				$this->table_prefix . 'randombanner'	=> array(
					'randombanner_target'	=> array('UINT', '0'),
				),
			),
		);
	}
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: How to Update Extensions Table?

Post by mrgoldy »

Just to add to what david means, is the public function depends_on() (and possibly even public function effectively_installed()).
Also, and this is a guess, you can probably use something else than UINT, which will allow numbers from 0 to 16,777,215. While I think you're more after a number between 0 and probably something like 10. So you could probably use something like TINT:%d or USINT.
For more about Database Type Map see here: https://wiki.phpbb.com/Database_Type_Map
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: How to Update Extensions Table?

Post by canonknipser »

And a additional addition to what david and mrgoldy already explained: There are also some nice tutorials on area 51
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 6669
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Re: How to Update Extensions Table?

Post by HiFiKabin »

david63 wrote: Mon Jan 14, 2019 12:44 pm This should do it - don't forget to check that the original is installed
<snip>
Perfect, thanks David (and Gijs and Frank. Lots more reading for me there)
User avatar
</Solidjeuh>
Registered User
Posts: 1788
Joined: Tue Mar 29, 2016 3:45 am
Location: Aalst (Belgium)
Name: Andy Dm
Contact:

Re: How to Update Extensions Table?

Post by </Solidjeuh> »

HiFiKabin wrote: Mon Jan 14, 2019 12:39 pm but there are some 80 people using the extension and I don't want to cause them any problems if I can avoid it.
We know the risks of using RC versions, so it's on us! :D We can also just simple delete data, and start over again. It's not that much, just adding url's and all is good again.
User avatar
HiFiKabin
Community Team Member
Community Team Member
Posts: 6669
Joined: Wed May 14, 2014 9:10 am
Location: Swearing at the PC, UK
Name: James
Contact:

Re: How to Update Extensions Table?

Post by HiFiKabin »

Thanks Andy. Just me trying to be kind to everyone (although you will have a bit more translation to do :lol: )
Post Reply

Return to “Extension Writers Discussion”