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

Check constraint💡 #99

Open
peldax opened this issue Jun 20, 2024 · 3 comments
Open

Check constraint💡 #99

peldax opened this issue Jun 20, 2024 · 3 comments
Assignees
Labels
type:feature New feature.

Comments

@peldax
Copy link

peldax commented Jun 20, 2024

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 peldax added the type:feature New feature. label Jun 20, 2024
@roxblnfk
Copy link
Member

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?

@peldax
Copy link
Author

peldax commented Jun 21, 2024

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.

@roxblnfk
Copy link
Member

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 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature.
Projects
Status: No status
Development

No branches or pull requests

2 participants