chronomodel icon indicating copy to clipboard operation
chronomodel copied to clipboard

Missing index on historical table when using `t.reference` or `index: true`

Open tagliala opened this issue 2 years ago • 0 comments

Ruby: 3.0 Rails: 7.0 ChronoModel: master branch

migration

enable_extension :btree_gist

create_table :countries, temporal: true do |t|
  t.string :name
end

create_table :cities, temporal: true do |t|
  t.references :country
  t.string :name
end

Expected result

--
-- Name: index_cities_on_country_id; Type: INDEX; Schema: history; Owner: -
--

CREATE INDEX index_cities_on_country_id ON history.cities USING btree (country_id);

--
-- Name: index_cities_on_country_id; Type: INDEX; Schema: temporal; Owner: -
--

CREATE INDEX index_cities_on_country_id ON temporal.cities USING btree (country_id);

Actual result

--
-- Name: index_cities_on_country_id; Type: INDEX; Schema: temporal; Owner: -
--

CREATE INDEX index_cities_on_country_id ON temporal.cities USING btree (country_id);

Workaround

Create the index manually

create_table :countries, temporal: true do |t|
  t.string :name
end

create_table :cities, temporal: true do |t|
  t.references :country, index: false
  t.string :name
end

add_index :cities, :country_id

tagliala avatar Jun 20 '22 12:06 tagliala