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

Don't automatically apply defer_foreign_keys in TableStatements.insertAll #3393

Open
wild-coffee opened this issue Dec 28, 2024 · 3 comments
Labels
breaking A breaking change that would require a major version jump

Comments

@wild-coffee
Copy link

Describe the bug

when postgresql, use insertAll raised exception: "pragma synax error"

the genarate sql:
pragma defer_foreign_keys = on;

in batch is useful!

error:

  await AppDatabase.instance.screw
      .insertAll(listData!.map((e) => ScrewCompanion.insert(
            name: e.name,
            remark: Value(e.remark),
            displayName: Value(e.displayName),
          )));

success:

  await AppDatabase.instance.batch((b) {
    b.insertAll(
        AppDatabase.instance.screw,
        listData!.map((e) => ScrewCompanion.insert(
              name: e.name,
              remark: Value(e.remark),
              displayName: Value(e.displayName),
            )));
  });
@simolus3
Copy link
Owner

Thanks for the feedback! I don't think we should apply that pragma behind the scenes, it adds an implicit dependency on the dialect used (and since not all database systems support an equivalent option, necessarily leads to platform-specific behavior).

Changing this now is breaking though, so I'll fix the method by only applying that pragma to SQLite databases (2e40917). In the next major drift release, we can remove it entirely. I'll repurpose this issue to remind me of that change.

@simolus3 simolus3 added the breaking A breaking change that would require a major version jump label Dec 28, 2024
@simolus3 simolus3 changed the title With Postgresql, insertAll failed Don't automatically apply defer_foreign_keys in TableStatements.insertAll Dec 28, 2024
@wild-coffee
Copy link
Author

Thanks!
I'm looking forward to the release of your new version.

Thanks for the feedback! I don't think we should apply that pragma behind the scenes, it adds an implicit dependency on the dialect used (and since not all database systems support an equivalent option, necessarily leads to platform-specific behavior).

Changing this now is breaking though, so I'll fix the method by only applying that pragma to SQLite databases (2e40917). In the next major drift release, we can remove it entirely. I'll repurpose this issue to remind me of that change.

@simolus3
Copy link
Owner

simolus3 commented Jan 6, 2025

The first fix described in my last comment is part of drift: ^2.23.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A breaking change that would require a major version jump
Projects
None yet
Development

No branches or pull requests

2 participants