pgslice 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 595fd1ef4439e8f5180ee6f84596c088124cf900
4
- data.tar.gz: 6a7144e70f93c4edeb7b48be0efe28e6ccfd87f9
3
+ metadata.gz: 27fdf533604b2635d75b2eb92043617f8a53ed7a
4
+ data.tar.gz: 5f5579762fdfe759f38a4eb03cce91acb90a7397
5
5
  SHA512:
6
- metadata.gz: ffb023c7ceacab8f0362808131a6a8d680455d756ab636f558257390c68b20214edf2ad4eefb3dd6f5fb46b9a9b7a8eb264fa070ffc4fca34e051c9b069ca66f
7
- data.tar.gz: 44869b8f950334d8db95a9a081937966367e1cac30caa5ce03254b694f54f893f04a429f935e2f6a80487465c5283005f280512ac3b600f027a2f9fd87d4ec16
6
+ metadata.gz: ac1abb9261c93e8b0bf057b6b16fd1a864f3e2ddd9b85f196df095731fbbbdac0b49e3878b966632c15ce9d7c6774d64231dc03d2e4a42b74fd185ffc177a8b5
7
+ data.tar.gz: 9524851474990255e54c008477db65de535fcea6412900ea0c68a801518a79b7124175cde7cddd5e932a6575c76d282047642d7c8f4016e6cce13fd703a90877
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.3
2
+
3
+ - Fixed table inheritance
4
+
1
5
  ## 0.1.2
2
6
 
3
7
  - Added `--dry-run` option
data/README.md CHANGED
@@ -93,7 +93,7 @@ $ pgslice prep locations created_at day
93
93
  BEGIN;
94
94
 
95
95
  CREATE TABLE locations_intermediate (
96
- LIKE locations INCLUDING INDEXES INCLUDING DEFAULTS
96
+ LIKE locations INCLUDING ALL
97
97
  );
98
98
 
99
99
  CREATE FUNCTION locations_insert_trigger()
@@ -116,20 +116,29 @@ $ pgslice add_partitions locations --intermediate --past 1 --future 1
116
116
  BEGIN;
117
117
 
118
118
  CREATE TABLE locations_20160423 (
119
- LIKE locations_intermediate INCLUDING INDEXES INCLUDING DEFAULTS,
120
119
  CHECK (created_at >= '2016-04-23'::date AND created_at < '2016-04-24'::date)
121
120
  ) INHERITS (locations_intermediate);
122
121
 
122
+ ALTER TABLE locations_20160423 ADD PRIMARY KEY (id);
123
+
124
+ CREATE INDEX ON locations_20160423 USING btree (updated_at, shopper_id);
125
+
123
126
  CREATE TABLE locations_20160424 (
124
- LIKE locations_intermediate INCLUDING INDEXES INCLUDING DEFAULTS,
125
127
  CHECK (created_at >= '2016-04-24'::date AND created_at < '2016-04-25'::date)
126
128
  ) INHERITS (locations_intermediate);
127
129
 
130
+ ALTER TABLE locations_20160424 ADD PRIMARY KEY (id);
131
+
132
+ CREATE INDEX ON locations_20160424 USING btree (updated_at, shopper_id);
133
+
128
134
  CREATE TABLE locations_20160425 (
129
- LIKE locations_intermediate INCLUDING INDEXES INCLUDING DEFAULTS,
130
135
  CHECK (created_at >= '2016-04-25'::date AND created_at < '2016-04-26'::date)
131
136
  ) INHERITS (locations_intermediate);
132
137
 
138
+ ALTER TABLE locations_20160425 ADD PRIMARY KEY (id);
139
+
140
+ CREATE INDEX ON locations_20160425 USING btree (updated_at, shopper_id);
141
+
133
142
  COMMIT;
134
143
  ```
135
144
 
@@ -159,6 +168,11 @@ gem install specific_install
159
168
  gem specific_install ankane/pgslice
160
169
  ```
161
170
 
171
+ ## TODO
172
+
173
+ - Command to sync index changes with partitions
174
+ - Disable indexing for faster `fill`
175
+
162
176
  ## Contributing
163
177
 
164
178
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
@@ -1,3 +1,3 @@
1
1
  module PgSlice
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/pgslice.rb CHANGED
@@ -63,7 +63,7 @@ module PgSlice
63
63
 
64
64
  queries << <<-SQL
65
65
  CREATE TABLE #{intermediate_table} (
66
- LIKE #{table} INCLUDING INDEXES INCLUDING DEFAULTS
66
+ LIKE #{table} INCLUDING ALL
67
67
  );
68
68
  SQL
69
69
 
@@ -122,6 +122,9 @@ FOR EACH ROW EXECUTE PROCEDURE #{trigger_name}();
122
122
  days = range.map { |n| today + (n * inc) }
123
123
  queries = []
124
124
 
125
+ index_defs = execute("select pg_get_indexdef(indexrelid) from pg_index where indrelid = $1::regclass AND indisprimary = 'f'", [original_table]).map { |r| r["pg_get_indexdef"] }
126
+ primary_key = self.primary_key(table)
127
+
125
128
  days.each do |day|
126
129
  partition_name = "#{original_table}_#{day.strftime(name_format)}"
127
130
  next if table_exists?(partition_name)
@@ -130,10 +133,15 @@ FOR EACH ROW EXECUTE PROCEDURE #{trigger_name}();
130
133
 
131
134
  queries << <<-SQL
132
135
  CREATE TABLE #{partition_name} (
133
- LIKE #{table} INCLUDING INDEXES INCLUDING DEFAULTS,
134
136
  CHECK (#{field} >= '#{day.strftime(date_format)}'::date AND #{field} < '#{(day + inc).strftime(date_format)}'::date)
135
137
  ) INHERITS (#{table});
136
138
  SQL
139
+
140
+ queries << "ALTER TABLE #{partition_name} ADD PRIMARY KEY (#{primary_key});"
141
+
142
+ index_defs.each do |index_def|
143
+ queries << index_def.sub(" ON #{original_table} USING ", " ON #{partition_name} USING ").sub(/ INDEX .+ ON /, " INDEX ON ") + ";"
144
+ end
137
145
  end
138
146
 
139
147
  run_queries(queries) if queries.any?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgslice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane