home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
upgrade_database.tcl
< prev
next >
Wrap
Text File
|
1996-06-03
|
7KB
|
285 lines
#---------------------------------------------------------------------------
#
# (c) Cadre Technologies Inc. 1996
#
# File: %W%
# Author: Harm Leijendeckers
# Description: Upgrade an Ot4OMT-4.0/00 repository database
# structure to an Ot4OMT-4.0/01 repository
#
#---------------------------------------------------------------------------
# SccsId = %W% %G% Copyright 1996 Cadre Technologies Inc.
source [m4_path_name tcl libocl.tcl]
require upgrade_tools.tcl
require upgrade_labels.tcl
proc create_fipropref { tableId } {
catch {
db query "create table fipropref$tableId ("
db query "c_id varchar(64) primary key,"
db query "c_hasacl smallint,"
db query "c_name varchar(80),"
db query "c_type varchar(20),"
db query "c_systemv varchar(64),"
db query "c_status smallint,"
db query "c_reffile varchar(64),"
db query "c_reffilev varchar(64) )"
db run
}
}
proc create_itpropref { tableId } {
catch {
db query "create table itpropref$tableId ("
db query "c_id varchar(64) primary key,"
db query "c_hasacl smallint,"
db query "c_name varchar(80),"
db query "c_type varchar(20),"
db query "c_systemv varchar(64),"
db query "c_proprefst varchar(64),"
db query "c_status smallint,"
db query "c_refobject varchar(64),"
db query "c_refitem varchar(64) )"
db run
}
}
proc create_proprefst { tableId } {
catch {
db query "create table proprefst$tableId ("
db query "c_id varchar(64) primary key,"
db query "c_propref varchar(64) )"
db run
}
}
proc create_proprefl { tableId } {
catch {
db query "create table proprefl$tableId ("
db query "c_id varchar(64) primary key,"
db query "c_hasacl smallint,"
db query "c_owner varchar(64),"
db query "c_hasncacl smallint )"
db run
}
}
proc update_extlink { tableId } {
#add_field extlink$tableId c_name varchar(80) c_systemv
#add_field extlink$tableId c_type varchar(20) c_systemv
db select c_id
db select c_path
db from extlink$tableId
set allLinks [db runLoop]
foreach link $allLinks {
set id [lvarpop link]
set path [lvarpop link]
set name [path_name base $path]
set type [path_name type $path]
db update extlink$tableId
db set -s c_name $name
db set -s c_type $type
db where -s "c_id =" $id
db run
}
}
proc update_sysfiref { tableId } {
#add_field sysfiref$tableId c_name varchar(80) c_systemv
#add_field sysfiref$tableId c_type varchar(20) c_systemv
# new name = 'sysfiref.reffile.item.name'_'sysfiref.reffile.type'
# new type = 'sysfiref.reffile.type'
db select c_id
db select c_reffile
db from sysfiref$tableId
set firefdatas [db runLoop]
foreach firefdata $firefdatas {
set refid [lvarpop firefdata]
set reffile [lvarpop firefdata]
# construct new name
db select -s c_item
db select -s c_type
db from file$tableId
db where -s c_id= $reffile
set result [db run]
set itemid [lvarpop result]
set filetype [lvarpop result]
db select -s c_name
db from item$tableId
db where -s c_id= $itemid
set itemname [db run]
db update sysfiref$tableId
db set -s c_name $itemname\_$filetype
db set -s c_type $filetype
db where -s c_id= $refid
db run
}
}
proc update_systemv { tableId } {
#add_field systemv$tableId c_proprefl varchar(64) c_iscope
db select c_id
db from systemv$tableId
set allSystemVersions [db runLoop]
foreach sv $allSystemVersions {
set newObid [gen_obid PropertyReferenceList $tableId]
db query "update systemv$tableId"
db query "set c_proprefl = '$newObid'"
db query "where c_id = '$sv'"
db run
db query "insert into proprefl$tableId values ("
db query "'$newObid', 1, '$sv', 0 )"
db run
}
}
proc update_release { release } {
db update corporate0
db set -s c_release $release
db run
}
proc upgrade_corporate { release } {
update_release $release
}
proc update_project { tableId projectId } {
puts " Updating tables"
update_extlink $tableId
update_sysfiref $tableId
update_systemv $tableId
set newObid [gen_obid ControlledClass $tableId]
db query "insert into controlc$tableId values ("
db query "'$newObid', 1, 'PropertyReferenceList',"
db query "'PropertyReferenceList', 121, '$projectId' )"
db run
set newObid [gen_obid ControlledClass $tableId]
db query "insert into controlc$tableId values ("
db query "'$newObid', 1, 'FilePropertyReference',"
db query "'FilePropertyReference', 543, '$projectId' )"
db run
set newObid [gen_obid ControlledClass $tableId]
db query "insert into controlc$tableId values ("
db query "'$newObid', 1, 'ItemPropertyReference',"
db query "'ItemPropertyReference', 543, '$projectId' )"
db run
puts " Updating labels"
update_labels $tableId
}
# Update structure of tables for a project
#
proc update_tables { tableId } {
puts " Adding new fields"
add_field systemv$tableId c_proprefl varchar(64) c_iscope
add_field extlink$tableId c_name varchar(80) c_systemv
add_field extlink$tableId c_type varchar(20) c_systemv
add_field sysfiref$tableId c_name varchar(80) c_systemv
add_field sysfiref$tableId c_type varchar(20) c_systemv
add_field systemv$tableId c_proprefl varchar(64) c_iscope
puts " Creating new tables"
create_fipropref $tableId
create_itpropref $tableId
create_proprefst $tableId
create_proprefl $tableId
}
proc upgrade40 {} {
# global var initialization
set from_release Ot4OMT-4.0/00
set to_release Ot4OMT-4.0/01
puts "Upgrading repository structure of database '[db name]'"
puts ""
if ![lempty $argv] {
puts "Usage: dbserver -f upgrade40.tcl <databaseName>"
return 1
}
set this_release [get_release]
# do nothing if the release of the repository is the same as the one
# we're upgrading to
if { $this_release == $to_release } {
puts "Repository is already of release '$to_release'"
return 0
}
if { $this_release != $from_release } {
puts "Can only upgrade from release '$release'"
return 1
}
# SQL Server only:
# update tables outside transaction
#
foreach project [get_projects] {
puts "Upgrading project (structure) '[lvarpop project]'"
set projectId [lvarpop project]
set tableId [lvarpop project]
update_tables $tableId
}
db begin
upgrade_corporate $to_release
foreach project [get_projects] {
puts "Upgrading project (default contents) '[lvarpop project]'"
set projectId [lvarpop project]
set tableId [lvarpop project]
update_project $tableId $projectId
}
db commit
puts ""
puts "Upgrading repository structure finished"
return 0
}
if { [catch { set retval [upgrade40] } string] == 1 } {
puts $errorInfo
exit 1
}
exit $retval