Giter Club home page Giter Club logo

Comments (9)

AngelMunoz avatar AngelMunoz commented on August 27, 2024 1

#28 has been merged and it includesthe facilities to use migrondi as a library, I will try to get a sample of a prototype using @JordanMarr 's SqlHydra.Query to re-take the fsx scripts it will also help me test the public API and see if it's actually usable

from migrondi.

JordanMarr avatar JordanMarr commented on August 27, 2024 1

On second thought, I just noticed that my naive toEmbeddedSql fn would need to do a lot more work to properly embed different data types in a db provider agnostic way: strings need to be wrapped with single or double quotes depending on provider, etc.
Browsing through the SqlKata issues repo, I don't see any built-in functionality to do this.

So I think your original idea of just getting a list of SqlKata.Query objects would be the best. You can easily convert a SqlKata.Query object into command on your side.

Here's the updated version with some sample inserts included:

image

from migrondi.

JordanMarr avatar JordanMarr commented on August 27, 2024 1

FYI, I just pushed v0.200.1 with the Kata.ToQuery helpers.

from migrondi.

AngelMunoz avatar AngelMunoz commented on August 27, 2024 1

I'm about to start with this actually, I think for the moment I just want to be sure I can pull .fsx scripts just like I used to do on the old branch, I'll get the queries and build a command to execute them, very very close to what you have there, I'm not sure if the Kata.ToQuery is needed yet, but I do appreciate the effort!
we could actually use that to create an "eject" kind of thing where you can emit all of the migrations in standard SQL (or even transform them between languages) and use the default migrondi mechanisms

from migrondi.

JordanMarr avatar JordanMarr commented on August 27, 2024

Since the various query builders (select, insert, update and delete) all have different return types, I am in the process of adding a helper to transform a builder specific query spec to a SqlKata.Query, and another helper to turn a SqlKata.Query into an embedded SQL string. I think this would give you the flexibility you need for creating a clean list of migrations.

This is what I have so far.

image

from migrondi.

AngelMunoz avatar AngelMunoz commented on August 27, 2024

Yeah looks like the last one might do the trick, I'm also wary that this is going to run inside a fsx script so not sure how that will turn out specially if you have "#r" usings at the top performance might not be that great

from migrondi.

JordanMarr avatar JordanMarr commented on August 27, 2024

Since migrations would probably be run as part of a CI build, I can't imagine that a few seconds here or there would be that big of deal. Or do you think it would be longer than that?

But if performance is a concern, you could create a separate Migrondi package that would allow running it as its own executable.

Pros:

  • it would be easy to add a migration fsproj with migration "scripts-as-code"
  • this package could share some of the existing code used by your dotnet tool
    Cons:
  • would be a separate package to create

For some of my projects I use a FAKE build .fsx, but recently I have begun skipping using the FAKE dotnet tool and have instead been creating a FAKE build console .fsproj. For some reason this seems easier to me because I can just pull it into my project via NuGet as opposed to mucking around with the dotnet command line tools.

from migrondi.

JordanMarr avatar JordanMarr commented on August 27, 2024

More thoughts on creating a list of migrations-as-code...
I can imagine you creating a series of "adapter" functions that transform the various inputs to some sort of a MigrationScript spec.
For example:

    let seedErrorsTable: SqlKata.Query list = 
        [ 
            for record in sampleErrors do
                insert {
                    into table<dbo.ErrorLog>
                    entity record
                }
                |> Kata.ToQuery 
            
            update {
                for e in table<dbo.ErrorLog> do
                set e.ErrorMessage "Unauthorized"
                where (e.ErrorNumber = 401)
            }
            |> Kata.ToQuery

            update {
                for e in table<dbo.ErrorLog> do
                set e.ErrorMessage "Resource Not Found"
                where (e.ErrorNumber = 404)
            }
            |> Kata.ToQuery
        ]

    let doSomethingCmd = 
        new Microsoft.Data.SqlClient.SqlCommand("UPDATE...")

    let migration = 
        [
            yield! seedErrorsTable |> List.map Script.ofSqlKataQuery
            yield! IO.DirectoryInfo("./migrations/") |> Script.ofMigrationFolder
            IO.FileInfo("./scripts/do_stuff.sql") |> Script.ofSqlFile
            doSomethingCmd |> Script.ofCommand
        ]

from migrondi.

JordanMarr avatar JordanMarr commented on August 27, 2024

TBH, I have used SSDT for my last few big projects with no migration, so I don't have enough experience using migrations to know if my suggestions make sense. So whatever you think is best, I defer to your judgement!

from migrondi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.