Entity Framework MVC code first, migration to production server - sql

I've created a project using EF Version 6.0, with settings of AutomaticMigrationsEnabled = true;
Which worked fine, i could able to deploy in production server on first time, It created desire database tables.
Now for second update, I've get script out from migration so that i can able to run in production server. but i tried many Package Manager commands, but it does creating empty .sql files.
My second Migration has name "201601181549424_Version-1.2.0", i used following sequence of steps and commands to generate .sql file.
Added desire data classes (which will be creating tables in database) and MVC views and controller.
Run Package Manger Command is "ADD-MIGRATION Version-1.2.0" has created 201601181549424_Version-1.2.0" file in Migration folder
Than "UPDATE-DATABASE" - has updated local database, check everything works fine.
Than "UPDATE-DATABASE -Script" - has created empty.sql file. I am looking to get sql file with creation of database tables in sql file.
Can you please help me understand how i can deploy this in production database.
Thanks,

I figured out by this way..
Make desire changes to model, (INSERT OR UPDATE MODEL)
Add-Migration
Update-Database -Script
(Which will create script and can store for QA or production deployment purpose)
Update-Database
(Above command will update model in to local database)

Related

Update production database : jhipster

I am having hard time understanding how Liquibase works with jhipster. I am using Boxfuse to deploy jar file to AWS. Now , since my application is evolving continuously I need to add/drop columns/tables every week.
Application works fine for the first time when I deploy it for the first time , Also it works fine when there is no change in the Database schema only the change in code. Now , I need to add column to database. I used mvn liquibase:update command wit the changesets containing the respective changes in the master.xml. Even the changes are applied to the database. I confirmed them.
Now, when I deploy the updated jar with the changes , It gives error and is unable to deploy. Also, boxfuse console does not show any specific error . It just says that failed to upload.
Can someone help me with this? Thanks.

Get SQL queries which are executed from SSIS package on SQL Server

I have built a custom job log framework which logs all of the tasks which are execute in an SSIS package along with any error that surface. Once complete, an enhancement was requested to also store any SQL queries that the SSIS package executes on the SQL Server. This is not limited to only Execute SQL tasks, they are looking for ANY SQL queries that the pack runs. I am aware of the OnInformation logging that is part of the SSIS logging framework, but this only shows some of the query.
Thanks in advance!
These is a free software on codeplex which I believe might satisfy your request at: https://sqlmetadata.codeplex.com/
If you need to code it, you should consider that there are two main types for deployed SSIS packages: Legacy mode and Catalog mode.
Legacy Mode deploys pacakges to msdb where you can find using SELECT name, packagedata FROM msdb.dbo.sysssispackages
Catalog Mode uses SSISDB, you can use catalog.get_project to return project_stream which represents a zip file containing the packages in the project. You can refer to How to export packages deployed in "Integration Services Catalog" using any command line, C# or T-SQL?.
After having the packages' XML, you can easily identify which components you want to export.

SQL error in Laravel when moving project between machines

I just moved my laravel project from one machine to another.
What I didn was:
-Create a new Laravel Homestead machine.
-Copy all files from my laravel app's folder
The website serves ok from my new machine but any database dependant operation fails because the tables aren't created in my new server. The error is the following:
QueryException in Connection.php line 673: SQLSTATE[42S02]: Base table or view not found:
The migrations are present in my new machine but I cant do a
php artisan migrate
or a
php artisan migrate:refresh
since both return
[Symfony\Component\Debug\Exception\FatalErrorException]
Cannot declare class CreateUsersTable, because the name is already in use
I've spent so much time here I don't know what to do.
delete all the tables from the database manually including the migrations table and run php artisan migrate

Execute multiple sql scripts in order using web deploy

I am using SSDT project to keep my current schema.
I have some scripts that I need to run during deployment of sql database.
How can I setup scripts to execute in order as on picture below?
Currently my deploy fails when I have added publish data into post deploy, which means that steps 1,2 did not execute as I hoped.
See order I need to execute those below:

Entity framework and migrations - how to update my database on remote server?

I enabled migrations for my entity framework application. Now, i want to update my database on my remote server. I ran this command:
PM> Update-Database -Script
So it generated a sql script. But, this script has all the metadata that I actually have in my database, and not the changes that were made; so, when I try to run this sql script on my remote server, it says that tables already exists.
How can i generate sql script, that will contain only necessary updates?
You can target a specific migration for this. If you have a migration called Foo, for example:
Update-Database -TargetMigration Foo -Script
It will generate a migration script for the Foo migration. Replace Foo with whatever migration you need to run on that server.
Add-Migration InitialMigration
Add-Migration AddCustomers
Add-Migration AddProjects
Let's say you have the above three migrations in your project, and your local database has all of them applied, but the remote database only has InitialMigration. You can run the following:
Update-Database -SourceMigration InitialMigration -TargetMigration AddProjects -Script
This will apply two migrations on the remote server (AddCustomers and AddProjects).
If you have access via remote desktop to the server you can execute the command-line migration tool which is usually found in [projectFolder]/packages/EntityFramework.5.0.0/tools/migrate.exe
And call it like this:
Migrate.exe [StartupProjectName] /StartupDirectory:"[BIN folder path]" /ConnectionStringName:"[Connection String Name]" /StartupConfigurationFile:"[Path to web or app.config]"
You could use the MigrateDatabaseToLatestVersion Initializer to automatically apply any new migrations when you deploy a new version of your application:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDbContext, Configuration>());