sea-orm
sea-orm copied to clipboard
`manager.has_constraint` for migrations
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.
For sure. I guess we can work on SeaSchema first, just like the last time?
Yep. I'll make the changes.
@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.