yesodweb / yesodweb/persistent

Possible problem with migrations and cascade behavior

Open
#1,216 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

using persistent-postgresql, a foreign key reference may not be acting correctly in the presence of CASCADE behavior

setup notes:

  1. create table foo (id serial primary key, name text)
  2. create table bar (id serial primary key, foo_id integer references foo(id) on delete cascade)

Then with a model file like:

Foo
  name String

Bar
  fooId FooId  

This will assume a default ON UPDATE RESTRICT ON DELETE RESTRICT, and will issue a migration. This migration should alter the constraint, not add one. I'm seeing a create statement locally.

Modifying the fooId field to be fooId FooId OnDelete Cascade is not dismissing that migration.

need to reproduce smaller.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the migration with persistent-postgresql using the Foo and Bar schemas and the existing CASCADE foreign key described in the issue. Inspect the generated migration and the handling of OnDelete Cascade; done means it alters the existing constraint rather than issuing a create statement, and the migration is dismissed after the model matches the database.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.