* Denormalized post versions. Testing has shown it reduces the size
of the table 66%.
This commit is contained in:
@@ -1013,6 +1013,38 @@ CREATE SEQUENCE pools_id_seq
|
||||
ALTER SEQUENCE pools_id_seq OWNED BY pools.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_histories; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE post_histories (
|
||||
id integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
post_id integer NOT NULL,
|
||||
revisions text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_histories_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE post_histories_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MAXVALUE
|
||||
NO MINVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_histories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE post_histories_id_seq OWNED BY post_histories.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_moderation_details; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -1045,42 +1077,6 @@ CREATE SEQUENCE post_moderation_details_id_seq
|
||||
ALTER SEQUENCE post_moderation_details_id_seq OWNED BY post_moderation_details.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE post_versions (
|
||||
id integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
post_id integer NOT NULL,
|
||||
source character varying(255),
|
||||
rating character(1) DEFAULT 'q'::bpchar NOT NULL,
|
||||
tag_string text NOT NULL,
|
||||
updater_id integer NOT NULL,
|
||||
updater_ip_addr inet NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE post_versions_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MAXVALUE
|
||||
NO MINVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE post_versions_id_seq OWNED BY post_versions.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_votes; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -1812,14 +1808,14 @@ ALTER TABLE pools ALTER COLUMN id SET DEFAULT nextval('pools_id_seq'::regclass);
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE post_moderation_details ALTER COLUMN id SET DEFAULT nextval('post_moderation_details_id_seq'::regclass);
|
||||
ALTER TABLE post_histories ALTER COLUMN id SET DEFAULT nextval('post_histories_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE post_versions ALTER COLUMN id SET DEFAULT nextval('post_versions_id_seq'::regclass);
|
||||
ALTER TABLE post_moderation_details ALTER COLUMN id SET DEFAULT nextval('post_moderation_details_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
@@ -2137,6 +2133,14 @@ ALTER TABLE ONLY pools
|
||||
ADD CONSTRAINT pools_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_histories_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY post_histories
|
||||
ADD CONSTRAINT post_histories_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_moderation_details_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2145,14 +2149,6 @@ ALTER TABLE ONLY post_moderation_details
|
||||
ADD CONSTRAINT post_moderation_details_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY post_versions
|
||||
ADD CONSTRAINT post_versions_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_votes_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2712,6 +2708,13 @@ CREATE INDEX index_pools_on_creator_id ON pools USING btree (creator_id);
|
||||
CREATE INDEX index_pools_on_name ON pools USING btree (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_histories_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_histories_on_post_id ON post_histories USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_moderation_details_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -2726,20 +2729,6 @@ CREATE INDEX index_post_moderation_details_on_post_id ON post_moderation_details
|
||||
CREATE INDEX index_post_moderation_details_on_user_id ON post_moderation_details USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_versions_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_versions_on_post_id ON post_versions USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_versions_on_updater_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_versions_on_updater_id ON post_versions USING btree (updater_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_posts_on_created_at; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
16
db/migrate/20100205163027_create_post_histories.rb
Normal file
16
db/migrate/20100205163027_create_post_histories.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class CreatePostHistories < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :post_histories do |t|
|
||||
t.timestamps
|
||||
|
||||
t.column :post_id, :integer, :null => false
|
||||
t.column :revisions, :text, :null => false
|
||||
end
|
||||
|
||||
add_index :post_histories, :post_id
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :post_histories
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
class CreatePostVersions < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :post_versions do |t|
|
||||
t.timestamps
|
||||
|
||||
# Post
|
||||
t.column :post_id, :integer, :null => false
|
||||
|
||||
# Versioned
|
||||
t.column :source, :string
|
||||
t.column :rating, :character, :null => false, :default => 'q'
|
||||
t.column :tag_string, :text, :null => false
|
||||
|
||||
# Updater
|
||||
t.column :updater_id, :integer, :null => false
|
||||
t.column :updater_ip_addr, "inet", :null => false
|
||||
end
|
||||
|
||||
add_index :post_versions, :post_id
|
||||
add_index :post_versions, :updater_id
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :post_versions
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user