From 2aa3cabf1b737e225178230882ee9aadfd817ce0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 28 Mar 2013 16:04:48 +0200 Subject: Add changelog support for add/drop index/foreign key Also diagnose changes to primary keys and establish the 'alters' association. --- odb/semantics/relational/elements.cxx | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'odb/semantics/relational/elements.cxx') diff --git a/odb/semantics/relational/elements.cxx b/odb/semantics/relational/elements.cxx index e14bc00..d83bff7 100644 --- a/odb/semantics/relational/elements.cxx +++ b/odb/semantics/relational/elements.cxx @@ -45,23 +45,36 @@ namespace semantics { typename names_list::iterator i; - // We want the order to be columns first, then the primary key, - // and then the foreign keys. + // We want the order to be add/alter columns first, then the + // primary key, then other keys, and finnally drop columns. // - if (n.is_a ()) + if (n.is_a () || + n.is_a () || + n.is_a ()) + { i = names_.insert (first_key_, &e); - else + } + else if (!n.is_a ()) { if (n.is_a ()) - first_key_ = i = names_.insert (first_key_, &e); + first_key_ = i = names_.insert ( + first_key_ != names_.end () ? first_key_ : first_drop_column_, + &e); else { - i = names_.insert (names_.end (), &e); + i = names_.insert (first_drop_column_, &e); if (first_key_ == names_.end ()) first_key_ = i; } } + else + { + i = names_.insert (names_.end (), &e); + + if (first_drop_column_ == names_.end ()) + first_drop_column_ = i; + } names_map_[name] = i; iterator_map_[&e] = i; @@ -83,6 +96,11 @@ namespace semantics if (first_key_ == i->second) first_key_++; + // The same for the first drop column. + // + if (first_drop_column_ == i->second) + first_drop_column_++; + names_.erase (i->second); names_map_.erase (e.name ()); iterator_map_.erase (i); @@ -106,6 +124,14 @@ namespace semantics // insert (type_info (typeid (edge))); + // alters + // + { + type_info ti (typeid (alters)); + ti.add_base (typeid (edge)); + insert (ti); + } + // names // { -- cgit v1.1