Skip to content

Commit 5b59f52

Browse files
committed
Specify data types of roles columns
The data type is based on the length you configure for the entity fields. At least, that's the case for `object`, `array` and custom types. By default a LONGTEXT is used to store that table data. When running a MySQL like dbms in strict mode, that quickly becomes a problem as LONGTEXT fields can contain many bytes of data. Adding the new MDUI field was not permitted as the maximum table size restraint wat triggered (IIRC). To solve this issue, and to optimize the roles table. We decided to review the data types for the text/object based fields. And set them to a value that more realistically reflect their size. As a result the following changes were made: |**name**|**type**|**new length**| |---|----|---| |`certificates`|`array`|65535 (text)| |`contact_persons`|`array`|65535 (text)| |`name_id_formats`|`array`|65535 (text)| |`single_sign_on_services`|`array`|65535 (text)| |`shib_md_scopes`|`array`|65535 (text)| |`attribute_release_policy`|`array`|65535 (text)| |`assertion_consumer_services`|`array`|65535 (text)| |`allowed_idp_entity_ids`|`array`|16777215 (mediumtext)| |`requested_attributes`|`array`|65535 (text)| |`organization_nl_name`|`object`|65535 (text)| |`organization_en_name`|`object`|65535 (text)| |`organization_pt_name`|`object`|65535 (text)| |`consent_settings`|`json_array`|16777215 (mediumtext)| |`consent_settings`|`object`|16777215 (text)| |`mdui`|`engineblock_metadata_mdui`|65535 (text)| Note that the logo field is not updated as it is marked for removal in the next release. See: https://www.pivotaltracker.com/n/projects/1425900/stories/185861244
1 parent 436b701 commit 5b59f52

File tree

6 files changed

+96
-15
lines changed

6 files changed

+96
-15
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace OpenConext\EngineBlock\Doctrine\Migrations;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
use Doctrine\Migrations\AbstractMigration;
7+
8+
final class Version20230824090020 extends AbstractMigration
9+
{
10+
public function up(Schema $schema) : void
11+
{
12+
// this up() migration is auto-generated, please modify it to your needs
13+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
14+
$this->addSql('
15+
ALTER TABLE sso_provider_roles_eb5
16+
CHANGE organization_nl_name organization_nl_name TEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
17+
CHANGE organization_en_name organization_en_name TEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
18+
CHANGE organization_pt_name organization_pt_name TEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
19+
CHANGE name_id_format name_id_format VARCHAR(255) DEFAULT NULL,
20+
CHANGE single_logout_service single_logout_service TEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
21+
CHANGE attribute_release_policy attribute_release_policy TEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
22+
CHANGE assertion_consumer_services assertion_consumer_services TEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
23+
CHANGE allowed_idp_entity_ids allowed_idp_entity_ids MEDIUMTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
24+
CHANGE requested_attributes requested_attributes TEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
25+
CHANGE support_url_en support_url_en VARCHAR(255) DEFAULT NULL,
26+
CHANGE support_url_nl support_url_nl VARCHAR(255) DEFAULT NULL,
27+
CHANGE support_url_pt support_url_pt VARCHAR(255) DEFAULT NULL,
28+
CHANGE single_sign_on_services single_sign_on_services TEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
29+
CHANGE consent_settings consent_settings MEDIUMTEXT DEFAULT NULL COMMENT \'(DC2Type:json_array)\',
30+
CHANGE shib_md_scopes shib_md_scopes TEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
31+
CHANGE mdui mdui TEXT NOT NULL COMMENT \'(DC2Type:array)\',
32+
CHANGE coins coins TEXT NOT NULL COMMENT \'(DC2Type:array)\',
33+
CHANGE name_id_formats name_id_formats TEXT NOT NULL COMMENT \'(DC2Type:array)\',
34+
CHANGE contact_persons contact_persons TEXT NOT NULL COMMENT \'(DC2Type:array)\',
35+
CHANGE certificates certificates TEXT NOT NULL COMMENT \'(DC2Type:array)\',
36+
CHANGE manipulation manipulation TEXT NOT NULL COMMENT \'(DC2Type:array)\'
37+
');
38+
}
39+
40+
public function down(Schema $schema) : void
41+
{
42+
// this down() migration is auto-generated, please modify it to your needs
43+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
44+
45+
$this->addSql('
46+
ALTER TABLE sso_provider_roles_eb5
47+
CHANGE organization_nl_name organization_nl_name LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
48+
CHANGE organization_en_name organization_en_name LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
49+
CHANGE organization_pt_name organization_pt_name LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
50+
CHANGE name_id_format name_id_format VARCHAR(255) DEFAULT NULL,
51+
CHANGE single_logout_service single_logout_service LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:object)\',
52+
CHANGE attribute_release_policy attribute_release_policy LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
53+
CHANGE assertion_consumer_services assertion_consumer_services LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
54+
CHANGE allowed_idp_entity_ids allowed_idp_entity_ids LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
55+
CHANGE requested_attributes requested_attributes LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
56+
CHANGE support_url_en support_url_en VARCHAR(255) DEFAULT NULL,
57+
CHANGE support_url_nl support_url_nl VARCHAR(255) DEFAULT NULL,
58+
CHANGE support_url_pt support_url_pt VARCHAR(255) DEFAULT NULL,
59+
CHANGE single_sign_on_services single_sign_on_services LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
60+
CHANGE consent_settings consent_settings LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json_array)\',
61+
CHANGE shib_md_scopes shib_md_scopes LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\',
62+
CHANGE mdui mdui LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\',
63+
CHANGE coins coins LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\',
64+
CHANGE name_id_formats name_id_formats LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\',
65+
CHANGE contact_persons contact_persons LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\',
66+
CHANGE certificates certificates LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\',
67+
CHANGE manipulation manipulation LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\'
68+
');
69+
}
70+
}

src/OpenConext/EngineBlock/Metadata/Entity/AbstractRole.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,21 @@ abstract class AbstractRole
162162
/**
163163
* @var Organization
164164
*
165-
* @ORM\Column(name="organization_nl_name",type="object", nullable=true)
165+
* @ORM\Column(name="organization_nl_name",type="object", nullable=true, length=65535)
166166
*/
167167
public $organizationNl;
168168

169169
/**
170170
* @var Organization
171171
*
172-
* @ORM\Column(name="organization_en_name",type="object", nullable=true)
172+
* @ORM\Column(name="organization_en_name",type="object", nullable=true, length=65535)
173173
*/
174174
public $organizationEn;
175175

176176
/**
177177
* @var Organization
178178
*
179-
* @ORM\Column(name="organization_pt_name",type="object", nullable=true)
179+
* @ORM\Column(name="organization_pt_name",type="object", nullable=true, length=65535)
180180
*/
181181
public $organizationPt;
182182

@@ -204,7 +204,7 @@ abstract class AbstractRole
204204
/**
205205
* @var X509Certificate[]
206206
*
207-
* @ORM\Column(name="certificates", type="array")
207+
* @ORM\Column(name="certificates", type="array", length=65535)
208208
*/
209209
public $certificates = array();
210210

@@ -218,7 +218,7 @@ abstract class AbstractRole
218218
/**
219219
* @var ContactPerson[]
220220
*
221-
* @ORM\Column(name="contact_persons", type="array")
221+
* @ORM\Column(name="contact_persons", type="array", length=65535)
222222
*/
223223
public $contactPersons;
224224

@@ -232,14 +232,14 @@ abstract class AbstractRole
232232
/**
233233
* @var string[]
234234
*
235-
* @ORM\Column(name="name_id_formats", type="array")
235+
* @ORM\Column(name="name_id_formats", type="array", length=65535)
236236
*/
237237
public $supportedNameIdFormats;
238238

239239
/**
240240
* @var Service
241241
*
242-
* @ORM\Column(name="single_logout_service", type="object", nullable=true)
242+
* @ORM\Column(name="single_logout_service", type="object", nullable=true, length=65535)
243243
*/
244244
public $singleLogoutService;
245245

@@ -253,7 +253,7 @@ abstract class AbstractRole
253253
/**
254254
* @var string
255255
*
256-
* @ORM\Column(name="manipulation", type="text")
256+
* @ORM\Column(name="manipulation", type="text", length=65535)
257257
*/
258258
public $manipulation;
259259

src/OpenConext/EngineBlock/Metadata/Entity/IdentityProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ class IdentityProvider extends AbstractRole
6969
/**
7070
* @var Service[]
7171
*
72-
* @ORM\Column(name="single_sign_on_services", type="array")
72+
* @ORM\Column(name="single_sign_on_services", type="array", length=65535)
7373
*/
7474
public $singleSignOnServices = array();
7575

7676
/**
7777
* @var ConsentSettings
7878
*
79-
* @ORM\Column(name="consent_settings", type="json_array")
79+
* @ORM\Column(name="consent_settings", type="json_array", length=16777215)
8080
*/
8181
private $consentSettings;
8282

8383
/**
8484
* @var ShibMdScope[]
8585
*
86-
* @ORM\Column(name="shib_md_scopes", type="array")
86+
* @ORM\Column(name="shib_md_scopes", type="array", length=65535)
8787
*/
8888
public $shibMdScopes = array();
8989

src/OpenConext/EngineBlock/Metadata/Entity/ServiceProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ class ServiceProvider extends AbstractRole
4848
/**
4949
* @var null|AttributeReleasePolicy
5050
*
51-
* @ORM\Column(name="attribute_release_policy", type="array")
51+
* @ORM\Column(name="attribute_release_policy", type="array", length=65535)
5252
*/
5353
public $attributeReleasePolicy;
5454

5555
/**
5656
* @var IndexedService[]
5757
*
58-
* @ORM\Column(name="assertion_consumer_services", type="array")
58+
* @ORM\Column(name="assertion_consumer_services", type="array", length=65535)
5959
*/
6060
public $assertionConsumerServices;
6161

6262
/**
6363
* @var string[]
6464
*
65-
* @ORM\Column(name="allowed_idp_entity_ids", type="array")
65+
* @ORM\Column(name="allowed_idp_entity_ids", type="array", length=6777215)
6666
*/
6767
public $allowedIdpEntityIds;
6868

@@ -76,7 +76,7 @@ class ServiceProvider extends AbstractRole
7676
/**
7777
* @var null|RequestedAttribute[]
7878
*
79-
* @ORM\Column(name="requested_attributes", type="array")
79+
* @ORM\Column(name="requested_attributes", type="array", length=65535)
8080
*/
8181
public $requestedAttributes;
8282

src/OpenConext/EngineBlockBundle/Doctrine/Type/MetadataCoinType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class MetadataCoinType extends Type
3030

3131
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
3232
{
33+
// We want a `TEXT` field declaration in our column, the `LONGTEXT` default causes issues when running the
34+
// DBMS in strict mode.
35+
$fieldDeclaration['length'] = 65535;
3336
return $platform->getJsonTypeDeclarationSQL($fieldDeclaration);
3437
}
3538

@@ -52,6 +55,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
5255
return $value->toJson();
5356
}
5457

58+
public function getMappedDatabaseTypes(AbstractPlatform $platform)
59+
{
60+
return parent::getMappedDatabaseTypes($platform); // TODO: Change the autogenerated stub
61+
}
62+
5563
public function convertToPHPValue($value, AbstractPlatform $platform)
5664
{
5765
if (is_null($value)) {

src/OpenConext/EngineBlockBundle/Doctrine/Type/MetadataMduiType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class MetadataMduiType extends Type
3030

3131
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
3232
{
33+
// We want a `TEXT` field declaration in our column, the `LONGTEXT` default causes issues when running the
34+
// DBMS in strict mode.
35+
$fieldDeclaration['length'] = 65535;
3336
return $platform->getJsonTypeDeclarationSQL($fieldDeclaration);
3437
}
3538

0 commit comments

Comments
 (0)