sea-orm
sea-orm copied to clipboard
Migration fresh command cannot drop types with Postgresql
Description
Steps to Reproduce
- Write a migration that enables
citexton postgresql:
CREATE EXTENSION IF NOT EXISTS citext;
- Apply the migration on a clean postgresql db
- Run the command migration command
freshto clean the databasecargo run -- fresh - The command returns an error:
...
Dropping all types
Dropping type 'citext'
Execution Error: error returned from database: cannot drop type citext because extension citext requires it
Expected Behavior
The fresh command executes without error. Either it deletes the extension or it only deletes types that can be deleted or it continues without an error
Actual Behavior
Command runs with an error
See: https://github.com/SeaQL/sea-orm/blob/master/sea-orm-migration/src/migrator.rs#L330-L342
Reproduces How Often
Always
Workarounds
- Don't use
citextextension - Avoid using the
freshcommand and use other commands likerefreshand write my own down script to drop thecitextextension before hand
Reproducible Example
- Start a postgresql database
- Execute manually:
CREATE EXTENSION IF NOT EXISTS citext; - Run the command
sea-orm-cli migrate fresh
Versions
sea-orm = "0.12"
postgresql = 16
Same. Should drop extensions before dropping types.
I got the same issue with the vector extension, I found a workaround :
In the down function :
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let tx = manager.get_connection().begin().await?;
tx.execute(sea_orm::Statement::from_string(
manager.get_database_backend(),
"DROP EXTENSION vector CASCADE",
))
.await?;
tx.commit().await?;
// my other stuff
Ok(())
}
And then I use sea-orm-cli migrate refresh, I did not manage to make it work with sea-orm-cli migrate fresh.