We officially have access to php 5.4.x which means we can leverage traits. As @Crell mentions here: http://www.garfieldtech.com/blog/beyond-abstract abstract classes a likely unnecessary in favor of traits + interfaces. DBTNG is one of the hardest systems to follow in the IDE due to a.) it's architecture and b.) it's documentation. I've attempted to fix quite a bit of both these problems as they exist within the schema portion of dbtng as a first pass. I've introduced a SchemaInterface and moved all the methods in the abstract schema class into a DatabaseSchemaTrait. Hopefully this gets us started in introducing traits into D8.

Eclipse

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EclipseGc’s picture

Status: Active » Needs review

whoops

Eclipse

sun’s picture

Any particular reason for why we need both abstract methods in the trait AND the same methods on an interface? The interface should be sufficient, no?

Status: Needs review » Needs work

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

EclipseGc’s picture

@sun,

I had the same reaction initially, but the trait really is an implementation of the interface and if I don't put abstract methods on it, then it could be used outside the interface's confines, which while exceptionally unlikely, is not outside the realm of possibility. Some of this is discussed here: http://www.garfieldtech.com/blog/beyond-abstract#comment-2398

I'm pretty new to this trait thing so... open to suggestions, but I tried to implement this as I thought was "right" from the perspective of the interface I introduced.

Eclipse

EclipseGc’s picture

Status: Needs work » Needs review

SchemaTraits.patch queued for re-testing.

Status: Needs review » Needs work

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

EclipseGc’s picture

Status: Needs work » Needs review
FileSize
62.85 KB

Missed a testing file, let's see if this passes.

Eclipse

Status: Needs review » Needs work

The last submitted patch, 7: 2206183-7.patch, failed testing.

EclipseGc’s picture

Status: Needs work » Needs review
FileSize
64.73 KB

Fixed some tests and strings.

Eclipse

EclipseGc’s picture

Documentation fixed based upon the evolving discussion in #2206175: [policy, no patch] Figure out how to document traits and trait methods and removed some unnecessary use statements in the trait.

Eclipse

EclipseGc’s picture

FileSize
64.66 KB

oops

Damien Tournoud’s picture

Color me not convinced here. Having the interface is a good thing, but your trait here is really an abstract base class... so there is no real advantage in having it as a trait, it just makes things a little bit weirder with no gain.

Traits are for code reuse of relatively self-enclosed behaviors. Here there is no such thing, so let's keep the abstract base class.

Interface yes, trait (as is), no.

tim.plunkett’s picture

Traits are nice when you don't want to squat the only opportunity to use extends that a class can have.
But this is clearly a case where we actually want a base class:
Drupal\Core\Database\Driver\mysql\Schema extends Drupal\Core\Database\Schema

msonnabaum’s picture

100% agree with #12.

EclipseGc’s picture

As I said to msonnabaum earlier today, I don't really feel like this is a fight either way. I prefer our system to be more flexible, but if the world is against this as an approach, that's fine too. Still Crell makes the point that abstract base classes are largely vestigial as of 5.4.x. If we collectively don't agree, alright by me, but this seems like something we should discuss more.

FWIW, I interpreted abstract class's new place in the world identically to Crell.

I'll roll another patch moving this back to an abstract tomorrow and we can discuss further from there.

Eclipse

Damien Tournoud’s picture

@EclipseGc: it's a question of code organization. ABCs can be considered as vestigial only if you organize your code around small, relatively self contained object behaviors (emphasis on small and self-contained). Without further refactoring we don't do such a thing here, the abstract class Schema is a big mix of a lot of different stuff all closely tied together.

If broken down, many of those would be good fit as a trait (the clearest one being a concrete implementation of PlaceHolderInterface), but until broken down it's better to keep the whole thing as an ABC.

Crell’s picture

In the interest of progress I'm OK with backing off on the trait here and circling back around later after further refactoring (should any happen in D8), which I think we all agree is long-overdue for Schema API.

Damien is correct that placeholderinterface is a good target for traitification.

jhodgdon’s picture

Status: Needs review » Needs work

The documentation in this patch is not going to work.

The main doc block for this Trait starts with

+/**
+ * @defgroup schemaapi Schema API
+ * @{
+ * API to handle database schemas.
+ *

Defining a @defgroup needs to be separate from the Trait's doc block.

Also, there's an issue about defining standards for how to document traits that may be of interest:
#2206175: [policy, no patch] Figure out how to document traits and trait methods

EclipseGc’s picture

FileSize
40.45 KB

Ok, discussed this with Crell a little bit, and have opted to just trait-ify the Placeholder stuff. Otherwise, I've moved this back to an abstract base class but it has an interface now. I used git diff -M so it's pretty easy to read. I did however move a few methods around to be better groups which made for some patch weirdness. All the Schema subclasses (except tests) were using the class as DatabaseSchema, so I renamed the class to DatabaseSchema. I think it reads pretty easily. I also added the trait in the 2 other classes that were implementing PlaceholderInterface as they had the identical code to what was in my trait. There are tests that also implement the interface but they JUST throw exceptions, so the scope of this was super narrow. I also updated the docs for most of the files I touched, but especially in the SchemaInterface I tried to nail down all the returns as many of those were missing.

Hopefully this seems better to everyone in terms of using a trait and generally cleaning up some stuff in DBTNG.

Also, addressing jhodgdon's point, I moved back to an abstract base class, so I _THINK_ that's no longer an issue.

Eclipse

EclipseGc’s picture

Status: Needs work » Needs review

bah cross posts :-(

Eclipse

EclipseGc’s picture

FileSize
40.88 KB

Based on feedback in irc, encapsulated the uniqueIdentifier() method within the trait.

Eclipse

EclipseGc’s picture

FileSize
40.94 KB

fixed a comment I missed in the trait, otherwise the code's identical to 21, shouldn't need a retest.

Eclipse

Status: Needs review » Needs work

The last submitted patch, 22: 2206183-22.patch, failed testing.

EclipseGc’s picture

Status: Needs work » Needs review
FileSize
540 bytes

I asked Randy Fay to cancel that last test. Here's an interdiff.

Eclipse

Crell’s picture

  1. +++ b/core/lib/Drupal/Core/Database/DatabaseSchema.php
    @@ -367,359 +321,119 @@ public function fieldExists($table, $column) {
    -  /**
    -   * Create a new table from a Drupal table definition.
    -   *
    -   * @param $name
    -   *   The name of the table to create.
    -   * @param $table
    -   *   A Schema API table definition array.
    -   *
    -   * @throws \Drupal\Core\Database\SchemaObjectExistsException
    -   *   If the specified table already exists.
    -   */
    -  public function createTable($name, $table) {
    

    It looks like you moved where these methods are in the class (probably an artifact of earlier versions of the patch), which makes the patch larger and harder to review. It took me a while to figure out what happened to all of this code. :-)

    I don't know that there's anything to do here, but I'm mentioning it in case a later reroll could be smaller/easier to read.

  2. +++ b/core/lib/Drupal/Core/Database/SchemaInterface.php
    @@ -0,0 +1,423 @@
    +interface SchemaInterface extends PlaceholderInterface {
    

    I'm not sure if the interface should extend, or if the class should just implement both. Open to thoughts here.

EclipseGc’s picture

Yeah, I mentioned that I moved a couple methods around to re-organize them in a fashion I felt was easier to read. I'm cool either way on the extend/implements for PlaceholderInterface, just need a decision one way or the other.

Eclipse

jhodgdon’s picture

Status: Needs review » Needs work

I took a look at the documentation changes in this patch. There are a few issues:

a) class DatabaseSchema

   /**
-   * The placeholder counter.
+   * @var \Drupal\Core\Database\Connection
    */
-  protected $placeholder = 0;
+  protected $connection;

A member variable needs to have a one-line description as well as @var. This patch replaces the description with @var instead of adding to the description.

b) DatabaseSchema::getPrefixInfo()

+   * @param string $table
+   *   Name of table to look prefix up for. Defaults to 'default' because that
+   *   is the default key for prefix.

This makes zero sense to me. It says it's the name of the table and then says something about keys and prefixes -- what does this mean? What is a prefix and what is a key? This also applies to several methods in SchemaInterface with 'prefix' in their names. As far as I can see, prefixes are never explained and I have no idea what it is from reading this documentation.

c)

+/**
+ * @see \Drupal\Core\Database\Query\PlaceholderInterface
+ */
+trait PlaceholderTrait {

A Trait still needs to have a one-line description of what it is for. @see just gives you a See Also, not documentation.

d) (minor) In the new SchemaInterface, the method docs should all start with 3rd-person verbs, like "Creates" instead of "Create". Some currently do, and some do not.

These are relatively minor and/or preexisting conditions except (a) and (c), which really needs to be fixed for sure (our Documentation Gate says that everything at least needs one-line documentation).

EclipseGc’s picture

Yeah, that connection var has no docs in HEAD currently, but I'll put a description on it. I did this much to make sure IDEs would parse through it properly. b.) is only visible because I physically relocated some of the existing docs, so yeah we should probably address that in a follow up, and c.) is something I knew I needed to do. Sorry I've not yet done it. I'll get a/c squared away as soon as Crell gives me an answer on #26.

Eclipse

EclipseGc’s picture

FileSize
41.06 KB

Discussed with Crell the PlaceholderInterface question he posed above. My basic question was "do you want to have to check the PlaceholderInterface for various SchemaInterface classes, to which he answered "no" and we decided SchemaInterface should indeed extend PlaceholderInterface.

This patch then only changes the documentation issues A & C that jhodgdon outlined in 27. Hopefully this takes this patch the rest of the way home.

Eclipse

EclipseGc’s picture

Status: Needs work » Needs review

missed the status...

Eclipse

Crell’s picture

Status: Needs review » Reviewed & tested by the community

I think any other missing documentation can/should be handled by #2192185: Improve DB API code documentation. Thanks, Kris!

msonnabaum’s picture

Looks much better to me.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Looks like we lack a change record draft for this. At least the "use" statement in implementing classes needs to change, not sure how much else of this is developer-facing.

EclipseGc’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Wrote the change record.

Eclipse

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Made a slight language tweak to the change notice. Back to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: 2206183-29.patch, failed testing.

EclipseGc’s picture

Status: Needs work » Needs review
FileSize
40.89 KB

rerolled

Eclipse

EclipseGc’s picture

FileSize
41.53 KB
662 bytes

added back in the docs changes that caused the original breakage of this patch in #29. If 37 passes 38 should pass.

Eclipse

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Bot can object.

The last submitted patch, 37: 2206183-37.patch, failed testing.

ianthomas_uk’s picture

The failure on #37 looks like the testbot just ran out of diskspace, so nothing to worry about for this issue.

EclipseGc’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 38: 2206183-38.patch, failed testing.

Crell’s picture

38: 2206183-38.patch queued for re-testing.

Crell’s picture

Status: Needs work » Reviewed & tested by the community
Related issues: +#2192185: Improve DB API code documentation

Testbot burped. Can we get this committed before it burps again?

EclipseGc’s picture

Seconding that request. The last re-roll was comment related.

Eclipse

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 38: 2206183-38.patch, failed testing.

EclipseGc’s picture

38: 2206183-38.patch queued for re-testing.

EclipseGc’s picture

Status: Needs work » Reviewed & tested by the community

dunno what's up with testbot, but this still passes test.

Eclipse

jibran’s picture

+++ b/core/lib/Drupal/Core/Database/SchemaInterface.php
@@ -0,0 +1,423 @@
+   * sequences (from serial-type fields) that use the changed field to be dropped.
...
+   *   New name for the field (set to the same as $field if you don't want to change the name).
...
+   * Return an array of field names from an array of key/index column specifiers.
...
+   * This is usually an identity function but if a key/index uses a column prefix

more then 80 chars.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 38: 2206183-38.patch, failed testing.

Rajendar Reddy’s picture

Status: Needs work » Needs review
FileSize
40.91 KB

Updating patch with reroll. Please review.

Status: Needs review » Needs work

The last submitted patch, 52: 2206183-52.patch, failed testing.

Crell’s picture

Issue tags: +Needs reroll
lokapujya’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
41.38 KB

Not sure this will work, but it should apply.

Status: Needs review » Needs work

The last submitted patch, 55: 2206183-55.patch, failed testing.

Crell’s picture

So if we reroll this again and make it work, when's a good time for it so that it doesn't sit here and get stale again? That's one of the most demoralizing things in the issue queue, especially for something that's just moving code around to make it cleaner...

jhedstrom’s picture

Is this still under consideration for 8.0.x?

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.