Oracle packages in version control? - database

Lucky me, I have to work with Oracle. And packages.
I have a package that a lot of different developers are touching and it's scaring me. Is it possible to put a package inside of Version Control? Is there some kind of software out there that already does this? If not, is there some kind of export procedure? Can I just grab a file off of a file system?

How are they inputting it? The way we used to work at my last job is editing a text file, and loading it with SQL*Plus. You can just put that source file under version control.
The source must be between "CREATE OR REPLACE PACKAGE MYPACKAGE AS" and "END;" followed by a single slash on a line of its own ("/"); and ditto for "PACKAGE BODY" instead of "PACKAGE".
And yes, there's a way to pull the source out of Oracle. It's in a table, line by line, look up ALL_SOURCE and USER_SOURCE. You can pull it out with a query like
SELECT TEXT FROM ALL_SOURCE
WHERE TYPE='PACKAGE BODY'
AND NAME='MYPACKAGE'
AND OWNER='MYPACKAGEOWNER'
ORDER BY LINE
(untested as I no longer have access to Oracle) and ditto for the 'PACKAGE'.
I think it's best to load it again into Oracle using SQL*Plus; make sure to set "SCAN OFF".

We have a database level trigger to capture changes to packages and save the source in a seperate table. It's not as good as version control, but at least you know when something changes and can retrieve it if a later change tramples on it.

You can download sql developer for free: http://www.oracle.com/technology/products/database/sql_developer/files/what_is_sqldev.html. It integrates with subversion and cvs.
There is also a Visual Studio plugin (http://www.oracle.com/technology/tech/windows/odpnet/index.html). I don't know whether you use Visual Studio or not?

Try http://code.google.com/p/oracle-ddl2svn/ version control for Oracle

Take also a look at this link. It's a PHP/mySQL versioning tool which works with any database type and is fairly simple to learn.

Related

SSIS: Finding Table Used in Other Package(s)/ Integration

I did see some other posts on this, but they were rather old and there does not appear to be any solutions at this point.
I'm trying to determine where a particular table(s) that SSIS is loading during a monthly job is being used in other packages. The package that loads these tables have in the past several months been taking much longer than before, and I'm trying to see if I can eliminate this load all together.
I just happened to check the Allocation packages in our database to see how the tables were being used, and discovered that I can't find anywhere when/where those tables are being used. Is there a function or query I can run in SSMS or elsewhere to determine how to find this information?
Thx in advance - please let me know if I need to clarify something.
The packages are just XML files. If you have the packages somewhere on your file system you can use any program that searches through text files.
I'm not sure about older SSIS projects but with an SSIS project in Data Tools for SQL Server 2012 you can just use the build in search function to search through your entire solution. It will also search in the XML of all the packages.
If you don't have this particular information saved anywhere already in your documentation then I think you are going to have some difficulty in finding an accurate way to retrieve this information. However, there are a few automated data collection options that might help you get most of the way there.
The first option is that because all SSIS Packages are essentially glorified XML that is being fed into an engine you can perform a patterned search on the packages like GREP to look for that particular table name. Any packages that dynamically retrieve and build the table name though would not be found through this method.
Another option would be to run a server side SQL trace with a pattern match based on the table name(s) and limited to the host or application name of SSIS. Run over the course of a month or so would make for a fairly accurate list.
I haven't used it myself, but the DOC xPress tool from PragmaticWorks might be what you're looking for.

SSIS Control Flow Diagram is now empty

I had a working SSIS package last week. I came back into the office this morning, opened up the package and tried to open up one of the Data Flow tasks. Double clicking did nothing. I closed the project and reopened it and received an error message that there was a "Catastrophic Error" and that the layout could not be displayed. The Control Flow diagram now only showed my two Sequence Containers.
I made a copy of the dtsx file then went into it manually with a text editor and found that some of the XML was duplicated. I removed the "extra" copy and reopened my package. The empty Sequence Containers are now gone, but I still can't see any of my components. I looked at the Package Explorer and everything is still there, but it's just not displaying in the designer. I was even able to run the package successfully.
Is there any way to rebuild the package so that I can see everything in the designer? Any other suggestions?
Thanks!
I'm not sure why BIDS has decided the layout is junk but you can get around the issue by removing the layout and forcing BIDS to regenerate that information. The graphical layout stuff is a cool idea for conceptualizing how a package is organized but the implementation of storing that information, serialized XML inside XML, is pants.
There are various articles available about how to remove the XML, but this is a more recent example of how to use do this. http://joshrobi.blogspot.com/2012/04/editing-existing-ssis-package-via-ezapi.html
As always, ensure you have a good copy of the package before editing the XML directly.
Do you have a backup of your package - try and restore that to another location first to make sure that is not corrupted.
How are you accessing the package, are you connecting remotely to a server hosting SSIS, or are you using tools located locally on the server?
I've encountered issues when trying to access packages across networks before.
Also, as a word of warning it's not good practice to edit package contents before carrying out further diagnosis!

code template in management studio

Can I find in management studio the Following feature?
I want to write a specific word and that it be replaced by a statement specifies. Ex: I write "ss" and replace "select * from" or write "johnid" and is replaced by "where id = '555 '"
 
In Toad for Oracle You might still in: "option - behsvior - template code - code template"
http://www.toadworld.com/Blogs/tabid/67/EntryId/343/Customizing-Toad-Code-Templates.aspx
There is nothing I know of built into Management Studio that will behave exactly like you are suggesting. There are some shortcuts you can advantage of in Tools > Options > Environment > Keyboard > Query Shortcuts, but these run the code rather than paste them into your window, so you can't use them as partial syntax completion. For example if you assign SELECT * FROM to Ctrl+9, then open a new query window and press Ctrl+9, you have an empty query window and the following error message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'FROM'.
Chris already mentioned templates, so I won't treat those.
In SQL Server 2012 you can use a new feature (well, an old feature recycled from Visual Studio) called Snippets, which I think is a lot more powerful than the Template feature (I wrote about them here, and someone else did a decent job here). But I still don't think it's quite what you're after - there's a menu system to go through to insert a snippet, and so far in my research I've been unable to assign a keyboard shortcut -- even though there is an empty element in the Snippet XML called <Shortcut></Shortcut>, and most of the people who talk about this feature mention it, but I've yet to see a working snippet that used it (and I have tried many variations to get it work like it does in Visual Studio with no luck).
You can also use 3rd party tools, such as Mladen Prajdic's free SSMS Tools Pack. For what you want to do, I think this is the best fit, since it allows you to do real expansions snippets where the replacement text is put into your code based on the keyword you typed ad further keystrokes. However if you're using SQL Server 2012, at the time of posting we're still waiting on a compatible release for that version of SSMS. You may also want to look into Red-Gate's SQL Prompt, but I'd try Mladen's free tool first if you can. I'm sure there are other alternatives you can turn up with a standard search.
This feature is present in these free add-ins:
SSMSBoost or SSMS Tools Pack
Use Template Explorer
SQL Server provides a variety of templates. Templates are boilerplate files containing SQL scripts that help you create objects in a database. The first time the template explorer is opened, a copy of the templates are placed in the user’s folder in C:\Users, under AppData\Roaming\Microsoft\SQL Server Management Studio\110\Templates.
You can browse the available templates in Template Explorer, then open a template to incorporate the code into a code editor window. You can also create custom templates.

Add Database Diagram to Source Control?

Is there any way to add a SQL Server Database Diagram to source control? I can't seem to find a way to script it out of the database. If so, is there a way to get that diagram into a Visual Studio Database Project for easy deployment?
to script it to a file try:
http://www.codeproject.com/KB/database/ScriptDiagram2005.aspx
I would not do this.
I've been allowed to publish my variation on a set of scripts that do just that, providing easy two-way import/export between files and diagrams stored in a database.
https://github.com/timabell/database-diagram-scm
Just run the batch file, pointing at your database of choice and you'll get a set of files, one for each diagram. Unfortunately the data is still binary, but it's a start.
It builds on what others have already done, definitely a shoulders of giants job. :-)
I don't know what the advantage of storing the diagram in source control would be. The database diagrams put an illustration to your database relationships which should be defined elsewhere. So long as you put the creation scripts for your DB in source safe, the diagram should render just fine when you create it and add your tables to it.
There isn't really an easy way of doing this. I typically do one of a few things for this.
Simply print the document to PDF using something like CutePDF
Use Visio and the Reverse Engineering option to generate the document, then save the visio file
Use Enterprise Architect or similar tool for the process.
I personally use option 3, due to the lifecycle that I take my applications through. But the real thing is what are you looking to store, if it is a static version of the database diagram, any of the above are valid.

How to keep Stored Procedures and other scripts in SVN/Other repository?

Can anyone provide some real examples as to how best to keep script files for views, stored procedures and functions in a SVN (or other) repository.
Obviously one solution is to have the script files for all the different components in a directory or more somewhere and simply using TortoiseSVN or the like to keep them in SVN, Then whenever a change is to be made I load the script up in Management Studio etc. I don't really want this.
What I'd really prefer is some kind of batch script that I can run periodically (nightly?) that would export all the stored procedures / views etc that had changed in a given timeframe and then commit them to SVN.
Ideas?
Sounds like you're not wanting to use Revision Control properly, to me.
Obviously one solution is to have the
script files for all the different
components in a directory or more
somewhere and simply using TortoiseSVN
or the like to keep them in SVN
This is what should be done. You would have your local copy you are working on (Developing new, Tweaking old, etc) and as single components/procedures/etc get finished, you would commit them individually until you have to start the process over.
Committing half-done code just because it's been 'X' time since it was last committed is sloppy and guaranteed to cause anyone else using the repository grief.
I find it best to treat Stored Procedures just like any other compilable code: Code lives in the repository, you check it out to make changes and load it in your development tool to compile or deploy the code.
You can create a batch file and schedule it:
delete the contents of your scripts directory
using something like ExportSQLScript to export all objects to script/scripts
svn commit
Please note: That although you'll have the objects under source control, you'll not have the data or it's progression (is that a renamed field, or 1 new field and 1 deleted?).
This approach is fine for maintaining change history. But, of course, you should never be automatically committing to the "production build" (unless you like broken builds).
Although you didn't ask for it: This approach also won't produce a set of scripts that will upgrade a current DB. You'll only have initial creation scripts. Recording data progression and creation upgrade scripts is beyond basic source control systems.
I'd recommend Redgate SQL Compare for this - it allows you to compare database versions and generate change scripts - it's also fairly easily scriptable.
Based on your expanded question, you really want to use DDL triggers. Check out this article that details how to create a changelog system for your database.
Not sure on your price range, however DB Ghost could be an option for you.
I don't work for this company (or own the product) but in my researching of the same issue, this product looked quite promising.
I should've been a little more descriptive. The database in question is for an internal ERP system and thus we don't have many versions of our database, just Production/Testing/Development. When we've done a change request, some new fancy feature or something, we simply execute a script or series of scripts to update the procedures in question on the Testing database, if that is all good, then we do the same to Production.
So I'm not really after a full schema script per se, just something that can keep track of the various edits to the stored procedures over time. For example, PROCESS_INVOICE does stuff. It gets updated in some minor way in March. Some time later in say May it is discovered that in a rare case customers get double invoiced (or some other crazy corner case). I'd like to be able to see what has happened over time to this procedure. Currently the way the development environment is setup here I don't have that, which I'm trying to change.
I can recommend DBPro which is part of Visual Studio Team Edition. Have been using it for a few months for storing all parts of the database in Team Foundation Server as well as for deployment and database compares, etc.
Of course, as someone else mentioned, it does depend on your environment and price range.
I wrote a utility for dumping all of the relevant parts of my db into a directory structure that I use SVN on. I never got around to trying to incorporate it into the Manager but, if you're interested, it's here: http://www.reluctantdba.com/dbas-and-programmers/sqltools/svnforsql2005.aspx
It's free and, since I regularly run it, you know any bugs get fixed quickly.
You can always try integrating SourceSafe with SQL Server. Here's a quick start : link . To work with it you've got to have Managment Studio Developers Edition.

Resources