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

Subsequent migrations fail with type 'JsonDocument' is not defined error for JSONB column #160

Open
nodakai opened this issue Nov 6, 2023 · 3 comments

Comments

@nodakai
Copy link

nodakai commented Nov 6, 2023

Describe the bug

To Reproduce

type Tab = {
  Id: int
  Js: JsonDocument
}
ef migrations add First
ef database update  # works
ef migrations add Second

migrations/20231103200659_Second.fs(502,24): error FS0039: The type 'JsonDocument' is not defined.

which is from this line

            b.Property<JsonDocument>("Js")
                .IsRequired(true)
                .HasColumnType("jsonb")
                |> ignore

without open System.Text.Json

(Additionally, to avoid potential conflicts with user-defined types, wouldn't it be safer for machine-generated files to always use fully qualified type names, prefixed with global, given that one might create an entity named Int?)

Additional context

% dotnet list package
Project 'My.Postgres.Lib' has the following package references
   [net7.0]: 
   Top-level Package                               Requested   Resolved
   > EntityFrameworkCore.FSharp                    6.0.7       6.0.7   
   > FSharp.Core                                   7.0.400     7.0.400 
   > FSharpPlus                                    1.5.0       1.5.0   
   > Microsoft.EntityFrameworkCore.Design          6.0.23      6.0.23  
   > Microsoft.EntityFrameworkCore.Relational      6.0.23      6.0.23  
   > Npgsql.EntityFrameworkCore.PostgreSQL         6.0.22      6.0.22  

Logs above have been extracted from our proprietary codebase and edited to omit certain confidential details, are not from a minimal, self-contained repro

@nodakai
Copy link
Author

nodakai commented Nov 16, 2023

Just noticed I can add Workaround.fs before migration codes:

namespace Microsoft.EntityFrameworkCore

type JsonDocument = System.Text.Json.JsonDocument

"Poor man's global using", so to speak.

But I'm facing another problem now (was it there from the beginning?) The bug I reported above was about timestamped migrations codes but this time it's *Snapshot.fs that is malformed, it starts with

open System
open System.Text.Json
open 

Yes, an empty open statement. No way to circumvent this syntax error with namespace and alias tricks.

@simon-reynolds
Copy link
Collaborator

Hi, I'll take a look at this when I can but this is a bit of a one man show at the moment and I have limited time

Snapshot being generated with an empty open statement is new, I haven't encountered that issue before.

What version of EF Core are you working with?

@nodakai
Copy link
Author

nodakai commented Nov 16, 2023

Thank you very much @simon-reynolds

I've opened a new issue, as the empty open issue appears to be distinct from the absence of open System.Text.Json

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

No branches or pull requests

2 participants