Migration change column

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3726
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Migration change column

Post by Kailey »

Is it possible to change a column in a migration? Specifically, I want to change the name from my_old_column to my_new_column. I tried looking through the documentation but couldn't find anything.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Migration change column

Post by david63 »

Is it in the CDB? If not then you can, if you wish, do whatever you want. If not then it will be more difficult - you could try adding the new column, copy the data from the old column and then drop the old column.
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
Kailey
Community Team Leader
Community Team Leader
Posts: 3726
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Migration change column

Post by Kailey »

david63 wrote: Mon Jan 21, 2019 11:13 pm Is it in the CDB?
Yes.

My other option is to rewrite the extension and I guess just advise users that there is no upgrade path. I'm trying to avoid that. Thanks though!
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Migration change column

Post by david63 »

kinerity wrote: Tue Jan 22, 2019 1:14 am My other option is to rewrite the extension
A bit drastic just to rename a column.

Out of interest why do you need to re-name a column?
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
Kailey
Community Team Leader
Community Team Leader
Posts: 3726
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Migration change column

Post by Kailey »

I'm adding a few features and wanted to better correlate column names between the new tables.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Migration change column

Post by canonknipser »

So create the new column, copy the data to the new column in case of a version update (if there's plenty of data, maybe you need to do it in chunks or use a cron), and in one of the next versions simply drop the old column.
I guess you can check a version update or a new install in your extension to trigger the copy only in case of an update.
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
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Migration change column

Post by david63 »

canonknipser wrote: Tue Jan 22, 2019 6:23 pm So create the new column, copy the data to the new column in case of a version update (if there's plenty of data, maybe you need to do it in chunks or use a cron), and in one of the next versions simply drop the old column.
I guess you can check a version update or a new install in your extension to trigger the copy only in case of an update.
Isn't that basically what I said? :o
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
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Migration change column

Post by 3Di »

Why not to use "change_columns" simply?
And yes it is documented here https://area51.phpbb.com/docs/dev/3.2.x ... l#examples

And data changes are here: https://area51.phpbb.com/docs/dev/3.2.x ... -processes
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Migration change column

Post by canonknipser »

david63 wrote: Tue Jan 22, 2019 6:43 pm Isn't that basically what I said? :o
Yes, it is. Maybe it's more trustworthy the more people say it ;)
3Di wrote: Tue Jan 22, 2019 6:48 pm Why not to use "change_columns" simply?
And yes it is documented here https://area51.phpbb.com/docs/dev/3.2.x ... l#examples
Isn't that about data type changes? No way to specify a new column name ;) I just checked the sources of the database tools, no way to change a column name from the dbal
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
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Migration change column

Post by david63 »

3Di wrote: Tue Jan 22, 2019 6:48 pm Why not to use "change_columns" simply?
Change columns is for changing type - it specifically states not for changing name
* Change column type (not name!)
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
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Migration change column

Post by 3Di »

Ah yes, correct.

Time to add a new tool to the existing ones or modify the "change_columns" to allow such changes? :geek:

(an example for most of the supported DB)
https://www.techonthenet.com/sql/tables/alter_table.php
Based on the above I think it could be possible to call a custom function and code a "case" switch of sort, not tested.

On this purpose the second link I above posted could be the way to go for this (also usable to do what you suggested).
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “Extension Writers Discussion”