Index: openacs-4/packages/acs-admin/tcl/apm-admin-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/tcl/apm-admin-init.tcl,v diff -u -r1.2.16.1 -r1.2.16.2 --- openacs-4/packages/acs-admin/tcl/apm-admin-init.tcl 8 Sep 2014 07:24:34 -0000 1.2.16.1 +++ openacs-4/packages/acs-admin/tcl/apm-admin-init.tcl 19 Sep 2014 13:41:07 -0000 1.2.16.2 @@ -20,14 +20,15 @@ ns_register_filter trace GET /repository/* repository-download if {[info commands ::xo::db::require] ne ""} { - ::xo::db::require table apm_package_downloads \ - "time timestamp, - ip text, - user_id integer, - channel text, - package text, - version text, - url text" + ::xo::db::require table apm_package_downloads { + time timestamp + ip text + user_id integer + channel text + package text + version text + url text + } ad_proc ::repository_log_to_db {} { set ip [ns_conn peeraddr] Index: openacs-4/packages/xotcl-core/tcl/05-db-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-core/tcl/05-db-procs.tcl,v diff -u -r1.97.2.17 -r1.97.2.18 --- openacs-4/packages/xotcl-core/tcl/05-db-procs.tcl 10 Sep 2014 13:54:53 -0000 1.97.2.17 +++ openacs-4/packages/xotcl-core/tcl/05-db-procs.tcl 19 Sep 2014 13:41:06 -0000 1.97.2.18 @@ -643,15 +643,17 @@ # ::xotcl::Object create require - #require set postgresql_table_exists {select 1 from pg_tables where tablename = :name} - require set postgresql_table_exists {select 1 from pg_class where relname = :name and\ - pg_table_is_visible(oid)} - require set postgresql_view_exists {select 1 from pg_views where viewname = :name} - require set postgresql_index_exists {select 1 from pg_indexes where indexname = :name} - require set oracle_table_exists {select 1 from user_tables where table_name = :name} - require set oracle_view_exists {select 1 from user_views where view_name = :name} - require set oracle_index_exists {select 1 from user_indexes where index_name = :name} + require set postgresql_table_exists {select 1 from pg_class where relname = :name and pg_table_is_visible(oid)} + require set postgresql_column_exists {select 1 from information_schema.columns + where table_name = :table_name and column_name = :column_name} + require set postgresql_view_exists {select 1 from pg_views where viewname = :name} + require set postgresql_index_exists {select 1 from pg_indexes where indexname = :name} + require set oracle_table_exists {select 1 from user_tables where table_name = :name} + require set oracle_column_exists {select 1 from user_tab_columns where table_name = :table_name and column_name = :column_name} + require set oracle_view_exists {select 1 from user_views where view_name = :name} + require set oracle_index_exists {select 1 from user_indexes where index_name = :name} + require proc exists_table {name} { if {[db_driverkey ""] eq "oracle"} { set name [string toupper $name] @@ -661,10 +663,34 @@ ::xo::dc 0or1row "" [subst [my set [db_driverkey ""]_table_exists]] } + require proc exists_column {table_name column_name} { + if {[db_driverkey ""] eq "oracle"} { + set table_name [string toupper $table_name] + set column_name [string toupper $column_name] + } else { + set table_name [string tolower $table_name] + set column_name [string tolower $column_name] + } + ::xo::dc 0or1row "" [subst [my set [db_driverkey ""]_column_exists]] + } + require proc table {name definition} { if {![my exists_table $name]} { + set lines {} + foreach col [dict keys $definition] {append lines "$col [dict get $definition $col]"} + set definiition [join $lines ",\n"] #my log "--table $name does not exist, creating with $definition" ::xo::dc dml create-table-$name "create table $name ($definition)" + } else { + # The table exists already. Check the colums, whether we have to + # add columns. We do not alter attribute types, and we do not + # delete columns. + foreach col [dict keys $definition] { + if {![my exists_column $name $col]} { + ::xo::dc dml alter-table-$name \ + "alter table $name add column $col [dict get $definition $col]" + } + } } } @@ -1590,8 +1616,8 @@ error "no ::xo::db::Attribute slot for id_column '$id_column' specified" } set table_specs [list] - foreach {att spec} [array get column_specs] {lappend table_specs " $att $spec"} - set table_definition [join $table_specs ",\n"] + foreach {att spec} [array get column_specs] {lappend table_specs $att $spec} + set table_definition $table_specs } else { set table_definition "" } Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v diff -u -r1.472.2.21 -r1.472.2.22 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 3 Sep 2014 12:25:50 -0000 1.472.2.21 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 19 Sep 2014 13:41:06 -0000 1.472.2.22 @@ -148,32 +148,36 @@ ::xo::db::require index -table xowiki_form_page -col assignee ::xo::db::require index -table xowiki_page_instance -col page_template - ::xo::db::require table xowiki_references \ - "reference integer references cr_items(item_id) on delete cascade, - link_type [::xo::dc map_datatype text], - page integer references cr_items(item_id) on delete cascade" + ::xo::db::require table xowiki_references [subst { + reference {integer references cr_items(item_id) on delete cascade} + link_type {[::xo::dc map_datatype text]} + page {integer references cr_items(item_id) on delete cascade} + }] ::xo::db::require index -table xowiki_references -col reference - ::xo::db::require table xowiki_last_visited \ - "page_id integer references cr_items(item_id) on delete cascade, - package_id integer, - user_id integer, - count integer, - time timestamp" + ::xo::db::require table xowiki_last_visited { + page_id {integer references cr_items(item_id) on delete cascade} + package_id integer + user_id integer + count integer + time timestamp + } + ::xo::db::require index -table xowiki_last_visited -col user_id,page_id -unique true ::xo::db::require index -table xowiki_last_visited -col user_id,package_id ::xo::db::require index -table xowiki_last_visited -col time # Oracle has a limit of 3118 characters for keys, therefore we # cannot use "text" as type for "tag" - ::xo::db::require table xowiki_tags \ - "item_id integer references cr_items(item_id) on delete cascade, - package_id integer, - user_id integer references users(user_id), - tag varchar(3000), - time timestamp" + ::xo::db::require table xowiki_tags { + item_id {integer references cr_items(item_id) on delete cascade} + package_id integer + user_id {integer references users(user_id)} + tag varchar(3000) + time timestamp + } ::xo::db::require index -table xowiki_tags -col user_id,item_id ::xo::db::require index -table xowiki_tags -col tag,package_id ::xo::db::require index -table xowiki_tags -col user_id,package_id @@ -208,10 +212,11 @@ # number of sequences (in PostgresSQL or Oracle), the database # dependencies would be larger than in this simple approach. # - ::xo::db::require table xowiki_autonames \ - "parent_id integer references acs_objects(object_id) ON DELETE CASCADE, - name varchar(3000), - count integer" + ::xo::db::require table xowiki_autonames { + parent_id "integer references acs_objects(object_id) ON DELETE CASCADE" + name varchar(3000) + count integer + } ::xo::db::require index -table xowiki_autonames -col parent_id,name -unique true ::xotcl::Object create autoname