Skip to content

Commit

Permalink
SchemaGenerator: added new custom types for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Jun 12, 2024
1 parent f906177 commit 8ea499b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/custom-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ Prepared custom types for MySQL:
- `md5` - `CHAR(32)`
- `money` - `DECIMAL(15, 4)`
- `DateInterval` - `TIME`
- PHPDoc types
- `positive-int` - `UNSIGNED INT`
- `negative-int` - `INT`
- `non-positive-int` - `INT`
- `non-negative-int` - `UNSIGNED INT`
- `non-zero-int` - `INT`
- `lowercase-string` - `TEXT`
- `literal-string` - `TEXT`
- `class-string` - `TEXT`
- `interface-string` - `TEXT`
- `trait-string` - `TEXT`
- `enum-string` - `TEXT`
- `callable-string` - `TEXT`
- `array-key` - `TEXT`
- `numeric-string` - `TEXT`
- `non-empty-string` - `TEXT`
- `non-empty-lowercase-string` - `TEXT`
- `truthy-string` - `TEXT`
- `non-falsy-string` - `TEXT`
- `non-empty-literal-string` - `TEXT`
- [`inteve/types`](https://github.com/inteve/types)
- `Inteve\Types\HexColor` - `CHAR(6)`
- `Inteve\Types\Html` - `MEDIUMTEXT`
Expand Down
21 changes: 21 additions & 0 deletions src/SchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,27 @@ private function prepareDefaults($databaseType)
'CHARACTER SET' => 'utf8mb4',
'COLLATE' => 'utf8mb4_czech_ci',
];

$this->setCustomType('positive-int', 'INT', [], [SqlSchema\Column::OPTION_UNSIGNED]);
$this->setCustomType('negative-int', 'INT');
$this->setCustomType('non-positive-int', 'INT');
$this->setCustomType('non-negative-int', 'INT', [], [SqlSchema\Column::OPTION_UNSIGNED]);
$this->setCustomType('non-zero-int', 'INT');
$this->setCustomType('lowercase-string', 'TEXT');
$this->setCustomType('literal-string', 'TEXT');
$this->setCustomType('class-string', 'TEXT');
$this->setCustomType('interface-string', 'TEXT');
$this->setCustomType('trait-string', 'TEXT');
$this->setCustomType('enum-string', 'TEXT');
$this->setCustomType('callable-string', 'TEXT');
$this->setCustomType('array-key', 'TEXT');
$this->setCustomType('numeric-string', 'TEXT');
$this->setCustomType('non-empty-string', 'TEXT');
$this->setCustomType('non-empty-lowercase-string', 'TEXT');
$this->setCustomType('truthy-string', 'TEXT');
$this->setCustomType('non-falsy-string', 'TEXT');
$this->setCustomType('non-empty-literal-string', 'TEXT');

$this->setCustomType('bcrypt', 'CHAR', [60]);
$this->setCustomType('md5', 'CHAR', [32]);
$this->setCustomType('money', 'DECIMAL', [15, 4]);
Expand Down

0 comments on commit 8ea499b

Please sign in to comment.