annotated icon indicating copy to clipboard operation
annotated copied to clipboard

Check constraintšŸ’”

Open peldax opened this issue 1 year ago • 3 comments

I have an idea!

Hi,

I would love to add a check constraint to my table using attributes.

I imagine the functionality as following, but it is just a draft.

#[Entity]
#[Index(columns: ['a'], unique: true)]
#[Check(expression: 'a > b')]
class EntityDef
{
    #[Column(type: 'integer')]
    private int $a;
    
    #[Column(type: 'integer')]
    private int $b;
}

I am open to bounty this feature.

peldax avatar Jun 20 '24 21:06 peldax

Hi.

The feature looks good, however we have the MySQL driver but we don't have separated MariaDB driver. If we want to add DBMS-specific feature then we have to add the driver. Then I suppose we need to add constraint field in the Schema Builder. And then we can implement the attribute.

I'm afraid I don't have enough time for this task. Would you like to do this?

roxblnfk avatar Jun 21 '24 06:06 roxblnfk

Hi,

Mysql driver will suffice, as the mariadb maintains major compatibility with mysql. However, I am not sure about some other rdbms and its support for the check constraint. I think we should throw a NotSupported exception in cases where the functionality is not available on the db level.

I can try to implement it, I but cannot guarantee any timeline as I dont have much spare time right now.

peldax avatar Jun 21 '24 06:06 peldax

NotSupported exception

We don't need to throw an exception there because the same schema might be used on different databases (tests: sqlite, prod: mysql). Just subscribe supported DBMS in the docblock of the attribute.

However, I am not sure about some other rdbms and its support for the check constraint

That issue might be useful even though it was 3 years ago.

but cannot guarantee any timeline

Don't worry about it šŸ‘Œ

roxblnfk avatar Jun 21 '24 06:06 roxblnfk