As discussed at length in #866340: Remove support for date and time types, it would be very useful to have a way to dynamically change the column specification passed to db_create_table(), db_add_field() and db_change_field().

That would allow contrib modules (like the date module) to implement new portable types (date, datetime, time by the date module, for example, but we can also think about gis types or xml types).

We already have hook_schema_alter(), but it is only designed to alter the conceptual schema, and is not called (nor arguably supposed to be called) when creating the actual database structures.

CommentFileSizeAuthor
#5 schema_alter_ideas.patch1.03 KBjpstrikesback
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rfay’s picture

So should this be critical? And a task?

KarenS’s picture

Category: feature » task
Priority: Normal » Critical

I don't think this is a feature request. We can do this in D6, without it we have a regression. I don't mean we have a an alter() in D6, I mean we are able to create a table with a field type that is not defined by core without errors.

And I would call it critical because it is a post-freeze regression without this capability.

Damien Tournoud’s picture

KarenS, please don't confuse this with #927828: Some schema code incorrectly rely on the generic type instead of the engine-specific type, which is the actual bug that prevents creation of fields without a generic type.

KarenS’s picture

Priority: Critical » Normal

OK, if that issue will fix the problem.

jpstrikesback’s picture

Status: Active » Needs review
FileSize
1.03 KB

Here is a few ideas, probably incomplete but it works for the alter at table creation use-case:

Used like so (thanks for the schema_alter examples in #866340 Damien and in Date KarenS):

function date_api_db_create_table_alter(&$table) {
  foreach ($table['fields'] as &$field) {
    if ($field['type'] == 'datetime') {
      $field += array('mysql_type' => 'DATETIME', 'pgsql_type' => 'timestamp without time zone');
    }
    elseif ($field['type'] == 'date') {
      $field += array('mysql_type' => 'DATE', 'pgsql_type' => 'date');
    }
    elseif ($field['type'] == 'time') {
      $field += array('mysql_type' => 'TIME', 'pgsql_type' => 'time without time zone');
    }
  }
}

Status: Needs review » Needs work

The last submitted patch, schema_alter_ideas.patch, failed testing.

bjaspan’s picture

I'm only just coming up to speed on this issue now. One thought re: the code in #5: Since we're still using anonymous arrays for Schema API, AFAIK nothing at all prevents you from putting any random properties into a field structure that you want, e.g.

$schema['tbl']['fields']['mydate'] = array('type' => 'int', 'mydate_type' => 'datetime', ...);

Then in a hook_schema_alter() you can check for $field['mydate_type'] and change $field['type'] appropriately, and fail with an explicit error if the engine type is not supported by the mydate module. The 'type' => 'int' is a lie but will either be fixed up by hook_schema_alter() or irrelevant because the module will not install or throw an error.

jpstrikesback’s picture

@bjaspan How would this work for fields (fields in core fields) at table creation? For example...a drupal-field that uses datetime type db-field?

KarenS’s picture

@bjaspan, I tried that idea initially and ran into trouble, as I described in http://drupal.org/node/866340#comment-3265428. I ended up doing this by using schema_alter() instead, which is also currently broken.

Pancho’s picture

Version: 7.x-dev » 8.x-dev
Category: task » feature
Priority: Normal » Major

moved this as a feature request to the D8 queue

jhedstrom’s picture

Issue summary: View changes

While this is technically a feature request, since it was a regression from D6, I wonder if this is still possible to get into 8.0?

jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev

Feature request => 8.1.x.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.