Skip to content

Incorrect models generated for Postgresql #18

@shapiro2

Description

@shapiro2

RMRE is generating invalid models for postgresql when there are tables with the same names in multiple schemas that have foreign keys from one schema to another. The specifics are

I have tables in schema called "acct" and "merge". The ones in "merge" have FK into the table in "acct". I am asking RMRE to generate models for only the tables in "acct" (see rmre.yml below), but it sees the FK from "models" to the "acct" tables.


CREATE TABLE acct.people
(
  person_id serial NOT NULL,
  first_name character varying(100),
  middle_name character varying(60),
  last_name character varying(100) NOT NULL,
  CONSTRAINT pk_people PRIMARY KEY (person_id)
);

CREATE TABLE acct.people_map
(
  people_map_id serial NOT NULL,
  person_id integer NOT NULL,
  organization_id integer NOT NULL,
  site_person_id text NOT NULL,
  CONSTRAINT pk_people_map PRIMARY KEY  (people_map_id),
  CONSTRAINT fk1_people_map FOREIGN KEY (organization_id) REFERENCES acct.organizations (organization_id),
  CONSTRAINT fk2_people_map FOREIGN KEY (person_id) REFERENCES acct.people (person_id)
);

CREATE TABLE acct.organizations
(
  organization_id serial NOT NULL,
  organization_name text NOT NULL,
  CONSTRAINT pk_organizations PRIMARY KEY (organization_id)
)


CREATE TABLE merge.people
(
  id serial NOT NULL,
  keep_person_id integer NOT NULL,
  delete_person_id integer NOT NULL,
  CONSTRAINT people_pk PRIMARY KEY (id)
);

CREATE TABLE merge.people_map
(
  id integer NOT NULL,
  organization_id integer NOT NULL,
  keep_site_person_id text NOT NULL,
  delete_site_person_id text NOT NULL,
  CONSTRAINT people_map_pk PRIMARY KEY (id, organization_id),
  CONSTRAINT people_map_fk1 FOREIGN KEY (id) REFERENCES merge.people (id),
  CONSTRAINT people_map_fk2 FOREIGN KEY (organization_id) REFERENCES acct.organizations (organization_id)
);


=== rmre.yml
db:
  :adapter: postgresql
  :host: <host>
  :username: <username>
  :password: <passwd>
  :timeout: 5000
  :database: <db>
  :schema_search_path: "acct"

=== models generated by RMRM

=== person.rb
class Person < ActiveRecord::Base
    self.primary_key = :person_id

    has_many :people_maps, :class_name => 'PeopleMap', :foreign_key => :person_id    
    has_many :people_maps, :class_name => 'PeopleMap'    
end

=== people_map.rb
class PeopleMap < ActiveRecord::Base
    self.table_name = 'people_map'
    self.primary_key = :people_map_id

    belongs_to :organization, :class_name => 'Organization', :foreign_key => :organization_id    
    belongs_to :person, :class_name => 'Person', :foreign_key => :person_id    
    belongs_to :person, :class_name => 'Person', :foreign_key => :id 
    belongs_to :organization, :class_name => 'Organization', :foreign_key => :organization_id    
end

=== organization.rb
class Organization < ActiveRecord::Base
    self.primary_key = :organization_id

    has_many :people_maps, :class_name => 'PeopleMap', :foreign_key => :organization_id    
    has_many :people, :class_name => 'Person', :foreign_key => :organization_id    
    has_many :people_maps, :class_name => 'PeopleMap', :foreign_key => :organization_id    
end

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions