pgslice 0.1.0 → 0.1.1

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: 09c384b3832fb897a3efde949c8d1d9c8e3e2d64
4
- data.tar.gz: 6b28c7e711c74e88683a565af2f7b0b0f3de2f8a
3
+ metadata.gz: 5a7f188ff426286b8fd13dbc359d7bbdf514de64
4
+ data.tar.gz: bf65c37948a1cbd88e072f7c88b20e0cf4b75b1c
5
5
  SHA512:
6
- metadata.gz: 219a357d1eef81483fd613ed19d4e24cfc8ae3c0082a9791f01b3160df9e7d30ec77dac317d25255c76fdeb775425e0cf4c4aa19000bf75e1402e33ba6b48033
7
- data.tar.gz: 073a77f7ab738968c466bbc05ba6b4415b451dd6808b110373844f321d337a671d9a999c4a7ba373d97f531179469204422ec93e3fbd26b742504cc6ca431c49
6
+ metadata.gz: 6cece21cd4d7bb10fcf510fa6ba6a1590ba24faaaf553315c1a0c2f2d734a39b77ac9fa419168eb75a09f6f7851bf1b62ab0f1cb59774daa6832b4a7e6ed3559
7
+ data.tar.gz: 1a820b128546c65a697c32d928955734bac43123af7bc714839530e1bfcb3ce06c61ac7d454caf1e92a2d8a188267dc94910e5ceb25ce0db2b23eb0a0c130cc5
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## 0.1.1
2
+
3
+ - Add sql commands to output
4
+
5
+ ## 0.1.0
6
+
7
+ - First release
data/README.md CHANGED
@@ -4,7 +4,7 @@ Postgres partitioning as easy as pie
4
4
 
5
5
  ## Install
6
6
 
7
- Run
7
+ Run:
8
8
 
9
9
  ```sh
10
10
  gem install pgslice
@@ -64,13 +64,15 @@ gem install pgslice
64
64
 
65
65
  ## Adding Partitions
66
66
 
67
+ To add partitions, use:
68
+
67
69
  ```sh
68
70
  pgslice add_partitions <table> --future 3
69
71
  ```
70
72
 
71
73
  ## Additional Commands
72
74
 
73
- To undo prep and delete partitions, use:
75
+ To undo prep (which will delete partitions), use:
74
76
 
75
77
  ```sh
76
78
  pgslice unprep <table>
data/lib/pgslice.rb CHANGED
@@ -64,26 +64,26 @@ module PgSlice
64
64
  queries = []
65
65
 
66
66
  queries << <<-SQL
67
- CREATE TABLE #{intermediate_table} (
68
- LIKE #{table} INCLUDING INDEXES INCLUDING DEFAULTS
69
- )
67
+ CREATE TABLE #{intermediate_table} (
68
+ LIKE #{table} INCLUDING INDEXES INCLUDING DEFAULTS
69
+ );
70
70
  SQL
71
71
 
72
72
  sql_format = SQL_FORMAT[period.to_sym]
73
73
  queries << <<-SQL
74
- CREATE FUNCTION #{trigger_name}()
75
- RETURNS trigger AS $$
76
- BEGIN
77
- EXECUTE 'INSERT INTO public.#{table}_' || to_char(NEW.#{column}, '#{sql_format}') || ' VALUES ($1.*)' USING NEW;
78
- RETURN NULL;
79
- END;
80
- $$ LANGUAGE plpgsql
74
+ CREATE FUNCTION #{trigger_name}()
75
+ RETURNS trigger AS $$
76
+ BEGIN
77
+ EXECUTE 'INSERT INTO public.#{table}_' || to_char(NEW.#{column}, '#{sql_format}') || ' VALUES ($1.*)' USING NEW;
78
+ RETURN NULL;
79
+ END;
80
+ $$ LANGUAGE plpgsql;
81
81
  SQL
82
82
 
83
83
  queries << <<-SQL
84
- CREATE TRIGGER #{trigger_name}
85
- BEFORE INSERT ON #{intermediate_table}
86
- FOR EACH ROW EXECUTE PROCEDURE #{trigger_name}()
84
+ CREATE TRIGGER #{trigger_name}
85
+ BEFORE INSERT ON #{intermediate_table}
86
+ FOR EACH ROW EXECUTE PROCEDURE #{trigger_name}();
87
87
  SQL
88
88
 
89
89
  run_queries(queries)
@@ -100,8 +100,8 @@ module PgSlice
100
100
  log "Dropping #{intermediate_table}"
101
101
 
102
102
  queries = [
103
- "DROP TABLE #{intermediate_table} CASCADE",
104
- "DROP FUNCTION #{trigger_name}()"
103
+ "DROP TABLE #{intermediate_table} CASCADE;",
104
+ "DROP FUNCTION #{trigger_name}();"
105
105
  ]
106
106
  run_queries(queries)
107
107
  end
@@ -134,10 +134,10 @@ module PgSlice
134
134
  date_format = "%Y-%m-%d"
135
135
 
136
136
  queries << <<-SQL
137
- CREATE TABLE #{partition_name} (
138
- LIKE #{table} INCLUDING INDEXES INCLUDING DEFAULTS,
139
- CHECK (#{field} >= '#{day.strftime(date_format)}'::date AND #{field} < '#{(day + inc).strftime(date_format)}'::date)
140
- ) INHERITS (#{table})
137
+ CREATE TABLE #{partition_name} (
138
+ LIKE #{table} INCLUDING INDEXES INCLUDING DEFAULTS,
139
+ CHECK (#{field} >= '#{day.strftime(date_format)}'::date AND #{field} < '#{(day + inc).strftime(date_format)}'::date)
140
+ ) INHERITS (#{table});
141
141
  SQL
142
142
  end
143
143
 
@@ -209,8 +209,8 @@ module PgSlice
209
209
  log "Renaming #{intermediate_table} to #{table}"
210
210
 
211
211
  queries = [
212
- "ALTER TABLE #{table} RENAME TO #{retired_table}",
213
- "ALTER TABLE #{intermediate_table} RENAME TO #{table}"
212
+ "ALTER TABLE #{table} RENAME TO #{retired_table};",
213
+ "ALTER TABLE #{intermediate_table} RENAME TO #{table};"
214
214
  ]
215
215
  run_queries(queries)
216
216
  end
@@ -229,8 +229,8 @@ module PgSlice
229
229
  log "Renaming #{retired_table} to #{table}"
230
230
 
231
231
  queries = [
232
- "ALTER TABLE #{table} RENAME TO #{intermediate_table}",
233
- "ALTER TABLE #{retired_table} RENAME TO #{table}"
232
+ "ALTER TABLE #{table} RENAME TO #{intermediate_table};",
233
+ "ALTER TABLE #{retired_table} RENAME TO #{table};"
234
234
  ]
235
235
  run_queries(queries)
236
236
  end
@@ -259,7 +259,7 @@ module PgSlice
259
259
 
260
260
  # output
261
261
 
262
- def log(message)
262
+ def log(message = nil)
263
263
  $stderr.puts message
264
264
  end
265
265
 
@@ -294,7 +294,11 @@ module PgSlice
294
294
  def run_queries(queries)
295
295
  connection.transaction do
296
296
  execute("SET client_min_messages TO warning")
297
- queries.map(&:squish).each do |query|
297
+ log
298
+ log "============================== SQL =============================="
299
+ queries.each do |query|
300
+ log
301
+ log query
298
302
  execute(query)
299
303
  end
300
304
  end
@@ -1,3 +1,3 @@
1
1
  module PgSlice
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgslice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-24 00:00:00.000000000 Z
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -89,6 +89,7 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - README.md
94
95
  - Rakefile