Skip to content

Code First F# SQL DDL and migration generation from F# types? (maybe another related project) #843

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

Open
jkone27 opened this issue Apr 16, 2025 · 2 comments

Comments

@jkone27
Copy link

jkone27 commented Apr 16, 2025

Would be great to allow a form of code-first DDL generation also for this provider,

so that common EF-core code-first operation could be completely replaced by this provider within a script for DB generation, eventually such scripts could be versioned, etc...

maybe it could reuse efcore types for this purpose?

something like

type MyOther {
      Id: Guid
      Name: string
}

type MyRecord = {
      Id: long
      Name: string
      PublicIdentifier: Guid
      Others: MyOther list // should identify implicitly or explicitly such relations a bit like efcore does
}

let migration =  ctx.migrationWith "dbo.MigrationTableName" (createIfNotExist = true) // or maybe also default this value if not provided by 

migration 
|> createSchema "test"
|> create<MyRecord>
|> withPrimaryKey _.Id
|> withUnique (_.Name, _.PublicIdentifier)
|> runAsync
|> Async.RunSynchronously
@Thorium
Copy link
Member

Thorium commented Apr 16, 2025

I recommend using the SSDT for database schema generation and versioning. That works very well as you can have different SSDT schemas in different git branches if needed, and use them from SQLProvider.

I have no idea if Postgres has similar tools as well (the internet says https://metacpan.org/pod/sqitchtutorial ), and I think we could add support for something like that (as just another new provider implementation in SQLProvider). I'm not sure if non-forward code-first migrations ever pay-off. It's a nice idea on paper, but in real life trying to return to the past seems to be harder than in theory.

For F# domain:

  • Part of the idea of type-providers is that they are compiler plugins and not code-generators. So there will be no all the maintenance issues that the code-generator provides, for example a) impedance mismatch between abstraction layers, b) updating F# version, c) generation infrastructure problems, d) string-parsing e) picking accidentally the non-favourite or not-well-maintained tool for ast (of tools like e.g. Quotations/Fantomas/Fabulous.Ast/Myriad/...) d) someone modifying generated code preventing re-generation, e) and so on.
  • This type-provider is erasing type-provider. It will compile the types away. So the domain-structure you see, the "ORM" part, even when felts like EF-user-experince to the developer, is compiled away by the compiler. At runtime, it's all just very lightweight dictionaries, not mapping layers and layers of objects. Totally different experience of the lovely EF debugging.

@jkone27
Copy link
Author

jkone27 commented Apr 17, 2025

interesting points thanks😊

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

No branches or pull requests

2 participants