Open stephaniesyed opened 10 months ago
Alternatively, it could be worth investigating the scope of using Drizzle's built in migration generation for the postgres adapter (there could be more edge cases they already handle gracefully)
We are simply relying on drizzle-kit
and how it generates these migrations. I was hopeful that our recent version upgrade might improve this.
Since the DROP TABLE
s comes straight from Drizzle, I don't know that this is going to be handled by Payload.
I do think it is okay to use the generated migrations as a first pass and modify according to your own needs.
What do you think?
Hi Dan, sorry for the confusion. On a previous bug ticket, something I would have expected to be handled by Drizzle (since they do provide migration support) was implemented by payload instead, so I wasn't sure what was Drizzle and what was Payload.
You're right, to mitigate the issue we can modify the file after it is generated, so this isn't a blocking/high priority bug. However, I do think it is still a bug since I expect modifying foreign keys to be a basic SQL migration pattern. I am also biased in this regard as I have used other ORMs for different languages that had fewer issues, and because of that I haven't had to write a manual migration in a while 😅
From my perspective, Payload provides postgres support, so bugs in that functionality are bugs in Payload, even if the root cause is in a dependency. I also think that Drizzle might be more inclined to address bugs reported by other companies using their code rather than individuals. They have a bit of a backlog at the moment so a ticket coming from Payload (and therefore affecting all payload postgres users) might have a bit more weight, especially since Payload is listed as a gold sponsor on their ORM repo's readme.
However, I know the Payload team is small and postgres support isn't part of the monetized product. If the team isn't able to support reporting bugs to dependencies I can submit bugs in migration file generation directly to Drizzle instead.
@stephaniesyed I appreciate the understanding here!
We will keep this issue open while we monitor the Drizzle issue. That gives the best visibility for anyone looking for the problem: https://github.com/drizzle-team/drizzle-orm/issues/1144
Working on resolving this issue on the Drizzle side
@AndriiSherman Great! Let us know if you need us to test anything :)
Link to reproduction
No response
Describe the Bug
When adding a new table, the
down
function doesn't drop any foreign key constraints.For example, this migration file:
Can migrate fine, but throws an error when trying to run
migrate:down
Terminal output:I can manually edit the
down
function to either cascade on table drop or to drop constraints first before trying to drop the tables. This could be generalized to 1) adding fk drops and 2) ordering thedown
function in the opposite order of theup
function .While adding
cascade
would work in this case, I think more edge cases would be covered if thedown
sql statements were the opposite of the migration statements in reverse order (since the current migration file does table creation then foreign key creation).Alternatively, it could be worth investigating the scope of using Drizzle's built in migration generation for the postgres adapter (there could be more edge cases they already handle gracefully)
To Reproduce
migrate:create 'inital_migration'
that creates a table with foreign keys (the payload metadata does this, so shouldn't be necessary to create models with relationships)migrate
migrate:down
(see the terminal output below for the error output)In the terminal output below, I actually used migrate:fresh since my local db was in a bad state.
The only model defined was
User
, as shown below (simplified for this example):Payload Version
2.4.0
Adapters and Plugins
none