New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to Refresh NAV Database #315

Closed
eclipses24 opened this Issue Jan 24, 2019 · 7 comments

Comments

Projects
None yet
3 participants
@eclipses24
Copy link
Contributor

eclipses24 commented Jan 24, 2019

Hi,

Is there a way to refresh the database only (remove customizations and replace with standard objects) wihout needed to Recreate the entire NAV-Container?

This could be useful in the CI.

Kind Regads
Sergio Castelluccio

@freddydk

This comment has been minimized.

Copy link
Contributor

freddydk commented Jan 25, 2019

For CI, I recommend recreating the container - it is less than 2 minutes and replacing the database really wouldn't be much faster.

@freddydk freddydk added the wontfix label Jan 25, 2019

@eclipses

This comment has been minimized.

Copy link

eclipses commented Jan 25, 2019

Hi,

Does it takes less than 2 minutes in your tests when you run the script through VSTS agent? In my tests takes more than 6 minutes.
Do you remove the NAV Container at the end of every build or you recreate it in next build using New-NavContainer function?

This is the command I'm using, am I doing something wrong?

New-NavContainer -accept_eula -containerName $ContainerName -imageName $ImageName -auth NavUserPassword -credential $Credential -licenseFile $licenseFile -updateHosts -includeCSide -includeTestToolkit

Please let me know

Kind Regards
Sergio Castelluccio

@freddydk

This comment has been minimized.

Copy link
Contributor

freddydk commented Jan 26, 2019

Not sure what agent you are using, but my suggestions on CI are all on my blog - at this time five posts ending with https://blogs.msdn.microsoft.com/freddyk/2018/11/17/developing-business-central-extensions-part-5/ (more to come)
Including the test toolkit import - it might take more than 2 minutes - and I typically remove the container and clean up after every build.
I will consider your suggestion - after all, it might speed up things, but it is also important for me that the same agents can be used for multiple versions of business central or nav.
thanks for the suggestion.

@freddydk freddydk added enhancement and removed wontfix labels Jan 26, 2019

@freddydk

This comment has been minimized.

Copy link
Contributor

freddydk commented Feb 5, 2019

You can actually do this very easily yourself...
Right after you create the container, you run this:

$containerName = "fkdev"
$config = Get-NavContainerServerConfiguration -ContainerName $containerName
Invoke-ScriptInNavContainer -containerName $containerName -scriptblock { Param($DatabaseServer, $DatabaseInstance, $DatabaseName, $NewDatabaseName)
    Copy-navDatabase -DatabaseServer $DatabaseServer -DatabaseInstance $DatabaseInstance -SourceDatabaseName $DatabaseName -DestinationDatabaseName $NewDatabaseName
} -argumentList $config.DatabaseServer, $config.DatabaseInstance, $config.DatabaseName, "backup"

When you need to restore, you can

$containerName = "fkdev"
$config = Get-NavContainerServerConfiguration -ContainerName $containerName
Invoke-ScriptInNavContainer -containerName $containerName -scriptblock { Param($DatabaseServer, $DatabaseInstance, $DatabaseName, $NewDatabaseName)
    Copy-navDatabase -DatabaseServer $DatabaseServer -DatabaseInstance $DatabaseInstance -SourceDatabaseName $DatabaseName -DestinationDatabaseName $NewDatabaseName
} -argumentList $config.DatabaseServer, $config.DatabaseInstance, "backup", $config.DatabaseName
@eclipses24

This comment has been minimized.

Copy link
Contributor Author

eclipses24 commented Feb 5, 2019

My idea was to have a function that was downloading the standard database from the image e replacing the existing one without need to make backup and restore

@freddydk

This comment has been minimized.

Copy link
Contributor

freddydk commented Feb 5, 2019

Well, that is almost what the script does - the only difference is, that it doesn't copy the database to the outside - but keeps it inside the container which I think is absolutely the smartest (this way you don't have to invent a naming algorithm for databases on which container they match).
First script will take a copy of the database.
Other script will replace the standard with that copy.
On my machine - these scripts takes less than 10 seconds.

@eclipses24

This comment has been minimized.

Copy link
Contributor Author

eclipses24 commented Feb 5, 2019

ok, I closing this. Thanks again for your time and support

@eclipses24 eclipses24 closed this Feb 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment