How to avoid dropping schemas when publishing DB in VS 2019 Database project - visual-studio

When publishing a database from Visual Studio, there are several options to "do not drop" an object if it is not in the Source. However, it seems that there is no option to avoid dropping schemas. Do anyone know if this is possible to achieve, or do I have to manually edit the publish script?

It would probably be simplest just to add the schema to the project. The script would be simple enough, we use:
CREATE SCHEMA [api]
AUTHORIZATION [dbo];
(Also, I wish I'd seen this question much earlier, hopefully this isn't too late to help someone.)

Related

Created schema with DataGrip how to backup and migrate

I have just implemented my DB Schema with Jetbrains new DataGrip IDE. The schema now exists on my DB server instance that is running locally.
In other IDE's I can save the work as a "Project" or save the SQL to a file. I don't see any option in DataGrip, except for Copy DDL, which I have tried and it copies my schema along with a lot of other stuff.
Is that the only option or am I supposed to do it through a PostgreSQL management tool. I want to save my work.
Thanks. Also, please don't just mark this to be closed. I have seen many other questions like this on StackOverflow. i.e. Asking how to perform some action on a tool related to software development.
You are in "default" project by default. Go to File/Project and create your own which can be opened later by File/Open recent, for example.

How to update a Visual Studio Databaseproject automatically

is it possible to update a databaseproject automatically? For example on a TFS build server?
I had a big database and just start with the databaseprojects. So currently our database is primary not updated by a databaseproject and thats the reason why i must update my project alot to get it sync with the database. Currently i use a preconfigured schemacompare of the datatools. But the update of the project must be done by hand :(
Is there any way to do that automatically?
Regards
If I understand your question correctly, then you should probably look into creating a .cmd script that calls SqlPackage.exe. The operation you are interested in is Extract. You should be able to update your .dacpac file with the current DB schema using this.

TFS 2010 version control

We want to start using the TFS version control on our project. I read the tutorial and noticed that TFS creates tables in the sql db. My questions are:
What are these tables for?
Where is the vs solution actually stored?
How can I use more then one instance of our solution from another computer (another developer)?
TFS stores pretty much all its data in few SQL database: source control, work items, build definitions, build results etc.
In the SQL database for the Team Project Collection, specifics about which tables etc should not matter to you. Users setup a workspace which maps the directory structure in source control to a place on their local disk.
I'm not sure what you're asking here, can you try clarify your question?

How to re-deploy, re-create database on each test run

Currently I'm using Visual Studio 2012 RC and SQL Server 2012 RTM.
I'd like to know how to re-deploy/re-create a test database for each test run.
Keep in mind I've a SQL Server database project for the database using Visual Studio 2012's template.
Actually I'm not very sure about an idea I got in my mind, but .testsettings file has Setup and cleanup scripts. Is this the way to go? For example, a PowerShell script reading the database project generated script and executing it against the database?
I guess there're better ways of doing that and it should be an out-of-the-box solution but I ignore it and Google doesn't help me in finding the right solution.
As mentioned you'll probably want to use the VS 2012 .Local.testsettings > Setup and Cleanup scripts to create / tear down you SQL Server database.
For the script you may want to use powershell with a .dacpac (rather than just a T-SQL script), since you are using a SSDT project. Here's a link to some example code - in particular you may want to take a look at the 'Deploy-Dac' command.
If you are unfamiliar with .dacpacs as the (build) output of SSDT-created database projects, take a look at this reference link.
Edit: Although this doesn't answer the question in a plain SQL Server way, an easy Entity Framework approach would be the following: I found that I could create and destroy my database every time correctly by using the DbContext.Database.CreateIfNotExists() and DbContext.Database.Delete() methods in my setup and cleanup phases of my tests.
The fastest solution, while a bit of a hack, is really straightforward. You can set the DB Projects properties under the debugging tab to "always re-created DB". Then test in two clicks, do a debug/build, then run all tests. You should get a freshly built DB on localDB for you tests to be ran against. You can also change the target for the debugging DB (again the DB projects properties) to whatever you want, so you can deploy to a .dacpac, or to an existing SQL DB or wherever. It means testing in two steps, and if your build is long, it may be annoying, but it works. Otherwise, I believe scripting is your only option.

Database project with a lot of references

I just try to set up a database project in Visual Studio 2010. We have one database, that contains a lot of stored procedures. Unfortunately those procedures accesses quite a lot of other databases (30+), so I get a lot of "unresolved references" errors.
At the moment I see two possibilities to solve my problem:
Add database projects to my solution, till I have all the errors resolved.
Create a lot of schemas for all my databases and add them as reference.
Both possibilities are a lot of work, especially as there can come a lot more databases in the future. My dream would be, that I can just add the whole server as a reference. Is that possible somehow? Are there any other solutions I don't know of?
This might help you. I found a article about referring databases here and this explains how to add multiple database project here
Hope this helps
This might not be the answer you are looking for, but you could setup one database to carry the references to the other databases via. "Server Objects -> Linked Servers" and change the code for the sp's to run through the 4 name quantifiers.
This would give you the added benefit of having the databases you depend on not hard coded.
Hope this is usefull to you.

Resources