Silverstripe-framework: Test Databases is not equal to Build database.

Created on 22 May 2018  路  10Comments  路  Source: silverstripe/silverstripe-framework

Affected Version

phpunit/phpunit            5.7.27             The PHP Unit Testing framework.
silverstripe-themes/simple dev-master 4d546a4 The SilverStripe simple theme (defau...
silverstripe/recipe-cms    1.1.0              SilverStripe recipe for fully featur...
silverstripe/recipe-plugin 1.2.0              Helper plugin to install SilverStrip...

MySQL 5.7 with PDO connector.

Description

Generating a test database gives a different schema than the generated build database.

Steps to Reproduce

  1. Create a model with a column that contains a backtick on it.
  2. Generate your database with sake dev/build
  3. Generate a test database with:
use SilverStripe\ORM\Connect\TempDatabase;

$test = new TempDatabase();
$test->build();

Compare the two tables, the column with the backtick should be missing from the test database.

affectv4 feedback-requireauthor

Most helpful comment

  • First: thanks for taking the time to test this.馃憤馃徑
  • Second: Some how now I am unable to replicate it馃槖. But I guess that is good news!

All 10 comments

Does this only happen when using a backtick in a column name?

Indexes are working correctly for me, so seems like it only happens with columns.

I just want to clarify here. When you write Create a model with a column that contains a backtick on it, do you mean creating a DB field with a _backtick_ character in the name? For example, something like this.

<?php
use SilverStripe\ORM\DataObject;
class Dummy extends DataObject {
    private static $db = [
        '`Moola' => 'Varchar'
    ];
}

Yes, like that. I should have given a more complete example.

Yeah, don't do that.

I'm going to close this; putting a backtick in the column name is just asking for trouble. alphanumeric only, please.

Well, I am not saying that backticks should be allowed on the names.

I just wanted to point out that the databases are generated differently, and (IMO) that should not happen.

The process of generating the Test DB and the Production DB should output the same exact result.

If the Test DB is not replicating the Production database, can I really trust it?

I can't replicate this:

MariaDB [(none)]> use ss_tmpdb_1531495473_8867054
Database changed
MariaDB [ss_tmpdb_1531495473_8867054]> describe Page;
+------------------------+--------------+------+-----+---------+----------------+
| Field                  | Type         | Null | Key | Default | Extra          |
+------------------------+--------------+------+-----+---------+----------------+
| ID                     | int(11)      | NO   | PRI | NULL    | auto_increment |
| `What is wrong with me | varchar(255) | YES  |     | NULL    |                |
+------------------------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> use vagrant
Database changed
MariaDB [vagrant]> DESCRIBE Page;
+------------------------+--------------+------+-----+---------+----------------+
| Field                  | Type         | Null | Key | Default | Extra          |
+------------------------+--------------+------+-----+---------+----------------+
| ID                     | int(11)      | NO   | PRI | NULL    | auto_increment |
| `What is wrong with me | varchar(255) | YES  |     | NULL    |                |
+------------------------+--------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

Couldn't replicate it either when I built my Dummy example.

  • First: thanks for taking the time to test this.馃憤馃徑
  • Second: Some how now I am unable to replicate it馃槖. But I guess that is good news!
Was this page helpful?
0 / 5 - 0 ratings