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.
Comment | File | Size | Author |
---|---|---|---|
#34 | schema.patch | 35.3 KB | amateescu |
#33 | 1180112-move_schema_functions.patch | 21.54 KB | franz |
#27 | 1180112-move_schema_functions.patch | 22.15 KB | franz |
#21 | 1180112-move_schema_functions.patch | 22.16 KB | franz |
#14 | 1180112-move_schema_functions.patch | 22.16 KB | franz |
Comments
Comment #1
franz+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
Comment #3
Pedro Lozano CreditAttribution: Pedro Lozano commentedschema.inc needs to be included also at includes/install.core.php
Comment #5
franzwrong patch format
Comment #7
franzAdded require_once in update.php
Comment #8
pamatt CreditAttribution: pamatt commentedComment #9
pamatt CreditAttribution: pamatt commented#7: 1180112-move_schema_functions.patch queued for re-testing.
Comment #11
franzWeird, what happened? It was working before!
Comment #12
pamatt CreditAttribution: pamatt commentedI 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().
Comment #13
franzAs 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.
Comment #14
franzThere 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.
Comment #15
franzComment #16
Lars Toomre CreditAttribution: Lars Toomre commentedThe 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.
Comment #17
franzI 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.
Comment #18
catchThe 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.
Comment #19
pamatt CreditAttribution: pamatt commented#14: 1180112-move_schema_functions.patch queued for re-testing.
Comment #21
franzJust re-rolling
Comment #22
Lars Toomre CreditAttribution: Lars Toomre commentedShould 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.
Comment #23
franz@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.
Comment #24
Anonymous (not verified) CreditAttribution: Anonymous commentedsubscribe.
Comment #25
franz#21: 1180112-move_schema_functions.patch queued for re-testing.
Comment #27
franzRe-rolled
Comment #29
franzBug 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.
Comment #30
franz#27: 1180112-move_schema_functions.patch queued for re-testing.
Comment #32
catchThat's a re-roll by-product, check SchemaCache:__construct() - bug fix went in about a week ago, missing brackets in the re-roll.
Comment #33
franzThanks.
Comment #34
amateescu CreditAttribution: amateescu commentedRecreated 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 bedb_write_record()
.Comment #35
sunLooks 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.
Comment #36
catchOn 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.
Comment #38
alberto56 CreditAttribution: alberto56 commentedPossibly related: #1618346: Error: Call to undefined function drupal_get_installed_schema_version() in core/includes/update.inc, line 94