Skip to content

Commit

Permalink
Attribute usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
egbuk committed Jan 10, 2025
1 parent 5e07206 commit 77bf67f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ doctrine_postgres_enum:
```
For defining new enum type, [use native PHP enums](https://www.php.net/manual/language.types.enumerations.php):
```php
use HeyMoon\DoctrinePostgresEnum\Attribute\EnumType;

#[EnumType('auth_status')]
enum AuthStatus: string
{
case New = 'new';
Expand All @@ -28,6 +31,7 @@ enum AuthStatus: string
case Deleted = 'deleted';
}

#[EnumType('auth_service')]
enum Service: string
{
case Google = 'google';
Expand All @@ -53,11 +57,11 @@ class Auth
```
Create migrations via `make:migration`. If enum was created or modified, the `CREATE TYPE`/`ALTER TYPE` calls would be added to migration. Example:
```php
$this->addSql('DROP TYPE IF EXISTS app_entity_type_authstatus');
$this->addSql('CREATE TYPE app_entity_type_authstatus AS ENUM (\'new\',\'active\',\'inactive\',\'deleted\')');
$this->addSql('DROP TYPE IF EXISTS app_entity_type_service');
$this->addSql('CREATE TYPE app_entity_type_service AS ENUM (\'google\')');
$this->addSql('CREATE TABLE auth (id UUID NOT NULL, status app_entity_type_authstatus NOT NULL, service app_entity_type_service NOT NULL, PRIMARY KEY(id))');
$this->addSql('DROP TYPE IF EXISTS auth_status');
$this->addSql('CREATE TYPE auth_status AS ENUM (\'new\',\'active\',\'inactive\',\'deleted\')');
$this->addSql('DROP TYPE IF EXISTS auth_service');
$this->addSql('CREATE TYPE auth_service AS ENUM (\'google\')');
$this->addSql('CREATE TABLE auth (id UUID NOT NULL, status auth_status NOT NULL, service auth_service NOT NULL, PRIMARY KEY(id))');
$this->addSql('COMMENT ON COLUMN auth.status IS \'(DC2Enum:App\\Entity\\Type\\AuthStatus)\'');
$this->addSql('COMMENT ON COLUMN auth.service IS \'(DC2Enum:App\\Entity\\Type\\Service)\'');
```

0 comments on commit 77bf67f

Please sign in to comment.