Run RoundHouse scripts based on object dependencies

478 views Asked by At

Currently we have been using RoundHouse for deploying of database scripts. The scripts are organised into folders for views, functions, up, and stored procedures. Each script creates or alters a single object

Everything has been working for many years. Until now. We have dependency problems where functions depend on views and views depend on functions (not circular dependencies).

We have attempted to address the issue by moving the offending scripts into the runFirstAfterUp folder.

Whilst incremental database updates have worked over the last few weeks, creating a new database from the scripts fails. All because the scripts that live in the runFirstAfterUp folder has dependencies that live in the views or functions folder, that have been there for many years.

The runFirstAfterUp folder contains scripts that have a sequence prefix to ensure they run in order - ie 0001_Create_View1.sql

So sorting this out one by one is a thankless task :-

  1. run roundhouse
  2. roundhouse errors running script
  3. move script to the runFirstAfterUp and rename sequence to appropriate sequence
  4. repeat 1

There are 68 functions and 83 views.

My feel is that the whole set of functions and views will be moved to the runFirstAfterUp - as order is important.

My thought is to generate a SQL script to create ALL of the views and functions first so that the subsequent alter/create view if not exists will work.

So something along the lines of:

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID('dbo.f_func1')) EXECUTE('CREATE dbo.f_func1()RETURNS @FunctionReturn TABLE(Col1 INT) AS BEGIN INSERT INTO @FunctionReturn SELECT NULL RETURN END');

This could be a one of runFirstAfterUp script. Is there any better ideas out there for managing deployment - preferably with Roundhouse as we cannot move away from it?

0

There are 0 answers