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

Migrate fresh not deleting postgres type

Open MaderNoob opened this issue 2 years ago • 6 comments

Description

If the migration creates postgres types, running sea-orm-cli migrate fresh will fail because it doesn't delete types, and it will say that the type already exists.

Steps to Reproduce

  1. Create a migration which creates a postgres type.
  2. Run the migration sea-orm-cli migrate up
  3. Try to run a fresh migration sea-orm-cli migrate fresh

Expected Behavior

The fresh migration should work

Actual Behavior

The fresh migration returns an error saying that the enum type already exists.

Reproduces How Often

always

Versions

│ └── sea-orm v0.8.0 │ ├── sea-orm-macros v0.8.0 (proc-macro) │ ├── sea-query v0.24.6 │ │ ├── sea-query-derive v0.2.0 (proc-macro) │ │ ├── sea-query-driver v0.1.1 (proc-macro) │ ├── sea-strum v0.23.0 │ │ └── sea-strum_macros v0.23.0 (proc-macro) │ ├── sea-orm-migration v0.8.2 │ │ ├── sea-orm v0.8.0 () │ │ ├── sea-orm-cli v0.8.1 │ │ │ ├── sea-schema v0.8.0 │ │ │ │ ├── sea-query v0.24.6 () │ │ │ │ └── sea-schema-derive v0.1.0 (proc-macro) │ │ ├── sea-schema v0.8.0 () ├── sea-orm v0.8.0 () ├── sea-orm-rocket v0.5.0 │ └── sea-orm-rocket-codegen v0.5.0 (proc-macro)

uname -a Linux arch 5.17.5-arch1-1 #1 SMP PREEMPT Wed, 27 Apr 2022 20:56:11 +0000 x86_64 GNU/Linux

pacman -Q postgresql postgresql 14.2-1

Additional Information

Types should be first deleted when running a fresh migration.

MaderNoob avatar May 25 '22 14:05 MaderNoob

Hey @MaderNoob, sorry for the delay. As discussed on Discord, we could delete all PostgreSQL types in current schema when calling fresh on migrator.

  • https://github.com/SeaQL/sea-orm/blob/9983e5d4987149ad227ccf402e4cf2618a1dddc3/sea-orm-migration/src/migrator.rs#L130-L212

It would be a two steps process:

  1. Select all type names out of PostgreSQL
  2. Construct delete type statement and execute it

billy1624 avatar Jul 06 '22 09:07 billy1624

I'll open this issue for anyone who have interested in contributing :)

billy1624 avatar Jul 06 '22 09:07 billy1624

@billy1624 can you assign me with this issue?

karpa4o4 avatar Jul 08 '22 11:07 karpa4o4

@karpa4o4 done!

ikrivosheev avatar Jul 08 '22 11:07 ikrivosheev

@ikrivosheev thanks

karpa4o4 avatar Jul 08 '22 11:07 karpa4o4

Thanks for the interest! @karpa4o4

billy1624 avatar Jul 08 '22 13:07 billy1624