Comments (10)
This is interesting because we have a lot of code snippets for applying and reverting changes in an idempotent fashion for SQL Server. Being able to bring that to Migrondi as an F# script or something would be awesome, especially with interpolated strings now.
from migrondi.
Almost every change script I write modifies at least 2 objects that have a dependency relationship, say a table and a stored procedure. So, I think the whole script must be run as a transaction.
from migrondi.
NOTE: This would be an alternative way to do migrations, the SQL migrations would still be the default unless specified otherwise
from migrondi.
cool! thanks for the input @brettrowberry I'll try to come up with something over the next week
from migrondi.
Of course, we could just have an F# script whose job is to generate SQL and Migrondi just runs the SQL.
from migrondi.
there are a couple of interesting approaches here, one could also have a program that sends a json serializable array with the SQL migrations to stdout read it from something like https://github.com/Tyrrrz/CliWrap
but I think the approach above is fairly simpler since you only need to have an F# list with up/down commands at the end of your script, scripts can be versioned with a timestamp as well
one thing that comes to my mind is that if there are multiple SQL statements that come from a script should each be in its own transaction? or should all of the statements be part of a single transaction
from migrondi.
I've been playing with this but it seems to work once then it stops working
it might be a bug within the F# compiler services or something that I'm doing wrong but I'll keep experimenting on this
namespace Migrondi
open System
open System.IO
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.Interactive.Shell
open Types
module ScriptedContent =
let getContentFromScripts (file: FileInfo): string * string =
let defConfig =
FsiEvaluationSession.GetDefaultConfiguration()
let argv =
[| "dotnet"
"fsi"
"--noninteractive"
"--nologo"
"--gui-" |]
use stdin = new StreamReader(Stream.Null)
use stdout = new StringWriter()
use stderr = new StringWriter()
use script = file.OpenText()
let session =
FsiEvaluationSession.Create(defConfig, argv, stdin, stdout, stderr)
let interaction =
session.EvalInteractionNonThrowing(script.ReadToEnd())
match interaction with
| Choice2Of2 ex, error -> raise (ex)
| Choice1Of2 None, error -> failwith $"Unsuported type %A{error}"
| Choice1Of2 (Some value), error ->
match value.ReflectionValue with
| :? (list<list<string>>) as migrations ->
let up =
(List.tryHead migrations |> Option.defaultValue [])
|> List.reduce (fun next curr -> $"{next}\n{curr}")
let down =
(List.tryLast migrations |> Option.defaultValue [])
|> List.reduce (fun next curr -> $"{next}\n{curr}")
$"\n{up}", $"\n{down}"
| _ -> failwith $"Unsuported type %A{value.ReflectionType}"
from migrondi.
ok ok fixed that I was doing some concurrent stuff without knowing it
dir.EnumerateFiles()
|> Seq.filter (fun f -> f.Extension = ".sql" || f.Extension = ".fsx")
|> Seq.toArray
|> Array.parallel.map fileMapping // <- this calls the fsi stuff fails if it's doing it parallel
|> Array.sortBy (fun m -> m.timestamp)
dir.EnumerateFiles()
|> Seq.filter (fun f -> f.Extension = ".sql" || f.Extension = ".fsx")
|> Seq.toArray
|> Array.map fileMapping // <- fix is to remove the parallel map
|> Array.sortBy (fun m -> m.timestamp)
from migrondi.
Sorry I'm so late to this discussion! This looks pretty cool! If I understand correctly, it'd give us a kind of an EF-like way to writing the up/down scripts rather than plain scripts. It'd also give us full fsharp compiler support so I wouldn't struggle with forgotten semicolons again 😂
I like what you did with mondocks there, it looks great! I also agree with @brettrowberry that the whole thing should be run as a transaction.
This does look like the next big thing for Migrondi!
from migrondi.
after months of thinking it, I don't think this is something we'd like to pursue I think it would be easier to expose the F# mechanisms as a library and use it from F# rather than evaluate F# scripts ourselves I might still look into alternatives
from migrondi.
Related Issues (20)
- Failing to apply migrations doesn't fail a build HOT 5
- Add Colored Output
- Validate new migration names HOT 5
- Which migrations will up and down commands run? HOT 8
- Dry Run HOT 1
- Connection String Secret HOT 2
- Migrondi: command not found HOT 7
- Accepted file pattern for the commands new and up differs HOT 5
- MariaDB is not working HOT 3
- [CI]: Run Integration Tests in GH Actions
- New options to support migrondi-vscode
- Adjust options for the List command
- Migration File Status
- Address code inconsistenciescistencies
- Expose Migrondi as a library HOT 9
- Running the migrondi command immediately kills the migrondi process HOT 7
- Roadmap HOT 1
- Running the migrondi up command second time output error message and nothing else happens HOT 2
- Docker guidance HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from migrondi.