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

manager.has_constraint for migrations #1839

Open
IgnisDa opened this issue Sep 5, 2023 · 3 comments
Open

manager.has_constraint for migrations #1839

IgnisDa opened this issue Sep 5, 2023 · 3 comments

Comments

@IgnisDa
Copy link
Contributor

IgnisDa commented Sep 5, 2023

Motivation

The SchemaManager has convenience methods like has_table and has_column while writing migrations. I propose a has_constraint method.

Proposed Solutions

It will return true if an constraint exists for a given table.

Current Workarounds

Execute the query manually.

If accepted I would like to make a PR.

@IgnisDa IgnisDa changed the title manager.has_index for migrations manager.has_constraint for migrations Sep 5, 2023
@tyt2y3
Copy link
Member

tyt2y3 commented Sep 8, 2023

For sure. I guess we can work on SeaSchema first, just like the last time?

@IgnisDa
Copy link
Contributor Author

IgnisDa commented Sep 8, 2023

Yep. I'll make the changes.

@IgnisDa
Copy link
Contributor Author

IgnisDa commented Sep 9, 2023

@tyt2y3 It seems like foreign keys created for sqlite by sea orm are unnamed. So this method should panic for sqlite?

EDIT:

If you don't explicitly name a foreign key constraint, SQLite will generate a name for it automatically. The automatically generated name will be in the form sqlite_autoindex_tablename_N, where tablename is the name of the table the foreign key belongs to, and N is a number that makes the name unique within the database.

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

No branches or pull requests

2 participants