-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatabase-deployment.yml
More file actions
82 lines (68 loc) · 2.34 KB
/
database-deployment.yml
File metadata and controls
82 lines (68 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
trigger:
branches:
include:
- main
pool:
vmImage: 'windows-latest'
variables:
- name: buildConfiguration
value: Release
- name: artifact
value: sql_scripts
- name: dbContext
value: ApplicationDbContext
- name: scriptsProject
value: 'src/Database.Scripts'
- name: dbContextProject
value: 'src/Database.Context/Database.Context.csproj'
- group: 'DbVariableGroup'
- name: 'ConnectionString:SqlServer'
value: $[variables.DefaultConnectionString]
steps:
- checkout: self
displayName: "Checkout Repo"
- task: UseDotNet@2
displayName: 'Use .NET Core sdk 3.1'
inputs:
version: '3.1.x'
- task: DotNetCoreCLI@2
displayName: "Add DotNet tools Manifest"
inputs:
command: 'custom'
custom: 'new'
arguments: 'tool-manifest'
- task: DotNetCoreCLI@2
displayName: "Install EFCore Tools"
inputs:
command: 'custom'
custom: 'tool'
arguments: 'install dotnet-ef'
- task: PowerShell@2
displayName: 'Retrieve Last MigrationId from Last 30 Migrations Batch'
inputs:
targetType: 'inline'
script: |
Install-Module -Name SqlServer -Force
$Query = "SELECT TOP 1 T.MigrationId FROM (SELECT TOP 30 MigrationId FROM [dbo].[__EFMigrationsHistory] ORDER BY MigrationId DESC) T ORDER BY MigrationId ASC"
$MigrationId = (Invoke-SqlCmd -ConnectionString $env:CONNECTIONSTRING:SQLSERVER -query $Query -querytimeout 6000)['MigrationId']
Write-Host "Last migration: $MigrationId"
Write-Host "##vso[task.setvariable variable=lastMigration]$MigrationId"
- task: CopyFiles@2
displayName: "Copy Scripts"
inputs:
sourceFolder: '$(scriptsProject)'
Contents: '**/*.sql'
TargetFolder: '$(Build.ArtifactStagingDirectory)/scripts'
flattenFolders: true
- task: DotNetCoreCLI@2
displayName: "Generate Migrations Scripts"
inputs:
command: 'custom'
custom: 'ef'
arguments: 'migrations script $(lastMigration) --output $(Build.ArtifactStagingDirectory)/schema/migrations.sql --project $(dbContextProject) --context $(dbContext) --idempotent'
- task: PublishPipelineArtifact@1
displayName: "Publish Artifact"
inputs:
targetPath: "$(Build.ArtifactStagingDirectory)"
artifact: "$(artifact)"
publishLocation: "pipeline"