Promoting from Dev to Prod using OMB*Plus

The other day I posted an article on migrating OWB modules to production, and I said that I'd come back shortly with some OMB*Plus code to automate the migration process. As good as my word, I'm now back with the said code.

In this example, we have a module called "CUSTOMERS" in an OWB10gR2 proiject called "PRODUCTION_EXAMPLES". The project is held in a "development" repository called "OWB_REPOS". Taking a look at the module, it contains a single table and a single mapping.<

The module is linked to a location called CUS_DEV_LOCATION, which points to a database target schema called CUS_DEV.

What I want to do now is to migrate this development project to another repository, called OWB_REPOS_PROD. This contains a location called CUS_PROD_LOCATION, which points to another target schema called CUS_PROD. I don't create the database module though, as I want the migration process to do this instead. The production project now looks like this:

Prod Project

I want to automate the migration process using OMB*Plus, to remove any chance of human error in importing, exporting and then deploying objects.

The OMB*Plus script to do this is as follows. Note the bits around altering the module to use the "production" location - when you import modules into a repository using an MDL file, you lose the locations that originally pointed to it, as they are owned by the other repository (repositories, or to be more correct control centers, own locations, not modules). We therefore have to assign a location to the module, alter the module to make this the deployment location, and then register the location before we can move on to the deployment. Anyway, here's the code. (warning - Wordpress removes all the backslash 'new line' characters from the script, you'll need to add these yourself if you split OMB commands over multiple lines.)

puts "connecting to owb_repos repository"
OMBCONNECT owb_repos/password@winxpvm:1521:ora10g

puts "exporting PRODUCTION_EXAMPLES/CUSTOMERS module to MDL file"
OMBEXPORT MDL_FILE 'c:customers.mdl'
FROM PROJECT 'PRODUCTION_EXAMPLES'
COMPONENTS (ORACLE_MODULE 'CUSTOMERS')
OUTPUT LOG TO 'c:customers.log'

puts "repository exported ok"
OMBDISCONNECT

puts "disconnected from owb_repos"
puts "connecting to owb_repos_prod"
OMBCONNECT owb_repos_prod/password@winxpvm:1521:ora10g

puts "importing CUSTOMERS module from MDL file"
OMBIMPORT MDL_FILE 'c:customers.mdl' USE UPDATE_MODE
MATCH_BY NAMES OUTPUT LOG TO 'c:customers.log'

puts "Changing context to the PRODUCTION_EXAMPLES project"
OMBCC 'PRODUCTION_EXAMPLES'

puts "Connecting to the DEFAULT_CONTROL_CENTER"
OMBCONNECT CONTROL_CENTER

OMBCOMMIT

puts "setting connection details for CUS_PROD_LOCATION location"

OMBALTER LOCATION 'CUS_PROD_LOCATION'
SET PROPERTIES (PASSWORD) VALUES ('PASSWORD')

puts "setting CUS_PROD_LOCATION as default location for CUSTOMERS"

OMBALTER ORACLE_MODULE 'CUSTOMERS'
ADD REFERENCE LOCATION 'CUS_PROD_LOCATION'
SET AS DEFAULT

OMBALTER ORACLE_MODULE 'CUSTOMERS'
SET PROPERTIES (DB_LOCATION)
VALUES ('CUS_PROD_LOCATION')

OMBCOMMIT

puts "registering CUS_PROD location"

OMBREGISTER LOCATION 'CUS_PROD_LOCATION'

puts "Setting contect to CUSTOMERS module"

OMBCC 'CUSTOMERS'

puts "deploying tables"

set tabList [ OMBLIST TABLES]

foreach tabName $tabList {
	puts "deploying: $tabName"

	OMBCREATE TRANSIENT
             DEPLOYMENT_ACTION_PLAN 'DEPLOY_PLAN'
	ADD ACTION 'TABLE_DEPLOY'
            SET PROPERTIES (OPERATION)
	VALUES ('REPLACE') SET REFERENCE TABLE
	'$tabName'
	OMBDEPLOY DEPLOYMENT_ACTION_PLAN 'DEPLOY_PLAN'
	OMBDROP DEPLOYMENT_ACTION_PLAN 'DEPLOY_PLAN'
	OMBCOMMIT
}

puts "tables deployed"
puts "deploying mappings"

set mapList [ OMBLIST MAPPINGS ]

foreach mapName $mapList {
	puts "deploying: $mapName"

	OMBCREATE TRANSIENT DEPLOYMENT_ACTION_PLAN
            'DEPLOY_PLAN'
	ADD ACTION 'MAPPING_DEPLOY' SET
            PROPERTIES (OPERATION)
	VALUES ('CREATE') SET
            REFERENCE MAPPING '$mapName'
	OMBDEPLOY DEPLOYMENT_ACTION_PLAN 'DEPLOY_PLAN'
	OMBDROP DEPLOYMENT_ACTION_PLAN 'DEPLOY_PLAN'
	OMBCOMMIT
}
OMBCC '..'

puts "mappings deployed"
puts "promotion to production complete"

OMBDISCONNECT


Now, when I run the OMB*Plus script, I get the following console output:


connecting to owb_repos repository
exporting PRODUCTION_EXAMPLES/CUSTOMERS module to MDL file
repository exported ok
disconnected from owb_repos
connecting to owb_repos_prod
importing CUSTOMERS mno from MDL file
Changing context to the PRODUCTION_EXAMPLES project
Connecting to the DEFAULT_CONTROL_CENTER
setting connection details for CUS_PROD_LOCATION location
setting CUS_PROD_LOCATION as default location for CUSTOMERS
registering CUS_PROD location
Setting contect to CUSTOMERS module
deploying tables
deploying: CUST_LIST
tables deployed
deploying mappings
deploying: MAP_CUST_LIST
mappings deployed
promotion to production complete

I'd like to say I worked it out in five minutes, but the bits around altering the module to use the production location, and then altering it again to make the DB_LOCATION property set to the same location, that took me a while to work out. I also found the process worked best when I used the Design Center GUI to create the production locations first (usually when creating the production database schema, and then registering it as a target schema), but other than that, it works fine and allows me to promote a module from development to production.