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

feat: Support schemas with non-deferred FKs. #1100

Merged
merged 2 commits into from
May 30, 2024

Conversation

stephenh
Copy link
Collaborator

@stephenh stephenh commented May 26, 2024

Todo:

  • Add a `nonDeferredForeignKeys: ignore | warn | error"
    • Warn is the default, creates a SQL file
    • Error just stops, current behavior
    • Ignore, will use fixups
  • Detect not-null cycles, error out
    • Make them deferred (if postgres)
    • Make one nullable (any db, can fixup)

Fixes #1097

@stephenh stephenh force-pushed the feat-support-non-deferred-fks branch 19 times, most recently from 74ff45e to 0e21cf4 Compare May 29, 2024 14:51
@stephenh stephenh force-pushed the feat-support-non-deferred-fks branch from 0e21cf4 to ce215c6 Compare May 29, 2024 15:20
Copy link
Collaborator

@zgavin zgavin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i've grokked this, good to open up support for more setups.

Why would you not have deferred FKs though 🤔

@@ -33,7 +33,7 @@ export class AuthorCodegen {
// ...all the boilerplate fields & m2o/o2m/m2m relations generated for you...
readonly books: Collection<Author, Book> = hasOne(...);
get firstName(): string { ... }
set firstName(): string { ... }
set firstName(value: string): string { ... }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱


await writeAlterTables(nonDeferredFks);

if (setting === "error") hasError ??= true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just hasError = true?

.filter((m2o) => m2o.notNull)
.forEach((m2o) => {
const added = addDependency(graph, entity, m2o);
if (Array.isArray(added)) notNullCylces.push(added.join(" -> "));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spelling "Cylces"

@stephenh
Copy link
Collaborator Author

Why would you not have deferred FKs though

@zgavin totally agreed; my hope is that users will use the alter-foreign-keys.sql to convert over, my assumption is just that anyone not using Joist today a) probably doesn't even know deferred FKs are a thing / b) does not have them enabled for every FK in their system.

So just want to lower the bar/entry point, at least for PG setups.

@stephenh stephenh marked this pull request as ready for review May 29, 2024 21:08
@stephenh stephenh merged commit 3577c18 into main May 30, 2024
6 checks passed
github-actions bot pushed a commit that referenced this pull request May 30, 2024
* feat: Support schemas with non-deferred FKs.

* PR feedback. 3577c18
stephenh pushed a commit that referenced this pull request May 30, 2024
# [1.169.0](v1.168.2...v1.169.0) (2024-05-30)

### Features

* Support schemas with non-deferred FKs. ([#1100](#1100)) ([3577c18](3577c18))
@stephenh
Copy link
Collaborator Author

🎉 This PR is included in version 1.169.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Support schemas that don't use deferred FKs
2 participants