drupal_get_schema(), drupal_schema_fields_sql() and various other functions are currently dotted around bootstrap.inc, common.inc and install.inc

All of those functions depend 100% on the module system - since they all invoke hook_schema() for one or more modules internally. Additionally, enabling modules, disabling modules, the update system etc. all depend on them too. So if we're going to put them in one place, then it would make sense to move them to either module.inc or a new schema.inc

There are a couple of notes about db drivers depending on these, this is no longer the case for any of the core drivers, I've not yet checked contrib drivers.

A lot of these functions are needed very rarely, sometimes never on a production site, that's the kind of thing it would be worth trying to convert to a class to be lazy loaded - code that is never or almost-never loaded during the normal lifecycle of an apache process is worth lazy-loading with or without an opcode cache. However that in itself shouldn't stop us just moving the code for now.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

franz’s picture

Status: Active » Needs review
FileSize
18.69 KB

+1 for schema.inc

The drupal_get_schema_versions(), drupal_get_installed_schema_version() and drupal_set_installed_schema_version() - all in intall.inc - were not in group schemaapi. I left _drupal_schema_initialize(), drupal_schema_fields_sql() and drupal_write_record() in common.inc

 includes/bootstrap.inc |   76 --------------
 includes/common.inc    |   83 +---------------
 includes/install.inc   |   98 ------------------
 includes/schema.inc    |  264 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 265 insertions(+), 256 deletions(-) 

Status: Needs review » Needs work

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

Pedro Lozano’s picture

Status: Needs work » Needs review
FileSize
18.89 KB

schema.inc needs to be included also at includes/install.core.php

Status: Needs review » Needs work

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

franz’s picture

Status: Needs work » Needs review
FileSize
19.3 KB

wrong patch format

Status: Needs review » Needs work

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

franz’s picture

Status: Needs work » Needs review
FileSize
19.8 KB

Added require_once in update.php

pamatt’s picture

pamatt’s picture

Issue tags: -Framework Initiative

#7: 1180112-move_schema_functions.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Framework Initiative

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

franz’s picture

Weird, what happened? It was working before!

pamatt’s picture

I was trying to apply your patch and I couldn't, so I guessed I'd better resubmit it for test. You can see the result. Anyway, why did you opt to create a new .inc file, at the cost of including it here and there? It seems that module.inc could be a good place for the schema functions, and maybe also for _drupal_schema_initialize(), drupal_schema_fields_sql() and drupal_write_record().

franz’s picture

A lot of these functions are needed very rarely, sometimes never on a production site, that's the kind of thing it would be worth trying to convert to a class to be lazy loaded - code that is never or almost-never loaded during the normal lifecycle of an apache process is worth lazy-loading with or without an opcode cache. However that in itself shouldn't stop us just moving the code for now.

As you can read from the description, leaving those inside schema.inc is better in long-term, specially if it's going to be lazy-loaded in the future.

I didn't find these other functions you cited, but drupal_write_record() is used quite often, so it wouldn't benefit so much to have it there, for the very same reasons.

Patch needs to be re-rolled. Doing it.

franz’s picture

There were some changes in functions, so I tried to make adapt to those - meaning, checked all of them for changes. The class for schema cache is also being moved.

franz’s picture

Status: Needs work » Needs review
Lars Toomre’s picture

Status: Needs review » Needs work

The cache_get() and cache_set() functions were changed within the last week to use the new API class in D8.

You might want to add documentation in this patch that the cache API class has its own implementation of schema() so that needed cache bins can be created dynamically. I do not know if any other major core classes have their own schema definitions.

franz’s picture

I don't see how this documentation - which refers to some other functionality - would fit in this patch. If the documentation is added otherwise to some function we're moving, we can re-roll this patch to contain it.

catch’s picture

Status: Needs work » Needs review

The cache API ->schema() method hasn't been committed yet, and it'll be in the database implementation not the interface if it is, so it shouldn't affect this patch either way. Issue is here for reference #1167144: Make cache backends responsible for their own storage.

Patch looks fine. It's a shame to move some code from install.core.inc to common.inc, but it's also great to move it out of bootstrap.inc - and once it's in one place we can look at OOP-ifying this to lazy load schema (since these shouldn't be needed often and when they have been we've treated that as a bug).

As far as I can see the patch is up to date with the cache() change so I'm moving back to CNR.

pamatt’s picture

Issue tags: -Framework Initiative

Status: Needs review » Needs work
Issue tags: +Framework Initiative

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

franz’s picture

Status: Needs work » Needs review
FileSize
22.16 KB

Just re-rolling

Lars Toomre’s picture

Should this patch include docblock corrections or should that be deferred to another issue?

For instance, at start of docblocks should be an active verb... s/Get/Gets/
Also there should be a blank line before @return doc line.
Finally, several @return doc lines are missing completely.

franz’s picture

@Lars, well, since we're moving them around, if it's changed elsewhere it needs to be re-rolled here. Still, doc corrections get faster into code, IMO it's better handle it separated and update this ticket when that's committed.

Anonymous’s picture

subscribe.

franz’s picture

Issue tags: -Framework Initiative

Status: Needs review » Needs work
Issue tags: +Framework Initiative

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

franz’s picture

Status: Needs work » Needs review
FileSize
22.15 KB

Re-rolled

Status: Needs review » Needs work

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

franz’s picture

Bug is really weird. Looks like schema is being written in cache with cid = ''. I don't know how this function moves could've caused it, I checked them one by one.

franz’s picture

Status: Needs work » Needs review
Issue tags: -Framework Initiative

Status: Needs review » Needs work
Issue tags: +Framework Initiative

The last submitted patch, 1180112-move_schema_functions.patch, failed testing.

catch’s picture

That's a re-roll by-product, check SchemaCache:__construct() - bug fix went in about a week ago, missing brackets in the re-roll.

franz’s picture

Status: Needs work » Needs review
FileSize
21.54 KB

Thanks.

amateescu’s picture

FileSize
35.3 KB

Recreated this patch in http://drupalcode.org/sandbox/sun/1255586.git/shortlog/refs/heads/platfo...

Do we also want to handle Schema API functions from database.inc in this issue? And while we're at it, I think drupal_write_record() should be db_write_record().

sun’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, merely moves functions around.

The functions in bootstrap.inc shouldn't have been in bootstrap.inc in the first place.

Wasn't 100% sure whether drupal_write_record() should be moved as well, but as it completely relies on the other schema.inc functions, that makes sense.

There's only one stale require_once for common.inc in one of the moved functions, but that ain't really a problem and can be cleaned up later.

catch’s picture

Status: Reviewed & tested by the community » Fixed

On the db_* vs. drupal_*_schema, I think those are two classes of functionality. The first is for schema changes - which takes a schema definition as argument but doesn't have much in the way of dependencies.

The drupal_*_schema (and drupal_write_record() on the other hand are all based on hook_schema() so have an explicit dependency on the module system). So it makes sense for them to be separate, but this is an area that could really use an overhaul.

Patch looks good to me, so I've committed/pushed this to 8.x. Would be good to look at a follow-up to convert the functions in this file into a class so we can lazy load it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

alberto56’s picture