diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 7f11a2a05b..2851ebdf64 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -9,6 +9,7 @@ use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; +use Appwrite\Utopia\Database\Attribute; use Appwrite\Utopia\Database\Validator\Attributes as AttributesValidator; use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Database\Validator\Indexes as IndexesValidator; @@ -81,7 +82,7 @@ class Create extends Action ->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE)), 'An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('documentSecurity', false, new Boolean(true), 'Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is collection enabled? When set to \'disabled\', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.', true) - ->param('attributes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, integer, float, boolean, datetime), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true) + ->param('attributes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, varchar, text, mediumtext, longtext, integer, bigint, float, boolean, datetime, email, url, ip, enum), size (integer, required for string and varchar types), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true) ->param('indexes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).', true) ->inject('response') ->inject('dbForProject') @@ -279,13 +280,12 @@ class Create extends Action Document $collection, array $attribute, ): array { + ['type' => $type, 'format' => $format, 'size' => $size] = Attribute::resolve($attribute); + $key = $attribute['key']; - $type = $attribute['type']; - $size = $attribute['size'] ?? 0; $required = $attribute['required'] ?? false; $signed = $attribute['signed'] ?? true; $array = $attribute['array'] ?? false; - $format = $attribute['format'] ?? ''; $formatOptions = []; $filters = $attribute['filters'] ?? []; $default = $attribute['default'] ?? null; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Create.php index 16aabc877d..2623b7ac94 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Tables/Create.php @@ -64,7 +64,7 @@ class Create extends CollectionCreate ->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE)), 'An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is table enabled? When set to \'disabled\', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.', true) - ->param('columns', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of column definitions to create. Each column should contain: key (string), type (string: string, integer, float, boolean, datetime, relationship), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true) + ->param('columns', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of column definitions to create. Each column should contain: key (string), type (string: string, varchar, text, mediumtext, longtext, integer, bigint, float, boolean, datetime, email, url, ip, enum), size (integer, required for string and varchar types), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true) ->param('indexes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of column keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Utopia/Database/Attribute.php b/src/Appwrite/Utopia/Database/Attribute.php new file mode 100644 index 0000000000..b4dba3433c --- /dev/null +++ b/src/Appwrite/Utopia/Database/Attribute.php @@ -0,0 +1,100 @@ + + */ + public const SIZES = [ + Database::VAR_TEXT => 65535, + Database::VAR_MEDIUMTEXT => 16777215, + Database::VAR_LONGTEXT => 2147483647, + ]; + + /** + * String formats, mapped to the size their dedicated endpoint uses. Each + * format is also accepted as a shorthand type, mirroring the endpoints + * (`createEmailColumn` and friends) that create a string with that format. + * + * @var array + */ + public const FORMAT_SIZES = [ + APP_DATABASE_ATTRIBUTE_EMAIL => 254, + APP_DATABASE_ATTRIBUTE_ENUM => Database::LENGTH_KEY, + APP_DATABASE_ATTRIBUTE_IP => 39, + APP_DATABASE_ATTRIBUTE_URL => 2000, + ]; + + /** + * Types accepted in an inline definition, including the format shorthands. + * + * @return array + */ + public static function types(): array + { + return [ + Database::VAR_STRING, + Database::VAR_VARCHAR, + Database::VAR_TEXT, + Database::VAR_MEDIUMTEXT, + Database::VAR_LONGTEXT, + Database::VAR_INTEGER, + Database::VAR_BIGINT, + Database::VAR_FLOAT, + Database::VAR_BOOLEAN, + Database::VAR_DATETIME, + Database::VAR_POINT, + Database::VAR_LINESTRING, + Database::VAR_POLYGON, + ...\array_keys(self::FORMAT_SIZES), + ]; + } + + /** + * Resolve an inline definition into the type, format and size stored on the + * attribute document. A format shorthand becomes a string of that format, + * and a size is filled in from the type or format when the caller omits it. + * + * @param array $attribute + * @return array{type: string, format: string, size: int} + */ + public static function resolve(array $attribute): array + { + $type = $attribute['type'] ?? ''; + $format = $attribute['format'] ?? ''; + + if (isset(self::FORMAT_SIZES[$type])) { + $format = $type; + $type = Database::VAR_STRING; + } + + $size = $attribute['size'] ?? 0; + $size = \is_int($size) ? $size : 0; + + if (isset(self::SIZES[$type])) { + // Fixed width types ignore any size the caller sent. + $size = self::SIZES[$type]; + } elseif ($size < 1) { + $size = self::FORMAT_SIZES[$format] ?? $size; + } + + return [ + 'type' => $type, + 'format' => $format, + 'size' => $size, + ]; + } +} diff --git a/src/Appwrite/Utopia/Database/Validator/Attributes.php b/src/Appwrite/Utopia/Database/Validator/Attributes.php index 54aaf135f9..4eefb9ba2d 100644 --- a/src/Appwrite/Utopia/Database/Validator/Attributes.php +++ b/src/Appwrite/Utopia/Database/Validator/Attributes.php @@ -2,6 +2,7 @@ namespace Appwrite\Utopia\Database\Validator; +use Appwrite\Utopia\Database\Attribute; use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; @@ -17,21 +18,6 @@ class Attributes extends Validator protected int $maxAttributes; protected string $message = 'Invalid attributes'; - /** - * @var array Supported attribute types - */ - protected array $supportedTypes = [ - Database::VAR_STRING, - Database::VAR_INTEGER, - Database::VAR_BIGINT, - Database::VAR_FLOAT, - Database::VAR_BOOLEAN, - Database::VAR_DATETIME, - Database::VAR_POINT, - Database::VAR_LINESTRING, - Database::VAR_POLYGON, - ]; - /** * @var array Supported formats for string attributes */ @@ -92,6 +78,7 @@ class Attributes extends Validator } $keyValidator = new Key(); + $supportedTypes = Attribute::types(); $keys = []; foreach ($value as $index => $attribute) { @@ -132,34 +119,44 @@ class Attributes extends Validator } // Validate type - if (!\in_array($attribute['type'], $this->supportedTypes)) { + if (!\in_array($attribute['type'], $supportedTypes)) { $this->message = "Invalid type for attribute '" . $attribute['key'] . "': " . $attribute['type']; return false; } + // Resolve format shorthands and implicit sizes the same way the + // attribute document is built, so both agree on what was asked for. + ['type' => $type, 'format' => $format, 'size' => $size] = Attribute::resolve($attribute); + // Validate spatial type support - if (\in_array($attribute['type'], Database::SPATIAL_TYPES) && !$this->supportForSpatialAttributes) { + if (\in_array($type, Database::SPATIAL_TYPES) && !$this->supportForSpatialAttributes) { $this->message = "Spatial attributes are not supported by the current database"; return false; } - // Validate size for string types - if ($attribute['type'] === Database::VAR_STRING) { - if (!isset($attribute['size']) || !is_int($attribute['size']) || $attribute['size'] < 1 || $attribute['size'] > APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH) { + if (isset($attribute['size']) && !\is_int($attribute['size'])) { + $this->message = "Invalid size for attribute '" . $attribute['key'] . "': must be an integer"; + return false; + } + + // Validate size for the types that take one. The remaining string + // types (text, mediumtext, longtext) are fixed width. + if (\in_array($type, [Database::VAR_STRING, Database::VAR_VARCHAR])) { + if ($size < 1 || $size > APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH) { $this->message = "Invalid or missing size for string attribute '" . $attribute['key'] . "'. Size must be between 1 and " . APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH; return false; } } // Validate format if provided - if (isset($attribute['format']) && $attribute['format'] !== '') { - // Format is only allowed for string type - if ($attribute['type'] !== Database::VAR_STRING) { + if ($format !== '') { + // Format is only allowed for sized string types + if (!\in_array($type, [Database::VAR_STRING, Database::VAR_VARCHAR])) { $this->message = "Format is only allowed for string type for attribute '" . $attribute['key'] . "'"; return false; } - if (!in_array($attribute['format'], $this->supportedFormats)) { - $this->message = "Invalid format for attribute '" . $attribute['key'] . "': " . $attribute['format']; + if (!in_array($format, $this->supportedFormats)) { + $this->message = "Invalid format for attribute '" . $attribute['key'] . "': " . $format; return false; } } @@ -183,7 +180,7 @@ class Attributes extends Validator } // Validate signed only for integer/bigint/float types - if (isset($attribute['signed']) && !in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) { + if (isset($attribute['signed']) && !in_array($type, [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) { $this->message = "Attribute '" . $attribute['key'] . "': 'signed' can only be used with integer, bigint or float types"; return false; } @@ -202,7 +199,7 @@ class Attributes extends Validator // Validate min/max range for integer/bigint/float if (isset($attribute['min']) || isset($attribute['max'])) { - if (!in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) { + if (!in_array($type, [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) { $this->message = "Attribute '" . $attribute['key'] . "': min/max can only be used with integer, bigint or float types"; return false; } @@ -216,15 +213,18 @@ class Attributes extends Validator // Validate default value matches attribute type if (isset($attribute['default'])) { - switch ($attribute['type']) { + switch ($type) { case Database::VAR_STRING: + case Database::VAR_VARCHAR: + case Database::VAR_TEXT: + case Database::VAR_MEDIUMTEXT: + case Database::VAR_LONGTEXT: if (!is_string($attribute['default'])) { $this->message = "Default value for string attribute '" . $attribute['key'] . "' must be a string"; return false; } // Validate string size - $size = $attribute['size'] ?? 0; if ($size > 0) { $textValidator = new Text($size, 0); if (!$textValidator->isValid($attribute['default'])) { @@ -234,7 +234,6 @@ class Attributes extends Validator } // Validate format-specific defaults - $format = $attribute['format'] ?? ''; if ($format === APP_DATABASE_ATTRIBUTE_EMAIL) { $emailValidator = new Email(); if (!$emailValidator->isValid($attribute['default'])) { @@ -330,7 +329,7 @@ class Attributes extends Validator } // Validate enum elements if format is enum - if (isset($attribute['format']) && $attribute['format'] === APP_DATABASE_ATTRIBUTE_ENUM) { + if ($format === APP_DATABASE_ATTRIBUTE_ENUM) { if (!isset($attribute['elements']) || !is_array($attribute['elements']) || empty($attribute['elements'])) { $this->message = "Attribute '" . $attribute['key'] . "' with enum format must have 'elements' array"; return false; diff --git a/tests/e2e/Services/Databases/TablesDB/TablesDBColumnsTest.php b/tests/e2e/Services/Databases/TablesDB/TablesDBColumnsTest.php new file mode 100644 index 0000000000..6235a8bfcb --- /dev/null +++ b/tests/e2e/Services/Databases/TablesDB/TablesDBColumnsTest.php @@ -0,0 +1,144 @@ + 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', $headers, [ + 'databaseId' => ID::unique(), + 'name' => 'Inline Columns', + ]); + + $this->assertEquals(201, $database['headers']['status-code']); + $databaseId = $database['body']['$id']; + + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [ + 'tableId' => ID::unique(), + 'name' => 'Modules', + 'permissions' => [ + Permission::create(Role::any()), + Permission::read(Role::any()), + ], + 'columns' => [ + ['key' => 'title', 'type' => 'string', 'size' => 128, 'required' => true], + ['key' => 'slug', 'type' => 'varchar', 'size' => 64], + ['key' => 'modulePath', 'type' => 'text'], + ['key' => 'summary', 'type' => 'mediumtext'], + ['key' => 'archive', 'type' => 'longtext'], + ['key' => 'email', 'type' => 'email'], + ['key' => 'website', 'type' => 'url'], + ['key' => 'address', 'type' => 'ip'], + ['key' => 'status', 'type' => 'enum', 'elements' => ['on', 'off'], 'default' => 'on'], + ], + ]); + + $this->assertEquals(201, $table['headers']['status-code']); + $tableId = $table['body']['$id']; + + $columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns', $headers); + + $this->assertEquals(200, $columns['headers']['status-code']); + $this->assertEquals(9, $columns['body']['total']); + + $byKey = []; + foreach ($columns['body']['columns'] as $column) { + $this->assertEquals('available', $column['status']); + $byKey[$column['key']] = $column; + } + + // Sizes must match the dedicated per-column endpoints. The fixed width + // types do not expose a size, it is implied by the type. + $this->assertEquals('string', $byKey['title']['type']); + $this->assertEquals(128, $byKey['title']['size']); + $this->assertEquals('varchar', $byKey['slug']['type']); + $this->assertEquals(64, $byKey['slug']['size']); + $this->assertEquals('text', $byKey['modulePath']['type']); + $this->assertEquals('mediumtext', $byKey['summary']['type']); + $this->assertEquals('longtext', $byKey['archive']['type']); + + // Format shorthands become a string of that format + $this->assertEquals('string', $byKey['email']['type']); + $this->assertEquals('email', $byKey['email']['format']); + $this->assertEquals('string', $byKey['website']['type']); + $this->assertEquals('url', $byKey['website']['format']); + $this->assertEquals('string', $byKey['address']['type']); + $this->assertEquals('ip', $byKey['address']['format']); + $this->assertEquals('string', $byKey['status']['type']); + $this->assertEquals('enum', $byKey['status']['format']); + $this->assertEquals(['on', 'off'], $byKey['status']['elements']); + $this->assertEquals('on', $byKey['status']['default']); + + // Longer than any of the sized string types allow, so it only fits if + // the text column really got its 65535 default + $modulePath = \str_repeat('src/Appwrite/Platform/Modules/Databases/', 200); + + $row = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $headers, [ + 'rowId' => ID::unique(), + 'data' => [ + 'title' => 'Appwrite', + 'modulePath' => $modulePath, + 'email' => 'team@appwrite.io', + 'website' => 'https://appwrite.io', + 'address' => '127.0.0.1', + 'status' => 'off', + ], + ]); + + $this->assertEquals(201, $row['headers']['status-code']); + $this->assertEquals($modulePath, $row['body']['modulePath']); + $this->assertEquals('off', $row['body']['status']); + } + + public function testCreateTableUnsupportedColumnType(): void + { + $headers = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]; + + $database = $this->client->call(Client::METHOD_POST, '/tablesdb', $headers, [ + 'databaseId' => ID::unique(), + 'name' => 'Inline Columns Invalid', + ]); + + $this->assertEquals(201, $database['headers']['status-code']); + $databaseId = $database['body']['$id']; + + $table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [ + 'tableId' => ID::unique(), + 'name' => 'Invalid', + 'columns' => [ + ['key' => 'unknown', 'type' => 'blob'], + ], + ]); + + $this->assertEquals(400, $table['headers']['status-code']); + $this->assertStringContainsString("Invalid type for attribute 'unknown': blob", (string) $table['body']['message']); + } +} diff --git a/tests/unit/Utopia/Database/Validator/AttributesTest.php b/tests/unit/Utopia/Database/Validator/AttributesTest.php new file mode 100644 index 0000000000..6c02e5bbe7 --- /dev/null +++ b/tests/unit/Utopia/Database/Validator/AttributesTest.php @@ -0,0 +1,137 @@ +object = new Attributes(); + } + + public function testStringTypes(): void + { + $this->assertTrue($this->object->isValid([ + ['key' => 'title', 'type' => Database::VAR_STRING, 'size' => 128], + ['key' => 'slug', 'type' => Database::VAR_VARCHAR, 'size' => 128], + ['key' => 'body', 'type' => Database::VAR_TEXT], + ['key' => 'summary', 'type' => Database::VAR_MEDIUMTEXT], + ['key' => 'archive', 'type' => Database::VAR_LONGTEXT], + ]), $this->object->getDescription()); + } + + public function testStringTypeDefaults(): void + { + $this->assertTrue($this->object->isValid([ + ['key' => 'body', 'type' => Database::VAR_TEXT, 'default' => 'hello'], + ]), $this->object->getDescription()); + + $this->assertFalse($this->object->isValid([ + ['key' => 'body', 'type' => Database::VAR_TEXT, 'default' => 1], + ])); + + $this->assertFalse($this->object->isValid([ + ['key' => 'slug', 'type' => Database::VAR_VARCHAR, 'size' => 4, 'default' => 'toolong'], + ])); + } + + public function testVarcharRequiresSize(): void + { + $this->assertFalse($this->object->isValid([ + ['key' => 'slug', 'type' => Database::VAR_VARCHAR], + ])); + } + + public function testFormatTypes(): void + { + $this->assertTrue($this->object->isValid([ + ['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL, 'required' => true], + ['key' => 'website', 'type' => APP_DATABASE_ATTRIBUTE_URL], + ['key' => 'address', 'type' => APP_DATABASE_ATTRIBUTE_IP], + ['key' => 'status', 'type' => APP_DATABASE_ATTRIBUTE_ENUM, 'elements' => ['on', 'off'], 'default' => 'on'], + ]), $this->object->getDescription()); + + $this->assertFalse($this->object->isValid([ + ['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL, 'default' => 'not-an-email'], + ])); + + $this->assertFalse($this->object->isValid([ + ['key' => 'status', 'type' => APP_DATABASE_ATTRIBUTE_ENUM], + ])); + } + + public function testEmailWithoutSize(): void + { + $this->assertTrue($this->object->isValid([ + ['key' => 'email', 'type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_EMAIL], + ]), $this->object->getDescription()); + } + + public function testUnsupportedType(): void + { + $this->assertFalse($this->object->isValid([ + ['key' => 'rel', 'type' => Database::VAR_RELATIONSHIP], + ])); + $this->assertSame("Invalid type for attribute 'rel': relationship", $this->object->getDescription()); + } + + public function testResolveMatchesDedicatedEndpoints(): void + { + $this->assertEquals( + ['type' => Database::VAR_TEXT, 'format' => '', 'size' => 65535], + Attribute::resolve(['key' => 'body', 'type' => Database::VAR_TEXT]) + ); + + $this->assertEquals( + ['type' => Database::VAR_MEDIUMTEXT, 'format' => '', 'size' => 16777215], + Attribute::resolve(['key' => 'body', 'type' => Database::VAR_MEDIUMTEXT]) + ); + + $this->assertEquals( + ['type' => Database::VAR_LONGTEXT, 'format' => '', 'size' => 2147483647], + Attribute::resolve(['key' => 'body', 'type' => Database::VAR_LONGTEXT]) + ); + + $this->assertEquals( + ['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_EMAIL, 'size' => 254], + Attribute::resolve(['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL]) + ); + + $this->assertEquals( + ['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_IP, 'size' => 39], + Attribute::resolve(['key' => 'ip', 'type' => APP_DATABASE_ATTRIBUTE_IP]) + ); + + $this->assertEquals( + ['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_URL, 'size' => 2000], + Attribute::resolve(['key' => 'url', 'type' => APP_DATABASE_ATTRIBUTE_URL]) + ); + + $this->assertEquals( + ['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_ENUM, 'size' => Database::LENGTH_KEY], + Attribute::resolve(['key' => 'enum', 'type' => APP_DATABASE_ATTRIBUTE_ENUM]) + ); + } + + public function testResolveKeepsExplicitSize(): void + { + $this->assertEquals( + ['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_EMAIL, 'size' => 512], + Attribute::resolve(['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL, 'size' => 512]) + ); + + $this->assertEquals( + ['type' => Database::VAR_VARCHAR, 'format' => '', 'size' => 128], + Attribute::resolve(['key' => 'slug', 'type' => Database::VAR_VARCHAR, 'size' => 128]) + ); + } +}