Deleting Database Migration Safely Manually (not delete data)

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Deleting Database Migration Safely Manually (not delete data)

Post by aster59 »

Is there a documentation page for deleting migrations safely with phpBB?
I just have to delete ONE migration I did. I can't "delete data" for the rest of the migrations/extension either in this, so revert_schema() I guess won't be of use.

I would:
1.) Disable
2.) Delete migration file.
3.) Delete the table column manually in my phpMyAdmin
4.) Enable

Would that throw an error?


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

Re: Deleting Database Migration Safely Manually (not delete data)

Post by david63 »

If the extension is in the CDB then except in exceptional circumstances you cannot modify a previous migration file - you simply add a new migration file to reverse the action of the first one.

If it is an extension in development then you can do whatever you want with your migration files.
aster59 wrote: Sun Apr 30, 2017 8:47 pm I can't "delete data" for the rest of the migrations/extension either
Why?

Perhaps if you were to explain what it is that you are trying to do it would make it easier to assist.
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
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Deleting Database Migration Safely Manually (not delete data)

Post by aster59 »

david63 wrote: Sun Apr 30, 2017 9:05 pm you simply add a new migration file to reverse the action of the first one.
So looks like I could create a new migration called remove_mistake_field.php with only a revert_schema() and not an update_schema() one?

The users have data in there for a virtual currency system. If I deleted data for the whole extension, they would lose everything which wouldn't go over well.
I basically made a mistake and thought I needed a field in the users table I don't actually need. I want to get rid of that field without wiping it all.
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Deleting Database Migration Safely Manually (not delete data)

Post by aster59 »

Oh wait a minute. I would do an update_schema() with drop_columns instead of add_columns?
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: Deleting Database Migration Safely Manually (not delete data)

Post by 3Di »

aster59 wrote: Sun Apr 30, 2017 11:44 pm Oh wait a minute. I would do an update_schema() with drop_columns instead of add_columns?
Yes. Beware of dependencies. Example:

Code: Select all

	public function update_schema()
	{
		return array(
			'drop_columns'	=> array(
				$this->table_prefix . 'users'	=>	array(
					'your_field',
				),
			),
		);
	}
More on data changes
https://area51.phpbb.com/docs/dev/31x/e ... ta-changes

More on migration dependencies
https://area51.phpbb.com/docs/dev/31x/e ... ta-changes

Home page of the Docs for 3.1.x
https://area51.phpbb.com/docs/dev/31x/index.html

Home page of the Docs for 3.2.x
https://area51.phpbb.com/docs/dev/32x/index.html
🆓 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
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Deleting Database Migration Safely Manually (not delete data)

Post by javiexin »

aster59 wrote: Sun Apr 30, 2017 11:44 pm Oh wait a minute. I would do an update_schema() with drop_columns instead of add_columns?
Yes, and most probably, a revert_schema with add_columns as well. Otherwise, when you delete data for this extension, some migration may/will fail.

As 3Di indicated, beware of dependencies!
-javiexin
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Deleting Database Migration Safely Manually (not delete data)

Post by aster59 »

javiexin wrote: Mon May 01, 2017 12:22 pm
aster59 wrote: Sun Apr 30, 2017 11:44 pm Oh wait a minute. I would do an update_schema() with drop_columns instead of add_columns?
Yes, and most probably, a revert_schema with add_columns as well. Otherwise, when you delete data for this extension, some migration may/will fail.

As 3Di indicated, beware of dependencies!
-javiexin
Ok thank you all for the help!

I assume it is safe to rearrange my DB columns in phpMyAdmin? (with PHPBB tables)
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: Deleting Database Migration Safely Manually (not delete data)

Post by 3Di »

Is not a good practise I can say.
And without knowing what you coded is even more difficult to help you.
🆓 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
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Deleting Database Migration Safely Manually (not delete data)

Post by aster59 »

3Di wrote: Tue May 02, 2017 9:52 pm Is not a good practise I can say.
And without knowing what you coded is even more difficult to help you.
I made sure I backed up to do it. It appears to be working even when I disable and enable the extension.
I have about 10 migrations for the extension that add columns upon enable for first time. I definitely won't rearrange phpBB configuration of columns, just with this extension at the end of the table.
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: Deleting Database Migration Safely Manually (not delete data)

Post by 3Di »

aster59 wrote: Tue May 02, 2017 10:39 pm
3Di wrote: Tue May 02, 2017 9:52 pm Is not a good practise I can say.
And without knowing what you coded is even more difficult to help you.
I made sure I backed up to do it. It appears to be working even when I disable and enable the extension.
I have about 10 migrations for the extension that add columns upon enable for first time. I definitely won't rearrange phpBB configuration of columns, just with this extension at the end of the table.
If the extension you wrote is just for your personal use, on your Board (and not to be shared), you can do whatever you want with it and your DB. You have been lead to the right things already, now it's up to you.
🆓 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
aster59
Registered User
Posts: 82
Joined: Sun Jun 26, 2016 1:47 pm
Location: United States

Re: Deleting Database Migration Safely Manually (not delete data)

Post by aster59 »

3Di wrote: Wed May 03, 2017 2:22 am
aster59 wrote: Tue May 02, 2017 10:39 pm
3Di wrote: Tue May 02, 2017 9:52 pm Is not a good practise I can say.
And without knowing what you coded is even more difficult to help you.
I made sure I backed up to do it. It appears to be working even when I disable and enable the extension.
I have about 10 migrations for the extension that add columns upon enable for first time. I definitely won't rearrange phpBB configuration of columns, just with this extension at the end of the table.
If the extension you wrote is just for your personal use, on your Board (and not to be shared), you can do whatever you want with it and your DB. You have been lead to the right things already, now it's up to you.
I am very new to developing so I don't want to share an extension until I get better.
I guess if I were to share it then it would be a problem with the rearrangement? Or I guess I would have to rewrite the migrations just to be in a good order I saw fit..
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: Deleting Database Migration Safely Manually (not delete data)

Post by 3Di »

Migrations written in the right way is one of the rules of thumb. :)

To ask for help is not a shame, feel free. :)
🆓 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”