Skip to content

Commit

Permalink
fixed regexp, removed step limit, display progress
Browse files Browse the repository at this point in the history
  • Loading branch information
lamg committed Dec 13, 2023
1 parent 0496338 commit 5734edb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cli/Cli.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>0.0.7</Version>
<Version>0.0.8</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PackAsTool>true</PackAsTool>
Expand Down
24 changes: 13 additions & 11 deletions Lib/Execution/Commit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ open SqlParser.Types
open Migrate.SqlGeneration
open NuGet.Versioning

[<Literal>]
let stepsLimit = 20

let replicateInDb (schema: SqlFile) (dbFile: string) =

let tables = schema.tables |> List.map Table.sqlCreateTable
Expand Down Expand Up @@ -70,24 +67,29 @@ let migrateStep (p: Project) : ProposalResult list option =
Print.printRed $"got error\n{e.Message}"
None

let printProgress (n: int) =
let prog = [| "/"; "-"; "\\"; "|" |]
let i = n % prog.Length
printf $"\r{prog[i]}"

let migrateDb (p: Project) =
let mutable stop = false
let mutable steps = ResizeArray<ProposalResult>()
let mutable last = []
let mutable i = 0

while not stop do
printProgress i
i <- i + 1

while not stop && steps.Count <> stepsLimit do
match migrateStep p with
| Some xs when steps.Count > 0 && xs = last -> StaleMigration xs |> raise
| Some xs ->
last <- xs
xs |> List.iter steps.Add
| None -> stop <- true

if steps.Count = stepsLimit then
Print.printYellow (
$"Reached maximum steps {stepsLimit}."
+ "You would need to rerun again to continue migration"
)
| None ->
printfn "\r"
stop <- true

steps |> List.ofSeq

Expand Down
7 changes: 4 additions & 3 deletions Lib/Execution/MigrationStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ let getMigrations (p: Project) =
migrationLog)

let parseReason r =
let added = Regex "Added \"(\\w+)\""
let removed = Regex "Removed \"(\\w+)\""
let changed = Regex "Changed \(\"(\\w+)\",\\s+\"(\\w+)\"\)"
let elem = @""
let added = Regex @"Added ""(.*)"""
let removed = Regex @"Removed ""(.*)"""
let changed = Regex @"Changed \(""(.*)"",\s+""(.*)""\)"
let ra = added.Match r
let rr = removed.Match r
let rc = changed.Match r
Expand Down
2 changes: 1 addition & 1 deletion Lib/Lib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>MigrateLib</PackageId>
<Version>0.0.7</Version>
<Version>0.0.8</Version>
<Authors>Luis Ángel Méndez Gort</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<AssemblyName>Migrate</AssemblyName>
Expand Down

0 comments on commit 5734edb

Please sign in to comment.