At my company, we save each database object (stored proc, view, etc) as an individual SQL file, and place them under source control that way.
Up until now, we've had a very flat storage model in our versioned file structure:
DatabaseProject
Functions
- (all functions here; no further nesting)
StoredProcedures
- (all stored procs in here; no further nesting)
Views
- (ditto)
For a big new project, another idea has occurred to me: why not store these files by subject instead of in these prefab flat lists?
For example:
DatabaseProject
Reports
- (individual stored procs, views, etc.)
SpecificReport
- (more objects here, further nesting as necessary)
SpecificApplication
- (all types of DB objects, with arbitrarily deep nesting)
- et cetera....
The obvious flaw is that this folder structure doesn't impose any kind of namespace hierarchy on the database objects; it's for organization only. Thus, it would be very easy to introduce objects with duplicate names. You'd need some kind of build tool to survey the database project and die on naming conflicts.
What I'd like to know is: has anyone tried this method of organizing SQL files by application subject in their versioned file structure? Was it worth it? Did you create a build tool that would police the project as I have described?