Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm starting to check in the SQL files for creating/maintaining our database. Previously SQL files were kept totally separate from our codebase's version control.

I'd like to pragmatically store my database construction/manipulation files with my other code. Do they make the most sense in a subdirectory of my Models or as a separate directory somewhere?

For the most part the SQL statements are the data my Models access, but some other stuff is maintenance scripts ect; stuff that doesn't pragmatically fit into my MVC folder structure.

share|improve this question

3 Answers 3

up vote 8 down vote accepted

No. Your SQL files either define your Schema or they define your data access.

The data retrieved from SQL files are not your model either, or rather database record sets should not be your model. There should be a level of translation that converts your record sets into data suitable for the Model.

In an ideal scenario your Model will be agnostic of data access logic and should mereley contain data that is pertinent to one or more Views as well as view state information as well.

Your Controller should bridge the gap between the View and the data contained in the Model such that only the Controller is concerned with data access matters.

On another note, if your SQL is NOT code then what is it? You are right to store SQL in version control because they define your application as much as anything.

share|improve this answer
3  
This. I usually have SQL files in their own dbschema directory... –  Yannis Rizos Apr 17 '12 at 14:44
    
That's why I'm storing it in version control, but where? My problem is where the files make logical sense among my Controller/Model/Ect folders. –  Ben Brocka Apr 17 '12 at 14:44
5  
@BenBrocka: I think the point of this answer is you create a new directory, so you will have these: Controller; Model; View; Schema; Etc... –  FrustratedWithFormsDesigner Apr 17 '12 at 14:47
    
+1 The controller probably shouldn't be concerned with data access either, right? It should only be taking in user input and providing the proper view. Nor should the view be concerned with data access. Ideally a DAL is injected and "magically" the model is populated. –  ElGringoGrande Apr 17 '12 at 17:31
    
@ElGringoGrande I agree that a DAL is a good idea, but where would you inject the DAL then? What would call the DAL? –  maple_shaft Apr 17 '12 at 17:45

Have you looked at the SSMS plug-in SQL Source Control? It connects SQL Server to SVN, TFS, Vault, Mercurial, etc. Details at http://www.red-gate.com/products/sql-development/sql-source-control/

share|improve this answer

We keep each iteration's sql migration scripts in a big ugly .sql file that lives in TFS.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.