dataplat / dbops

âš™ dbops - Powershell module that provides continuous database deployments on any scale
MIT License
163 stars 39 forks source link

Install-DBOScript fails to run a changed file #137

Closed ishepherd closed 2 years ago

ishepherd commented 2 years ago

Hi 👋 thankyou for this project.

I'm finding that this cmdlet, though it finds the file, never runs it? It seems to run it once and never again, even if it changed. I assumed it tracks the checksum in SchemaVersions for the purpose of detecting a change?

Expected behaviour: Content has changed => script is run again.

> Install-DBOScript -Path 04_DatabaseServers/SqlManagedInstance/*.sql -Database master `
         -Server $endpoint -User $adminUser -Password (ConvertTo-SecureString -AsPlainText $adminPassword) -Debug -Verbose

VERBOSE: [20:28:10][Get-DbopsFile] Item 04_DatabaseServers/SqlManagedInstance/*.sql (string) will be treated as a string
DEBUG: 49 | [20:28:10][Get-DbopsFile] Item 04_DatabaseServers/SqlManagedInstance/*.sql (string) will be treated as a string
DEBUG: 15 | [20:28:10][Select-DbopsFile] Getting child items from <snip>\04_DatabaseServers\SqlManagedInstance\SetupSqlManagedInstance.sql; Root defined as <snip>\04_DatabaseServers\SqlManagedInstance
VERBOSE: [20:28:10][Install-DBOScript] Preparing to start the deployment of 1 file(s)
DEBUG: 223 | [20:28:10][Install-DBOScript] Preparing to start the deployment of 1 file(s)
VERBOSE: [20:28:10][Get-DBOConfig] Merging configuration from a DBOpsConfig object
DEBUG: 59 | [20:28:10][Get-DBOConfig] Merging configuration from a DBOpsConfig object
DEBUG: 32 | [20:28:10][Merge-Config] Replacing variable tokens
DEBUG: 157 | [20:28:10][Invoke-Deployment] Initializing libraries for SqlServer
DEBUG: 35 | [20:28:10][Initialize-ExternalLibrary] All libraries for SqlServer were found among the loaded libraries
DEBUG: 193 | [20:28:10][Invoke-Deployment] Adding deployment script <snip>\04_DatabaseServers\SqlManagedInstance\SetupSqlManagedInstance.sql as SetupSqlManagedInstance.sql
DEBUG: 205 | [20:28:10][Invoke-Deployment] Creating DbUp objects
VERBOSE: [20:28:10][Get-DbUpJournal] Creating journal object for SqlServer in dbo.SchemaVersions
DEBUG: 50 | [20:28:10][Get-DbUpJournal] Creating journal object for SqlServer in dbo.SchemaVersions
DEBUG: 315 | [20:28:10][Invoke-Deployment] Performing deployment
[20:28:10][Install-DBOScript] Beginning database upgrade
DEBUG: 224 | [20:28:10][Install-DBOScript] Beginning database upgrade
[20:28:10][Install-DBOScript] Checking whether journal table exists..
DEBUG: 224 | [20:28:10][Install-DBOScript] Checking whether journal table exists..
[20:28:10][Install-DBOScript] Fetching list of already executed scripts.
DEBUG: 224 | [20:28:10][Install-DBOScript] Fetching list of already executed scripts.
[20:28:10][Install-DBOScript] No new scripts need to be executed - completing.
DEBUG: 224 | [20:28:10][Install-DBOScript] No new scripts need to be executed - completing.
ishepherd commented 2 years ago

OK I get it - Seems that the checksum isn't part of change detection? This tool runs a certain script filename once and never again, by design.

This seems bad for stateless objects (Stored Procs, Views, etc), you have to rename the file every time you want to edit the object? Surely this will break git blame and things like that?

Am I missing something?

nvarscar commented 2 years ago

There is a way to detect changes, but currently the only way to do so is to use the incremental builds in Packages, which would track the file changes on the client side. You would do something like

# Create a package first 
New-DBOPackage -Path package.zip -ScriptPath .\myfunctions -Build 1.0.0
# add files, as they get created or modified
Add-DBOBuild -Path package.zip -ScriptPath .\myfunctions -Type New, Modified
# install the package
Install-DBOPackage -Path package.zip ...
ishepherd commented 2 years ago

OK, thanks!