madmatt / silverstripe-encrypt-at-rest

Encrypt data at rest in your database
7 stars 11 forks source link

Building the MySQL database: Int fields are not allowed to have a default value #12

Open Taitava opened 7 years ago

Taitava commented 7 years ago

This is just a quick post about an SQL error I just encountered when trying to run /dev/build.

[User Error] Uncaught SS_DatabaseException: Couldn't run query: ALTER TABLE "EncryptionTestObject" ADD "IntEnc" mediumtext character set utf8 collate utf8_general_ci default '0' 42000-1101: BLOB, TEXT, GEOMETRY or JSON column 'IntEnc' can't have a default value

My PHP code:

class EncryptionTestObject extends DataObject
{
    private static $db = array(
        'IntEnc' => 'EncryptedInt',
    );
}

Got it working when I made a small change to the array in the EncryptedInt::requireField() method:

public function requireField()
    {
        $values = array(
            'type'  => 'text',
            'parts' => array(
                'datatype'   => 'text',
//                'precision'  => $this->service->calculateRequiredFieldSize(strlen('Y-m-d H:i:s')),
                'null'       => 'not null',
                'default'    => $this->defaultVal /* CHANGE THIS TO NULL */,
                'arrayValue' => $this->arrayValue
            )
        );

        DB::require_field($this->tableName, $this->name, $values);
    }

Should I create a pull request about this?

Firesphere commented 7 years ago

Yes please, sorry for the delayed reply. The precision for EncryptedInt shouldn't be needed anyway.

Taitava commented 7 years ago

No problem :). I'll create a PR about this at some point :).

Taitava commented 3 years ago

I just noticed some activity on this module and saw this old issue of mine. Well, it appears that the "PR at some point" newer happened, sorry :).

As I'm not anymore working on a project where I used this module, I think I'll just drop this out of my todo list :). If anyone else needs a fix for this, they are free to create a pull request, this seems to be a quite easy thing, just needs testing that it works because it's been many years.