Skip to content

Schema compile does not adhere to default database value of null #70

Description

@moroswitie

Description

When compiling a schema, the default database value as configured within the database manager will be used inside of the schema instead of null.

Example with annotated entity:

use Cycle\Annotated\Annotation\Entity;

#[Entity(role: AccountType::class, repository: AccountTypeRepository::class, table: 'account_type')]
class AccountType
{
    #[Column(type: 'tinyInteger', name: 'account_type_id', primary: true, nullable: true)]
    protected ?int $accountTypeId = null;
    // ...
}    

In the above example the "database" entity option is not set, so I expect the schema to have a null value for SchemaInterface::DATABASE instead it uses the default value as configured on the database manager (in my example that would be test).

Schema snippit:

namespace Cycle\ORM\SchemaInterface;

class CompiledSchema
{
    public const LIST = [
        AccountType::class => [
            // ...
            SchemaInterface::MAPPER => 'Cycle\ORM\Mapper\Mapper',
            SchemaInterface::SOURCE => 'Cycle\ORM\Select\Source',
            SchemaInterface::REPOSITORY => AccountTypeRepository::class,
            SchemaInterface::DATABASE => 'test', // <================ should be null not test
            
            // ...
        ],
    ];
}

If I compile the schema during my build step which uses a different database name compared to production I end up with the following error, on production.

Cycle\Database\Exception\DBALException: Unable to create Database, no presets for 'build_2024_abfertgg_db' found

I can resolve this by setting the database to null after the schema has been compiled. But I feel like this is not the expected behavior.
Explicitly setting the entity option "database" to null does not change the outcome.

Versions used:

    "cycle/annotated": "^3.4",
    "cycle/database": "^2.7",
    "cycle/orm": "^2.6",

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions