Skip to content
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

Migration scripts not found when using Azure App Service #76

Closed
ld0614 opened this issue Aug 30, 2018 · 5 comments
Closed

Migration scripts not found when using Azure App Service #76

ld0614 opened this issue Aug 30, 2018 · 5 comments
Labels

Comments

@ld0614
Copy link

ld0614 commented Aug 30, 2018

Configuration:
C# .Net 4.6.2
Azure SQL Server V12
Azure App Service

Migration Launcher:

try
{
	string connectionString = Settings.GetSettings().DatabaseConnectionString;
	SqlConnection cnx = new SqlConnection(connectionString);
	Evolve.Evolve evolve = new Evolve.Evolve(cnx, msg => Trace.TraceInformation(msg))
	{
		Driver = "SqlClient", //Connect to SQL Server
		Locations = new List<string> { "db/migrations" },
		IsEraseDisabled = true, //Do not allow Erasing of schema
		EnableClusterMode = true //Ensure that no other instances also attempt to migrate the database as the same time
	};

	evolve.Migrate();
}
catch (Exception ex)
{
	Trace.TraceError("Database migration failed.", ex);
	throw;
}
}

SQL files have been written and are uploaded to the web server:

image

During start the following logs are provided

Application: 2018-08-30T14:46:57  PID[5928] Information Executing Migrate...
Application: 2018-08-30T14:46:57  PID[5928] Information Evolve initialized.
Application: 2018-08-30T14:46:57  PID[5928] Information No metadata found.
Application: 2018-08-30T14:46:57  PID[5928] Information Database is up to date. No migration needed.

And a single blank changelog table has been created:
image

As far as I can tell I've followed all the requirements for using Evolve but I'm unsure of how to troubleshoot this issue further, any assistance would be greatly appreciated.

@lecaillon
Copy link
Owner

lecaillon commented Aug 30, 2018

Hi @ld0614

Since the changelog table has been created, it means that Evolve is able to connect to your database.
Your migration scripts seem to be well named.
So I think it does not find any of your sql migration files.
Have you set the property Copy to output directory to Copy always on each of your sql file ?

I realize the doc might not be specific about this point when you use the In-app mode ... ?

@ld0614
Copy link
Author

ld0614 commented Aug 30, 2018

Hi @lecaillon, thanks for getting back so soon, the screenshot above is a view of the web server file structure showing the files on the web server. The below screenshot if the file configuration.
image

The only thing I really stray from your example is in the code launch, in Global.asax.cs I have the following line:

UpdateDatabase.UpdateDatabaseUsingEvolve();

This then calls the updateDatabase class which is saved in App_Start\UpdateDatabase.cs file. The db\migration path is at the root of the directory.

I have also attempted to place the files at /bin/App_Start/db/migrations as the dlls for the website are at /bin. After updating the file locations to either bin/App_Start/db/migrations or Add_Start/db/migrations nither returned a different log message.

@lecaillon
Copy link
Owner

lecaillon commented Aug 30, 2018

ok, in fact Evolve searches migration files in the current app directory combine with the value of the Locations parameter. Or in the Locations parameter only if you have define a full path.
So in our case I see the db folder is next the bin folder.
Thus I would try:

Locations = new List { "../db/migrations" },

@ld0614
Copy link
Author

ld0614 commented Aug 30, 2018

Thanks for all your assistance, after a few experiments I discovered that the working directory on an Azure App Service is fixed to D:\Windows\System32. thus all uses of DirectoryInfo where branching off of there. using ../db/migrations" didn't help either as this returned to the root of the D drive. To fix I added the following code:

string currentPath = System.Web.HttpContext.Current.Server.MapPath("~");
Locations = new List<string> { currentPath + "db\\migrations" },

This maps to the correct root folder which can then be changed to the correct relative folder.

To assist with future debugging may I suggest a branch from here:

if(!dirToScan.Exists) continue;
which would write a message if it was unable to locate the directory (ideally with the offending path)?

@lecaillon
Copy link
Owner

lecaillon commented Aug 30, 2018

Nice, i did not know.
I will think about a way of logging locations that do not exist.

Can I change your title issue to something like: "Scripts not found in Azure App Service" ?

@ld0614 ld0614 changed the title Unable to update database Migration scripts not found when using Azure App Service Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants