Page 1 of 1

Deleting Database Migration Safely Manually (not delete data)

Posted: Sun Apr 30, 2017 8:47 pm
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

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

Posted: Sun Apr 30, 2017 9:05 pm
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.

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

Posted: Sun Apr 30, 2017 9:16 pm
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.

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

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

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

Posted: Mon May 01, 2017 12:05 am
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

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

Posted: Mon May 01, 2017 12:22 pm
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

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

Posted: Tue May 02, 2017 8:46 pm
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)

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

Posted: Tue May 02, 2017 9:52 pm
by 3Di
Is not a good practise I can say.
And without knowing what you coded is even more difficult to help you.

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

Posted: Tue May 02, 2017 10:39 pm
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.

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

Posted: Wed May 03, 2017 2:22 am
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.

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

Posted: Sun May 07, 2017 11:33 am
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..

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

Posted: Mon May 08, 2017 9:12 pm
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. :)