From f2801c2f5f63c587b1410ad34e5fcf1daaad1a92 Mon Sep 17 00:00:00 2001 From: Silvano Coriani Date: Tue, 14 Jul 2020 08:54:08 +0200 Subject: [PATCH 1/3] Create main.yml --- .github/workflows/main.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..3f63d97 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: .NET Core + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.101 + - name: Change folder and install depen + run: cd fitnessdb-dbup; dotnet restore + - name: Run + env: # as an environment variable + ConnectionString: ${{ secrets.CONNECTIONSTRING }} + SQLPassword: ${{ secrets.SQLPASSWORD }} + run: cd fitnessdb-dbup; dotnet run + From b5e88467525a964b630c197abe2d3235360202ad Mon Sep 17 00:00:00 2001 From: Silvano Coriani Date: Tue, 14 Jul 2020 08:59:54 +0200 Subject: [PATCH 2/3] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3f63d97..f93dbe0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,9 +2,9 @@ name: .NET Core on: push: - branches: [ master ] + branches: [ add-pipeline ] pull_request: - branches: [ master ] + branches: [ add-pipeline ] jobs: build: From 85e3c21c0a8c5cc2146dbc2399ca4926aaf9bdff Mon Sep 17 00:00:00 2001 From: scoriani Date: Tue, 14 Jul 2020 09:13:57 +0200 Subject: [PATCH 3/3] add temperature --- fitnessdb-dbup/.vscode/launch.json | 27 +++++++++ fitnessdb-dbup/.vscode/tasks.json | 42 ++++++++++++++ fitnessdb-dbup/sql/04-add-temperature.sql | 2 + fitnessdb-dbup/sql/05-stored-proc-update.sql | 58 ++++++++++++++++++++ fitnessdb-dbup/sql/06-temps-data.sql | 5 ++ 5 files changed, 134 insertions(+) create mode 100644 fitnessdb-dbup/.vscode/launch.json create mode 100644 fitnessdb-dbup/.vscode/tasks.json create mode 100644 fitnessdb-dbup/sql/04-add-temperature.sql create mode 100644 fitnessdb-dbup/sql/05-stored-proc-update.sql create mode 100644 fitnessdb-dbup/sql/06-temps-data.sql diff --git a/fitnessdb-dbup/.vscode/launch.json b/fitnessdb-dbup/.vscode/launch.json new file mode 100644 index 0000000..241b89d --- /dev/null +++ b/fitnessdb-dbup/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/database-migration.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/fitnessdb-dbup/.vscode/tasks.json b/fitnessdb-dbup/.vscode/tasks.json new file mode 100644 index 0000000..21cc639 --- /dev/null +++ b/fitnessdb-dbup/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/database-migration.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/database-migration.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/database-migration.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/fitnessdb-dbup/sql/04-add-temperature.sql b/fitnessdb-dbup/sql/04-add-temperature.sql new file mode 100644 index 0000000..e98890c --- /dev/null +++ b/fitnessdb-dbup/sql/04-add-temperature.sql @@ -0,0 +1,2 @@ +ALTER TABLE dbo.TrainingSession + ADD Temperature DECIMAL(9,3) NULL \ No newline at end of file diff --git a/fitnessdb-dbup/sql/05-stored-proc-update.sql b/fitnessdb-dbup/sql/05-stored-proc-update.sql new file mode 100644 index 0000000..400494b --- /dev/null +++ b/fitnessdb-dbup/sql/05-stored-proc-update.sql @@ -0,0 +1,58 @@ +create or alter procedure web.get_trainingsessionsync +@json nvarchar(max) +as + +declare @fromVersion int = json_value(@json, '$.fromVersion') + +set xact_abort on +set transaction isolation level snapshot; +begin tran + declare @reason int + + declare @curVer int = change_tracking_current_version(); + declare @minVer int = change_tracking_min_valid_version(object_id('dbo.TrainingSession')); + + if (@fromVersion = 0) begin + set @reason = 0 -- First Sync + end else if (@fromVersion < @minVer) begin + set @fromVersion = 0 + set @reason = 1 -- fromVersion too old. New full sync needed + end + + if (@fromVersion = 0) + begin + select + @curVer as 'Metadata.Sync.Version', + 'Full' as 'Metadata.Sync.Type', + @reason as 'Metadata.Sync.ReasonCode', + [Data] = json_query((select Id, RecordedOn, [Type], Steps, Distance, Temperature from dbo.TrainingSession for json auto)) + for + json path, without_array_wrapper + end else begin + select + @curVer as 'Metadata.Sync.Version', + 'Diff' as 'Metadata.Sync.Type', + [Data] = json_query(( + select + ct.SYS_CHANGE_OPERATION as '$operation', + ct.Id, + ts.RecordedOn, + ts.[Type], + ts.Steps, + ts.Distance, + ts.PostProcessedOn, + ts.AdjustedSteps, + ts.AdjustedDistance, + ts.Temperature + from + dbo.TrainingSession as ts + right outer join + changetable(changes dbo.TrainingSession, @fromVersion) as ct on ct.[Id] = ts.[id] + for + json path + )) + for + json path, without_array_wrapper + end + +commit tran \ No newline at end of file diff --git a/fitnessdb-dbup/sql/06-temps-data.sql b/fitnessdb-dbup/sql/06-temps-data.sql new file mode 100644 index 0000000..a61be39 --- /dev/null +++ b/fitnessdb-dbup/sql/06-temps-data.sql @@ -0,0 +1,5 @@ +insert into dbo.TrainingSession + (RecordedOn, [Type], Steps, Distance, Duration, Calories, Temperature) +values + ('20200530 07:24:32 +08:00', 'Run', 4866, 4562, 30*60+18, 475, 60) +go