JordanMarr / SqlHydra

SqlHydra is a suite of NuGet packages for working with databases in F# including code generation tools and query expressions.
MIT License
212 stars 20 forks source link

Generate types in GitHub workflow generates no table types #87

Closed stoft closed 3 months ago

stoft commented 3 months ago

I'm mostly in need of rubber ducking here and ideas on how to debug this I think and don't know where else to turn. šŸ™‚

I've added a GitHub workflow action that will auto-generate types and git diff them against the types in the PR with the goal of failing the build if there is a diff.

Problem: for some reason the generator is not generating the types for the tables, only the general types.

Environment:

Debugging and known so far:

Workflow steps:

      - name: Setup .NET Core
        uses: actions/setup-dotnet@v3
        with:
          global-json-file: global.json

      - name: Check generated DB types are up to date with the DB
        run: |
          dotnet tool restore

          ls -l src/Library/generated

          make generate-db-types

          ls -l src/Library/generated
          git diff --exit-code

I've added the ls -l just to show the size diff before and after. make generate-db-types is equal to dotnet sqlhydra npgsql --project ...

Output:

Tool 'fantomas' (version '6.2.3') was restored. Available commands: fantomas
Tool 'sqlhydra.cli' (version '2.3.3') was restored. Available commands: sqlhydra

Restore was successful.
total 16
-rw-r--r-- 1 runner docker 14442 Mar 14 15:49 DatabaseTypes.fs
dotnet sqlhydra npgsql --project src/Library/Library.fsproj
- SqlHydra.Npgsql
- v2.3.3.0
- '/home/runner/work/myproject/myproject/src/Library/generated/DatabaseTypes.fs' has
been generated!
total 8
-rw-r--r-- 1 runner docker 6546 Mar 14 15:50 DatabaseTypes.fs
diff --git a/src/Library/generated/DatabaseTypes.fs b/src/Library/generated/DatabaseTypes.fs
index 4dab217..eb75328 100644
--- a/src/Library/generated/DatabaseTypes.fs
+++ b/src/Library/generated/DatabaseTypes.fs
@@ -31,136 +31,6 @@ module private DataReaderExtensions =
             reader.GetFieldValue(ordinal) |> System.TimeOnly.FromTimeSpan

-module myschema = ...

Here we can see the size has more than halved and the diff is in reality about 200 lines removed.

Thanks for a great tool! Any ideas on how to debug this would be greatly appreciated. ā¤ļø

JordanMarr commented 3 months ago

Interesting! It's neat to see what kinds of things other people are doing with it.

Just a thought: is it possible that your GitHub Workflow Action is using a database where you haven't applied migration scripts yet? That's the only reason I can think that there would be no application tables.

Next thought: Are you using more than one .toml config file? (I'm wondering if you might have table filters specified in one config but not another). If so, there is an option to specify which .toml file is used.

setting the wrong password in the toml causes SqlHydra.Cli to throw an error

That sounds like the expected behavior.

stoft commented 3 months ago

Thank you @JordanMarr ! As it turns out the migrations, and our integration tests, were running correctly but in an unexpected schema (public instead of our specific schema). All good now! It's a shared code base with TS and F#, now we can get a heads up during the build that a migration on the TS side may have broken something on the F# side.

An improvement in SqlHydra could be to warn when an include filter has zero hits. This would imply that something is not as expected or no longer needed. Feel free to close this issue unless you want to convert it to a feature request. šŸ˜„

JordanMarr commented 3 months ago

That's pretty cool. Are you using Fable to generate your TS types?

stoft commented 3 months ago

Are you using Fable to generate your TS types?

No, it's a service completely written in TS that we're now adding F# code to. We have other services in F# and want to gently start moving away from TS.

I'm closing this issue now as resolved. Thank you so much for the help!

Resolved by https://github.com/JordanMarr/SqlHydra/issues/87#issuecomment-1999889588

JordanMarr commented 3 months ago

Thanks. i may add a message if all records are filtered out.