Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#26801 closed enhancement (wontfix)

Ability to drop table columns using dbDelta()

Reported by: toszcze's profile toszcze Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9
Component: Database Keywords: has-patch
Focuses: Cc:

Description

dbDelta() function doesn't drop columns that don't exist in the creation queries, but exist in the database.

I've attached a patch that adds this feature. Dropping columns is optional and disabled by default (it can be enabled by using the 'dbdelta_drop_columns' filter).

Attachments (1)

26801.diff (1.0 KB) - added by toszcze 11 years ago.

Download all attachments as: .zip

Change History (5)

@toszcze
11 years ago

#1 @toszcze
11 years ago

  • Keywords has-patch added

#2 @nacin
11 years ago

This feels a bit dangerous to include in such a shaky function.

We actually don't drop columns in WordPress unless we absolutely need to. When we've "dropped" columns in the post table over the years, for example, we've just left them on old installs.

#3 @toszcze
11 years ago

I agree it's dangerous - that's why this feature should be definitely disabled by default. Personally I think that it could be helpful for plugin developers who use their own database tables, but it's only my humble suggestion.

#4 @nacin
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

My point was that dbDelta() is extremely finicky. It requires exacting whitespace, among other things, in order to work. When it breaks and doesn't create a new table, or a new index, or a new field, well, that's not the end of the world. If it breaks and suddenly starts dropping columns because it didn't notice them in the CREATE TABLE, that's very, very bad.

As long as dbDelta() is in the shape it's in, I'm not OK with giving it the ability to destroy data in the process.

Note: See TracTickets for help on using tickets.