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: 18293
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

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!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
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
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
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
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
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
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
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.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
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
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
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.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
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
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
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. :)
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
Post Reply

Return to “Extension Writers Discussion”