Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
moroswitie opened this issue Jan 6, 2024 · 1 comment
Open
Assignees

Comments

@moroswitie
Copy link

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",
@roxblnfk roxblnfk added this to Cycle Jan 6, 2024
@roxblnfk roxblnfk moved this to Todo in Cycle Jan 6, 2024
@roxblnfk
Copy link
Member

roxblnfk commented Jan 6, 2024

I think it makes sense.
@msmakouz could you research and fix that behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

3 participants