Skip to content

Support referring foreign keys from other schemas#58

Open
Bouallegui-Moudhaffer wants to merge 2 commits intokraken-tech:mainfrom
Bouallegui-Moudhaffer:feature/cross-schema-referring-fks
Open

Support referring foreign keys from other schemas#58
Bouallegui-Moudhaffer wants to merge 2 commits intokraken-tech:mainfrom
Bouallegui-Moudhaffer:feature/cross-schema-referring-fks

Conversation

@Bouallegui-Moudhaffer
Copy link
Copy Markdown

Summary

This PR adds support for repacking tables that have referring foreign keys from other schemas.

Psycopack already tracked referring FK schema metadata, but it still rejected cross-schema referring FKs in pre_validate() and assumed FK-related DDL would always run against self.schema. This PR removes that limitation and makes FK handling schema-aware throughout the repack lifecycle.

Changes

  • remove the cross-schema referring FK rejection in pre_validate()
  • make FK constraint DDL schema-aware
  • fix get_referring_fks() to resolve referred tables against the correct schema and check ownership against the actual referring table schema
  • update reset / cleanup / stale-copy cleanup paths to operate on the real referring table schema
  • make cleanup FK restoration more robust by matching replacement FKs via deterministic temp names
  • preserve FK validation state during cleanup/retry flows

Tests

  • add regression coverage for referring FKs from another schema
  • cover both DIRECT_TRIGGER and CHANGE_LOG
  • keep existing reentrant / idempotent behavior green

Validation

Ran locally:

  • pytest tests/test_repack.py
  • ruff check .
  • mypy .

All passed.

@Bouallegui-Moudhaffer Bouallegui-Moudhaffer requested a review from a team as a code owner April 4, 2026 23:37
@marcelofern
Copy link
Copy Markdown
Collaborator

Hi @Bouallegui-Moudhaffer, thanks for your contribution. I will have a look at when I'm available next week.
In the meanwhile, could I ask you what has been your use case for psycopack?

@Bouallegui-Moudhaffer
Copy link
Copy Markdown
Author

Bouallegui-Moudhaffer commented Apr 10, 2026

Hi @Bouallegui-Moudhaffer, thanks for your contribution. I will have a look at when I'm available next week. In the meanwhile, could I ask you what has been your use case for psycopack?

Thanks for the note @marcelofern.

I’m genuinely interested in Kraken and potentially joining in the future, so I wanted to get more familiar with the tech you’re building. I’ve been going through Kraken Tech and OctoEnergy’s public repositories, especially around data engineering topics.

As I was reviewing this repo, I spotted an area where I felt I could contribute something useful, so I took the opportunity to work on it.

Thanks again for the feedback, I really appreciate it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants