Looking for thoughts, help in migrating database from Postgres (under Heroku) to SQL Azure - sql

Would the approach to migrate from Postgres to MySQL also work for a database migration from Postgres (under Heroku) to SQL Azure? If not, can someone help in understanding what strategies to adopt? I'm considering the following:
Build a fresh database schema under SQL Azure and change database.yml to the SQL Server adapter (not sure how)
Migrate the complete schema (tables and entity relationships — don't need data). And, change database.yml to the SQL Server adapter (not sure how) .
If neither works — figure out a way to sync data between Postgres and SQL Azure.
Thoughts, ideas greatly appreciated.

If you have a rails application, were using ActiveRecord and were using database migrations, this is fairly simple. Follow this (http://blogs.msdn.com/b/silverlining/archive/2011/09/14/using-active-record-with-sql-azure.aspx) guide to get your app working against SQL Azure, upload your code changes to Heroku, run heroku run bundle exec rake db:migrate and you are done.
If you were not using database migrations, your task will be harder. I suggest using PGBackups to export data from Heroku Postgres (https://devcenter.heroku.com/articles/heroku-postgres-import-export) and finding a way to load this SQL to SQL Azure.

Related

How to apply migrations to production server

Using Code First and Entity Framework, I have created my web application on my dev machine, used migrations and published to my beta application to my production server and database.
Then on my dev system I’ve done lots of changes created several migrations and applied them to my local dev database. When I use update-database this updates my local dev database, but how then do I apply the migrations to my production server database?
I've been using update-database -script to get the SQL to manually apply to my production server. Is there a better way?
You should ideally employ some kind of actual database deployment system like ReadyRoll. Short of that, you should generate SQL scripts that you can commit and deploy manually, preferably via a DBA role in your organization. Code-based migrations can do all sorts of potentially bad things to your database with no notice, but in a SQL script, you can easily see that a table is about to be dropped or a column with lots of irreplaceable data is about to be removed.
Your in Web.config is what establishes which database the application is pointing to. When you point it to production and run the same EF commands (dotnet ef migrations add migrationName, and dotnet ef database update) it should update your production environment.
For my setup I just don't deploy my web.config so in production it always points to production database. When I run the EF update scripts in production it updates production and I'm good to go.

SQL visual client to query a databse deployed at heroku

I know Heroku has a command line client to execute a .sql file.
But is there something like an SQL Server Management Studio for databases deployed at Heroku? I was looking for a UI that allows you to interactively write queries, execute them, and view the results on a grid. I'll mostly execute SELECTs and UPDATEs based on ids, over databases generated by Rails.
Have a look at Adminium: it's a free control panel plugin for Heroku.
https://addons.heroku.com/adminium
Take a look at http://www.pgadmin.org/ and install pgAdmin III. I use it for the same purpose, watch and query over the database of one of my Heroku apps.

Can't Export Data-tier Application for Azure

I am trying to create a .bacpac file of my SQL 2012 database.
In SSMS 2012 I right click my database, go to Tasks, and select Export Data-tier Application. Then I click Next, and it gives me this error:
Error SQL71564: Element Login: [myusername] has an unsupported property IsMappedToWindowsLogin set and is not supported when used as part of a data package.
(Microsoft.SqlServer.Dac)
I am trying to follow this tutorial so that I can put my database on Azure's cloud:
http://blogs.msdn.com/b/brunoterkaly/archive/2013/09/26/how-to-export-an-on-premises-sql-server-database-to-windows-azure-storage.aspx
How can I export a .bacpac file of my database?
SQL Azure doesn't support windows authentication so I guess you'll need to make sure your database users are mapped to SQL Server Authentication logins instead.
I found this post referenced below which seems to answer my question. I wonder if the is a way to do this without having to delete my user from my local database...
"... there are some features in on premise SQL Server which are not
supported in SQL Azure. You will need to modify your database before
extracting. This article and several others list some of the
unsupported features.
This blog post explains how you can use SQL Server Data Tools to
modify your database to make it Azure compliant.
It sounds like you added clustered indices. Based on the message
above, it appears you still need to address TextInRowSize and
IsMappedToWindowsLogin."
Ref. http://social.msdn.microsoft.com/Forums/fr-FR/e82ac8ab-3386-4694-9577-b99956217780/aspnetdb-migration-error?forum=ssdsgetstarted
Edit (2018-08-23): Since the existing answer is from 2014, I figured I'd serve it a fresh update... Microsoft now offers the DMA (Data Migration Assistant) to migrate SQL Server databases to Azure SQL.
You can learn more and download the free tool here: https://learn.microsoft.com/en-us/azure/sql-database/sql-database-migrate-your-sql-server-database
As of 9/2018, there is a new tool called the Data Migration Assistant that can help with the task of migrating an existing on-premise SQL Server Database to Azure. While the tool will NOT resolve the issue of migrating Windows Logins, it will at least help you get your database schema and data migrated up to Azure.
Here is the overview of the tool: https://learn.microsoft.com/en-us/sql/dma/dma-overview?view=sql-server-2017
You can download the Data Migration Assistant here:
https://www.microsoft.com/en-us/download/details.aspx?id=53595
Once you have migrated your database up to Azure, you can configure an AD Administrator on the SQL Server, then create contained users in your database to allow users to login to your SQL Database with their Windows accounts.

Sync Azure SQL Database with remote database

I was wondering if someone could help. I have a SQL database hosted on a remote server (internet hosting company) and i want to sync my azure database.
any ideas how i could do this? eventually, i would like to transition over to sql azure.
thanks in advance.
i prefer using SQL Database Migration Wizard: http://sqlazuremw.codeplex.com/ for one time migrations. it has the option to do some analysis to check for things that are not supported in Azure SQL Database.

Visual Studio database project won't deploy to SQL Azure

I've ran into problem very similar to this. I have a .dbproj Visual Studio database project. It deploys just fine in SQL Server Express. Now I want to deploy it to SQL Azure - I change the connection parameters but deployment fails with the following text:
C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): Error Deploy01234: The target database schema provider could not be determined. Deployment cannot continue.
Done executing task "SqlDeployTask" -- FAILED.
Is deploying .dbproj projects to SQL Azure supported? How do I make Visual Studio deploy the database into SQL Azure? What are other ways to achieve more or less the same results except recreating the database manually using Azure portal?
If you are using Visual Studio 2012, you can now create a Database project and go to Properties - set its Target Platform to SQL Azure in Project Settings tab. Also you can configure the setting for dacpac output. Use this file to import directly as a new SQL Azure database.
As far as I know, Database projects are still not supported by Windows Azure. You can deploy the project to a local SQL server and then use the "Generate Scripts" feature to port the database to SQL Azure. See this link.
An easy solution is to create the database locally and use the SQL Azure Migration Wizard to do the migration up to SQL Azure. It works very well in just a few clicks (and will fix common errors).
Database projects don't work with SQL Azure. What I do is before deploying, create a brand new database on local server (to ensure it is up to date with no dev scripts), and then sync that database to Azure with RedGate SQL Compare. I do a backup first with RedGate SQL Azure Backup.
When we first built DB projects, SQLAzure was still going through its identity crisis and didn't know what it wanted to be. ;)
DBProjects support a significant superset of capabilities vs. SQLAzure. Therefore, it's quite possible that it'll create scripts that won't run against SQLAzure.
I know that the team who took-over the DBProject tooling were looking at restricting the database project generators to output SQLAzure-compatible scripts, but I don't know how far they got or whether they decided to proceed.
I echo dunnry's suggestion above and use the SQL Azure Migration Wizard or Jeremy's and use SQL 2008 R2 and generate Azure-compatible scripts.