Skip to content
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

Introspection migration adds ON UPDATE CASCADE ON DELETE SET NULL to foreign key constraints #6999

Closed
lastmjs opened this issue May 9, 2021 · 3 comments

Comments

@lastmjs
Copy link

lastmjs commented May 9, 2021

Bug description

This is all using postgres by the way, postgres 12.3. I am trying to use prisma migrate in an existing app that we are refactoring away from Rails. I have run introspection and generated an initial migration. Everything seems to be working very well. But, just to make sure that the introspected initial migration matched my old Rails migrations, I ran pg_dump --schema-only on the database with the Rails migrations, and the database with just the initial introspected prisma migration. There were a few differences with data types, but the biggest difference was that the foreign key constraints in prisma had ON UPDATE CASCADE ON DELETE SET NULL added to them. These were not present in the Rails schema dump file.

How to reproduce

Difficult to reproduce, but you could create a Rails project, create a simple schema, and migrate using Active record. Make sure to include at least one foreign key constraint. use pg_dump --schema-only after migrating the database. Run prisma introspect on the database after running the Rails migrations.

After that, completely wipe the database and start over. Use prisma migrate deploy to recreate the database from the previously generated introspection initial migration. Now run pg_dump --schema-only again.

If you run a diff on those files, you should see that ON UPDATE CASCADE ON DELETE SET NULL has been added to foreign key constraints...unexpected.

Expected behavior

I do not expect ON UPDATE CASCADE ON DELETE SET NULL to be added to foreign key constraints, if they are not already present. Introspection should create a migration that is identical to the current postgres schema.

Prisma information

Here's an example from the Rails pg_dump: ALTER TABLE ONLY public.voicemails ADD CONSTRAINT fk_rails_fa0980bd48 FOREIGN KEY (contact_id) REFERENCES public.contacts(id);

Here's the same info after instrospection, wiping the database, and deploying the migration: ALTER TABLE ONLY public.voicemails ADD CONSTRAINT voicemails_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id) ON UPDATE CASCADE ON DELETE SET NULL;

Environment & setup

  • OS: Ubuntu 16
  • Database: Postgres 12.3
  • Node.js version: 12.13.1
  • Prisma version: 2.22.1

@lastmjs lastmjs added the kind/bug A reported bug. label May 9, 2021
@janpio janpio added topic: introspection bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. team/schema Issue for team Schema. topic: migrate topic: cascade labels May 10, 2021
@tomhoule tomhoule added kind/feature A request for a new feature. and removed kind/bug A reported bug. bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels May 12, 2021
@tomhoule
Copy link
Contributor

tomhoule commented May 12, 2021

Hi @lastmjs — this is something we are working on at the moment. There is an issue open for feedback on the current proposal: #6996 — your input there would be very appreciated :)

@pimeys
Copy link
Contributor

pimeys commented Jun 22, 2021

Fixed in prisma/prisma-engines#1947
Please read the proposal in #6996

Instructions on how to use this, and a place to give feedback: #7816

@pimeys pimeys closed this as completed Jun 22, 2021
@Jolg42 Jolg42 added this to the 2.26.0 milestone Jun 28, 2021
@janpio
Copy link
Member

janpio commented Jun 29, 2021

This has now been released as a preview feature flag. You can read about it in the release notes for 2.26.0: https://github.com/prisma/prisma/releases/tag/2.26.0 If you have any feedback, please use this issue: #7816

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants