tags: add tag_versions table.
Add a tag_versions table for tracking the history of tags. A couple notable differences from other version tables: * There is a previous_version_id column that points to the previous version. This allows finding the first, last, previous, or next version efficiently in SQL. * There is a `version` column that tracks the revision number (1, 2, 3, etc). Post versions and note versions have this, but other version tables don't. * The `updater_id` column is optional. This is because we don't know who the last updater was before we started tracking the history of tags, so the initial updater will be NULL in the first version of the tag.
This commit is contained in:
23
db/migrate/20220909211649_create_tag_versions.rb
Normal file
23
db/migrate/20220909211649_create_tag_versions.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class CreateTagVersions < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :tag_versions do |t|
|
||||
t.timestamps
|
||||
t.references :tag, null: false, foreign_key: { to_table: :tags }
|
||||
t.references :updater, null: true, foreign_key: { to_table: :users }
|
||||
t.references :previous_version, null: true, foreign_key: { to_table: :tag_versions }
|
||||
|
||||
t.column :version, :integer, null: false
|
||||
t.column :name, :string, null: false
|
||||
t.column :category, :integer, null: false
|
||||
t.column :is_deprecated, :boolean, null: false
|
||||
|
||||
t.index :name, opclass: :text_pattern_ops
|
||||
t.index :name, name: "index_tag_versions_on_name_trgm", using: :gin, opclass: :gin_trgm_ops
|
||||
t.index :version
|
||||
t.index :category
|
||||
t.index :is_deprecated
|
||||
|
||||
t.index [:tag_id, :previous_version_id], unique: true
|
||||
end
|
||||
end
|
||||
end
|
||||
142
db/structure.sql
142
db/structure.sql
@@ -1884,6 +1884,43 @@ CREATE SEQUENCE public.tag_implications_id_seq
|
||||
ALTER SEQUENCE public.tag_implications_id_seq OWNED BY public.tag_implications.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.tag_versions (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
tag_id bigint NOT NULL,
|
||||
updater_id bigint,
|
||||
previous_version_id bigint,
|
||||
version integer NOT NULL,
|
||||
name character varying NOT NULL,
|
||||
category integer NOT NULL,
|
||||
is_deprecated boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.tag_versions_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.tag_versions_id_seq OWNED BY public.tag_versions.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: tags; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@@ -2578,6 +2615,13 @@ ALTER TABLE ONLY public.tag_aliases ALTER COLUMN id SET DEFAULT nextval('public.
|
||||
ALTER TABLE ONLY public.tag_implications ALTER COLUMN id SET DEFAULT nextval('public.tag_implications_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tag_versions ALTER COLUMN id SET DEFAULT nextval('public.tag_versions_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tags id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -3038,6 +3082,14 @@ ALTER TABLE ONLY public.tag_implications
|
||||
ADD CONSTRAINT tag_implications_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions tag_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tag_versions
|
||||
ADD CONSTRAINT tag_versions_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tags tags_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -4605,6 +4657,69 @@ CREATE INDEX index_tag_implications_on_consequent_name ON public.tag_implication
|
||||
CREATE INDEX index_tag_implications_on_forum_post_id ON public.tag_implications USING btree (forum_post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_category; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_category ON public.tag_versions USING btree (category);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_is_deprecated; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_is_deprecated ON public.tag_versions USING btree (is_deprecated);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_name; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_name ON public.tag_versions USING btree (name text_pattern_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_name_trgm; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_name_trgm ON public.tag_versions USING gin (name public.gin_trgm_ops);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_previous_version_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_previous_version_id ON public.tag_versions USING btree (previous_version_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_tag_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_tag_id ON public.tag_versions USING btree (tag_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_tag_id_and_previous_version_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_tag_versions_on_tag_id_and_previous_version_id ON public.tag_versions USING btree (tag_id, previous_version_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_updater_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_updater_id ON public.tag_versions USING btree (updater_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tag_versions_on_version; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_tag_versions_on_version ON public.tag_versions USING btree (version);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_tags_on_array_to_tsvector_words; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -5131,6 +5246,22 @@ ALTER TABLE ONLY public.forum_posts
|
||||
ADD CONSTRAINT fk_rails_2ddd2b5687 FOREIGN KEY (topic_id) REFERENCES public.forum_topics(id) DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions fk_rails_2e7ebfd4dd; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tag_versions
|
||||
ADD CONSTRAINT fk_rails_2e7ebfd4dd FOREIGN KEY (tag_id) REFERENCES public.tags(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions fk_rails_2eab2fbb85; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tag_versions
|
||||
ADD CONSTRAINT fk_rails_2eab2fbb85 FOREIGN KEY (previous_version_id) REFERENCES public.tag_versions(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: wiki_page_versions fk_rails_2fc7c35d5a; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -5155,6 +5286,14 @@ ALTER TABLE ONLY public.api_keys
|
||||
ADD CONSTRAINT fk_rails_32c28d0dc2 FOREIGN KEY (user_id) REFERENCES public.users(id) DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
|
||||
--
|
||||
-- Name: tag_versions fk_rails_373a0aa141; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tag_versions
|
||||
ADD CONSTRAINT fk_rails_373a0aa141 FOREIGN KEY (updater_id) REFERENCES public.users(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: artist_commentary_versions fk_rails_3b1402ddb3; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@@ -5985,6 +6124,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20220623052547'),
|
||||
('20220627211714'),
|
||||
('20220829184824'),
|
||||
('20220909205433');
|
||||
('20220909205433'),
|
||||
('20220909211649');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user