I am maintaining an app that uses a lot of sql server 2008r2 stored procs, views etc.
The problem that I have is that certain stored procedures/views have code that is specific to the environment: production, test or development. That's how I inherited the system. The differences come from the way the linked servers have been defined.
What would be the best way to handle multiple versions of the same script?
Let's say I have a script containing a view called ViewName1.sql and this view is different in test than in production. Here are some options:
Add the environment name to the file name: ViewName1.prod.sql, ViewName1.dev.sql, ViewName1.test.sql and place all scripts in the same folder.
Put the code in different folders specific for each environment. So I would have something like this:
- Dev
- Views
- VewName1.sql
- ....
- Stored Procedures
- ....
- Views
- Production
- Views
- ViewName1.sql
- ....
- Stored Procedures.
- Views
- Dev
In this case I may put in Dev and Test only the scripts that are different, that is only the scripts that are specific to the environment, not everything. The production code would still be the source of truth for the rest of the code.
I like somewhat option 1 because the all the files that I have to modify are in the same place.
Any other ideas?
Thanks!