Comments (9)
#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.
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:
from migrondi.
FYI, I just pushed v0.200.1 with the Kata.ToQuery
helpers.
from migrondi.
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.
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.
from migrondi.
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.
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.
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.
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)
- Experiment: Allow F# Scripts HOT 10
- 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
- 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
- Failing to apply migrations doesn't fail a build HOT 5
- Add Colored Output
- Validate new migration names HOT 5
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.