sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

`manager.has_constraint` for migrations

Open IgnisDa opened this issue 2 years ago • 3 comments

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 avatar Sep 05 '23 15:09 IgnisDa

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

tyt2y3 avatar Sep 08 '23 21:09 tyt2y3

Yep. I'll make the changes.

IgnisDa avatar Sep 08 '23 23:09 IgnisDa

@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.

IgnisDa avatar Sep 09 '23 13:09 IgnisDa