-
-
Notifications
You must be signed in to change notification settings - Fork 520
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_index
for migrations
#1827
Comments
For reference, here are the queries: -- SQLITE
SELECT EXISTS (
SELECT 1
FROM sqlite_master
WHERE type = 'index'
AND name = 'metadata_identifier__index'
AND tbl_name = 'metadata'
) AS index_exists;
-- POSTGRES
SELECT EXISTS (
SELECT 1
FROM pg_indexes
WHERE schemaname = 'public'
AND tablename = 'metadata'
AND indexname = 'metadata_identifier__index'
) AS index_exists;
-- MYSQL
SELECT EXISTS (
SELECT 1
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'your_database_name'
AND TABLE_NAME = 'metadata'
AND INDEX_NAME = 'metadata_identifier__index'
) AS index_exists; |
Sure. Such a feature would be welcomed. The relevant code should go into SeaSchema and then wrapped in SeaORM. |
@tyt2y3 Thanks for the hint. For Postgres and MySQL(?) do I need to schema into account or do I assume that we are working with the EDIT: NVM figured it out. |
This was referenced Aug 26, 2023
@tyt2y3 Made the PRs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
The
SchemaManager
has convenience methods likehas_table
andhas_column
while writing migrations. I propose ahas_index
method.Proposed Solutions
It will return
true
if an index exists for a given table.Current Workarounds
Execute the query manually.
If accepted I would like to make a PR.
The text was updated successfully, but these errors were encountered: