postshift 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/postshift.rb +13 -0
- data/lib/postshift/railtie.rb +5 -0
- data/lib/postshift/schema.rb +100 -0
- data/lib/postshift/version.rb +1 -1
- data/lib/tasks/schema.rake +28 -0
- data/lib/tasks/v_generate_tbl_ddl.sql +254 -0
- data/lib/tasks/v_generate_view_ddl.sql +19 -0
- data/postshift.gemspec +3 -3
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e91aea35f8015bd2dd96fdc881a749296153c051
|
4
|
+
data.tar.gz: 035a9e661aea4d78da25d6cc93febc05278fd766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f7b617a18904e274f57cbb73a75d2da9ccf48a225dd242729b8ce44caf278fd46aaf076864a139c4f14817f071c36c9b5faa73309541c9a299e026ff51ba996
|
7
|
+
data.tar.gz: 293edceeacae0d92e9b6e9d26b41807ffcb750cc48f78b18909dca5aa971895d37defc4a6843f0f525ad17c1029736f1b715f80e0c2ae9da91d8f44f8e082484
|
data/README.md
CHANGED
@@ -67,6 +67,25 @@ end
|
|
67
67
|
For more information on compression types:
|
68
68
|
<http://docs.aws.amazon.com/redshift/latest/dg/c_Compression_encodings.html>
|
69
69
|
|
70
|
+
## Schema Dump
|
71
|
+
|
72
|
+
Several Rake tasks exist to help with performing a schema dump of an existing Redshift database. These utilize the [admin scripts provided by Amazon](https://github.com/awslabs/amazon-redshift-utils/tree/master/src/AdminViews). All actions are performed using `ActiveRecord::Base.connection` by default.
|
73
|
+
|
74
|
+
These views **must** exist within the Redshift database under the **admin** schema prior to any _dump_ or _restore_ actions. To generate, simple run:
|
75
|
+
|
76
|
+
```
|
77
|
+
rake postshift:schema:prepare
|
78
|
+
```
|
79
|
+
|
80
|
+
Once these views are in place, the _dump_ and _restore_ will be available and functional.
|
81
|
+
|
82
|
+
|
83
|
+
```
|
84
|
+
rake postshift:schema:dump
|
85
|
+
rake postshift:schema:restore
|
86
|
+
```
|
87
|
+
|
88
|
+
|
70
89
|
## Development
|
71
90
|
|
72
91
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/postshift.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
require 'postshift/version'
|
2
|
+
require 'postshift/railtie' if defined?(Rails)
|
3
|
+
require 'postshift/schema'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext/module/attribute_accessors_per_thread'
|
2
6
|
require 'active_record/connection_adapters/redshift_adapter'
|
3
7
|
|
4
8
|
module Postshift
|
9
|
+
thread_mattr_accessor :adapter
|
10
|
+
|
11
|
+
def self.root
|
12
|
+
File.dirname __dir__
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.connection
|
16
|
+
adapter.respond_to?(:raw_connection) ? adapter.raw_connection : nil
|
17
|
+
end
|
5
18
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Postshift
|
2
|
+
module Schema
|
3
|
+
FILENAME = 'postshift_schema.sql'.freeze
|
4
|
+
ADMIN_UTILITIES = %w(v_generate_tbl_ddl v_generate_view_ddl).freeze
|
5
|
+
|
6
|
+
def self.ensure_admin_schema
|
7
|
+
Postshift.connection.exec('CREATE SCHEMA IF NOT EXISTS admin')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.create_admin_utilities!
|
11
|
+
ensure_admin_schema
|
12
|
+
ADMIN_UTILITIES.each do |table_name|
|
13
|
+
Postshift.connection.exec(generate_ddl_sql(table_name))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.remove_admin_utilities!
|
18
|
+
ensure_admin_schema
|
19
|
+
ADMIN_UTILITIES.each do |table_name|
|
20
|
+
Postshift.connection.exec("DROP VIEW IF EXISTS admin.#{table_name}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.admin_uilities_exists?
|
25
|
+
ensure_admin_schema
|
26
|
+
ADMIN_UTILITIES.each do |table_name|
|
27
|
+
Postshift.connection.exec("SELECT 'admin.#{table_name}'::regclass;")
|
28
|
+
end
|
29
|
+
true
|
30
|
+
rescue PG::UndefinedTable
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.generate_ddl_sql(table_name)
|
35
|
+
path = File.join(Postshift.root, 'lib', 'tasks', "#{table_name}.sql")
|
36
|
+
File.open(path).read
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.dump
|
40
|
+
File.open(output_location, 'w+') do |file|
|
41
|
+
ddl_results(tbl_ddl_sql).each_row do |row|
|
42
|
+
file.puts(row)
|
43
|
+
end
|
44
|
+
ddl_results(view_ddl_sql).each_row do |row|
|
45
|
+
file.puts(row)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.dump_sql
|
51
|
+
if File.exist?(output_location)
|
52
|
+
File.read(output_location)
|
53
|
+
else
|
54
|
+
puts 'Postshift Schema Dump file does not exist. Run task postshift:schema:dump'
|
55
|
+
false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.restore
|
60
|
+
sql = dump_sql
|
61
|
+
Postshift.connection.exec(sql) if sql.present?
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.ddl_results(ddl_sql)
|
65
|
+
Postshift.connection.exec(ddl_sql, schemas)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.output_location
|
69
|
+
if defined?(Rails)
|
70
|
+
File.join(Rails.root, 'db', FILENAME)
|
71
|
+
else
|
72
|
+
base_path = File.join(Postshift.root, 'tmp')
|
73
|
+
Dir.mkdir(base_path) unless Dir.exist?(base_path)
|
74
|
+
File.join(base_path, FILENAME)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.schemas
|
79
|
+
%w(public)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.tbl_ddl_sql
|
83
|
+
<<-SQL
|
84
|
+
SELECT ddl
|
85
|
+
FROM admin.v_generate_tbl_ddl
|
86
|
+
WHERE schemaname IN ($1)
|
87
|
+
ORDER BY tablename ASC, seq ASC
|
88
|
+
SQL
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.view_ddl_sql
|
92
|
+
<<-SQL
|
93
|
+
SELECT ddl
|
94
|
+
FROM admin.v_generate_view_ddl
|
95
|
+
WHERE schemaname IN ($1)
|
96
|
+
ORDER BY viewname ASC
|
97
|
+
SQL
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/postshift/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :postshift do
|
2
|
+
namespace :schema do
|
3
|
+
task connect: :environment do
|
4
|
+
Postshift.adapter = ActiveRecord::Base.connection
|
5
|
+
end
|
6
|
+
|
7
|
+
desc 'Prepare Redshift instance for Schema Exports'
|
8
|
+
task prepare: :connect do
|
9
|
+
puts '*** Creating Admin Utilities ***'
|
10
|
+
Postshift::Schema.create_admin_utilities!
|
11
|
+
puts '*** Finished Creating Admin Utilities ***'
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Creates a db/postshift_schema.sql file for Redshift databases'
|
15
|
+
task dump: :connect do
|
16
|
+
puts '*** Starting Postshift Schema Dump ***'
|
17
|
+
Postshift::Schema.dump
|
18
|
+
puts '*** Completed Postshift Schema Dump ***'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Restores db/postshift_schema.sql file to Redshift database'
|
22
|
+
task restore: :connect do
|
23
|
+
puts '*** Starting Postshift Schema Restore ***'
|
24
|
+
Postshift::Schema.restore
|
25
|
+
puts '*** Completed Postshift Schema Restore ***'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,254 @@
|
|
1
|
+
--DROP VIEW admin.v_generate_tbl_ddl;
|
2
|
+
/**********************************************************************************************
|
3
|
+
Purpose: View to get the DDL for a table. This will contain the distkey, sortkey, constraints,
|
4
|
+
not null, defaults, etc.
|
5
|
+
|
6
|
+
Notes: Default view ordering causes foreign keys to be created at the end.
|
7
|
+
This is needed due to dependencies of the foreign key constraint and the tables it
|
8
|
+
links. Due to this one should not manually order the output if you are expecting to
|
9
|
+
be able to replay the SQL directly from the VIEW query result. It is still possible to
|
10
|
+
order if you filter out the FOREIGN KEYS and then apply them later.
|
11
|
+
|
12
|
+
The following filters are useful:
|
13
|
+
where ddl not like 'ALTER TABLE %' -- do not return FOREIGN KEY CONSTRAINTS
|
14
|
+
where ddl like 'ALTER TABLE %' -- only get FOREIGN KEY CONSTRAINTS
|
15
|
+
where tablename in ('t1', 't2') -- only get DDL for specific tables
|
16
|
+
where schemaname in ('s1', 's2') -- only get DDL for specific schemas
|
17
|
+
|
18
|
+
So for example if you want to order DDL on tablename and only want the tables 't1', 't2'
|
19
|
+
and 't4' you can do so by using a query like:
|
20
|
+
select ddl from (
|
21
|
+
(
|
22
|
+
select
|
23
|
+
*
|
24
|
+
from admin.v_generate_tbl_ddl
|
25
|
+
where ddl not like 'ALTER TABLE %'
|
26
|
+
order by tablename
|
27
|
+
)
|
28
|
+
UNION ALL
|
29
|
+
(
|
30
|
+
select
|
31
|
+
*
|
32
|
+
from admin.v_generate_tbl_ddl
|
33
|
+
where ddl like 'ALTER TABLE %'
|
34
|
+
order by tablename
|
35
|
+
)
|
36
|
+
) where tablename in ('t1', 't2', 't4');
|
37
|
+
|
38
|
+
History:
|
39
|
+
2014-02-10 jjschmit Created
|
40
|
+
2015-05-18 ericfe Added support for Interleaved sortkey
|
41
|
+
2015-10-31 ericfe Added cast tp increase size of returning constraint name
|
42
|
+
2016-05-24 chriz-bigdata Added support for BACKUP NO tables
|
43
|
+
2017-05-03 pvbouwel Change table & schemaname of Foreign key constraints to allow for filters
|
44
|
+
**********************************************************************************************/
|
45
|
+
CREATE OR REPLACE VIEW admin.v_generate_tbl_ddl
|
46
|
+
AS
|
47
|
+
SELECT
|
48
|
+
REGEXP_REPLACE (schemaname, '^zzzzzzzz', '') AS schemaname
|
49
|
+
,REGEXP_REPLACE (tablename, '^zzzzzzzz', '') AS tablename
|
50
|
+
,seq
|
51
|
+
,ddl
|
52
|
+
FROM
|
53
|
+
(
|
54
|
+
SELECT
|
55
|
+
schemaname
|
56
|
+
,tablename
|
57
|
+
,seq
|
58
|
+
,ddl
|
59
|
+
FROM
|
60
|
+
(
|
61
|
+
--DROP TABLE
|
62
|
+
SELECT
|
63
|
+
n.nspname AS schemaname
|
64
|
+
,c.relname AS tablename
|
65
|
+
,0 AS seq
|
66
|
+
,'--DROP TABLE "' + n.nspname + '"."' + c.relname + '";' AS ddl
|
67
|
+
FROM pg_namespace AS n
|
68
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
69
|
+
WHERE c.relkind = 'r'
|
70
|
+
--CREATE TABLE
|
71
|
+
UNION SELECT
|
72
|
+
n.nspname AS schemaname
|
73
|
+
,c.relname AS tablename
|
74
|
+
,2 AS seq
|
75
|
+
,'CREATE TABLE IF NOT EXISTS "' + n.nspname + '"."' + c.relname + '"' AS ddl
|
76
|
+
FROM pg_namespace AS n
|
77
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
78
|
+
WHERE c.relkind = 'r'
|
79
|
+
--OPEN PAREN COLUMN LIST
|
80
|
+
UNION SELECT n.nspname AS schemaname, c.relname AS tablename, 5 AS seq, '(' AS ddl
|
81
|
+
FROM pg_namespace AS n
|
82
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
83
|
+
WHERE c.relkind = 'r'
|
84
|
+
--COLUMN LIST
|
85
|
+
UNION SELECT
|
86
|
+
schemaname
|
87
|
+
,tablename
|
88
|
+
,seq
|
89
|
+
,'\t' + col_delim + col_name + ' ' + col_datatype + ' ' + col_nullable + ' ' + col_default + ' ' + col_encoding AS ddl
|
90
|
+
FROM
|
91
|
+
(
|
92
|
+
SELECT
|
93
|
+
n.nspname AS schemaname
|
94
|
+
,c.relname AS tablename
|
95
|
+
,100000000 + a.attnum AS seq
|
96
|
+
,CASE WHEN a.attnum > 1 THEN ',' ELSE '' END AS col_delim
|
97
|
+
,'"' + a.attname + '"' AS col_name
|
98
|
+
,CASE WHEN STRPOS(UPPER(format_type(a.atttypid, a.atttypmod)), 'CHARACTER VARYING') > 0
|
99
|
+
THEN REPLACE(UPPER(format_type(a.atttypid, a.atttypmod)), 'CHARACTER VARYING', 'VARCHAR')
|
100
|
+
WHEN STRPOS(UPPER(format_type(a.atttypid, a.atttypmod)), 'CHARACTER') > 0
|
101
|
+
THEN REPLACE(UPPER(format_type(a.atttypid, a.atttypmod)), 'CHARACTER', 'CHAR')
|
102
|
+
ELSE UPPER(format_type(a.atttypid, a.atttypmod))
|
103
|
+
END AS col_datatype
|
104
|
+
,CASE WHEN format_encoding((a.attencodingtype)::integer) = 'none'
|
105
|
+
THEN ''
|
106
|
+
ELSE 'ENCODE ' + format_encoding((a.attencodingtype)::integer)
|
107
|
+
END AS col_encoding
|
108
|
+
,CASE WHEN a.atthasdef IS TRUE THEN 'DEFAULT ' + adef.adsrc ELSE '' END AS col_default
|
109
|
+
,CASE WHEN a.attnotnull IS TRUE THEN 'NOT NULL' ELSE '' END AS col_nullable
|
110
|
+
FROM pg_namespace AS n
|
111
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
112
|
+
INNER JOIN pg_attribute AS a ON c.oid = a.attrelid
|
113
|
+
LEFT OUTER JOIN pg_attrdef AS adef ON a.attrelid = adef.adrelid AND a.attnum = adef.adnum
|
114
|
+
WHERE c.relkind = 'r'
|
115
|
+
AND a.attnum > 0
|
116
|
+
ORDER BY a.attnum
|
117
|
+
)
|
118
|
+
--CONSTRAINT LIST
|
119
|
+
UNION (SELECT
|
120
|
+
n.nspname AS schemaname
|
121
|
+
,c.relname AS tablename
|
122
|
+
,200000000 + CAST(con.oid AS INT) AS seq
|
123
|
+
,'\t,' + pg_get_constraintdef(con.oid) AS ddl
|
124
|
+
FROM pg_constraint AS con
|
125
|
+
INNER JOIN pg_class AS c ON c.relnamespace = con.connamespace AND c.oid = con.conrelid
|
126
|
+
INNER JOIN pg_namespace AS n ON n.oid = c.relnamespace
|
127
|
+
WHERE c.relkind = 'r' AND pg_get_constraintdef(con.oid) NOT LIKE 'FOREIGN KEY%'
|
128
|
+
ORDER BY seq)
|
129
|
+
--CLOSE PAREN COLUMN LIST
|
130
|
+
UNION SELECT n.nspname AS schemaname, c.relname AS tablename, 299999999 AS seq, ')' AS ddl
|
131
|
+
FROM pg_namespace AS n
|
132
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
133
|
+
WHERE c.relkind = 'r'
|
134
|
+
--BACKUP
|
135
|
+
UNION SELECT
|
136
|
+
n.nspname AS schemaname
|
137
|
+
,c.relname AS tablename
|
138
|
+
,300000000 AS seq
|
139
|
+
,'BACKUP NO' as ddl
|
140
|
+
FROM pg_namespace AS n
|
141
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
142
|
+
INNER JOIN (SELECT
|
143
|
+
SPLIT_PART(key,'_',5) id
|
144
|
+
FROM pg_conf
|
145
|
+
WHERE key LIKE 'pg_class_backup_%'
|
146
|
+
AND SPLIT_PART(key,'_',4) = (SELECT
|
147
|
+
oid
|
148
|
+
FROM pg_database
|
149
|
+
WHERE datname = current_database())) t ON t.id=c.oid
|
150
|
+
WHERE c.relkind = 'r'
|
151
|
+
--BACKUP WARNING
|
152
|
+
UNION SELECT
|
153
|
+
n.nspname AS schemaname
|
154
|
+
,c.relname AS tablename
|
155
|
+
,1 AS seq
|
156
|
+
,'--WARNING: This DDL inherited the BACKUP NO property from the source table' as ddl
|
157
|
+
FROM pg_namespace AS n
|
158
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
159
|
+
INNER JOIN (SELECT
|
160
|
+
SPLIT_PART(key,'_',5) id
|
161
|
+
FROM pg_conf
|
162
|
+
WHERE key LIKE 'pg_class_backup_%'
|
163
|
+
AND SPLIT_PART(key,'_',4) = (SELECT
|
164
|
+
oid
|
165
|
+
FROM pg_database
|
166
|
+
WHERE datname = current_database())) t ON t.id=c.oid
|
167
|
+
WHERE c.relkind = 'r'
|
168
|
+
--DISTSTYLE
|
169
|
+
UNION SELECT
|
170
|
+
n.nspname AS schemaname
|
171
|
+
,c.relname AS tablename
|
172
|
+
,300000001 AS seq
|
173
|
+
,CASE WHEN c.reldiststyle = 0 THEN 'DISTSTYLE EVEN'
|
174
|
+
WHEN c.reldiststyle = 1 THEN 'DISTSTYLE KEY'
|
175
|
+
WHEN c.reldiststyle = 8 THEN 'DISTSTYLE ALL'
|
176
|
+
ELSE '<<Error - UNKNOWN DISTSTYLE>>'
|
177
|
+
END AS ddl
|
178
|
+
FROM pg_namespace AS n
|
179
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
180
|
+
WHERE c.relkind = 'r'
|
181
|
+
--DISTKEY COLUMNS
|
182
|
+
UNION SELECT
|
183
|
+
n.nspname AS schemaname
|
184
|
+
,c.relname AS tablename
|
185
|
+
,400000000 + a.attnum AS seq
|
186
|
+
,'DISTKEY ("' + a.attname + '")' AS ddl
|
187
|
+
FROM pg_namespace AS n
|
188
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
189
|
+
INNER JOIN pg_attribute AS a ON c.oid = a.attrelid
|
190
|
+
WHERE c.relkind = 'r'
|
191
|
+
AND a.attisdistkey IS TRUE
|
192
|
+
AND a.attnum > 0
|
193
|
+
--SORTKEY COLUMNS
|
194
|
+
UNION select schemaname, tablename, seq,
|
195
|
+
case when min_sort <0 then 'INTERLEAVED SORTKEY (' else 'SORTKEY (' end as ddl
|
196
|
+
from (SELECT
|
197
|
+
n.nspname AS schemaname
|
198
|
+
,c.relname AS tablename
|
199
|
+
,499999999 AS seq
|
200
|
+
,min(attsortkeyord) min_sort FROM pg_namespace AS n
|
201
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
202
|
+
INNER JOIN pg_attribute AS a ON c.oid = a.attrelid
|
203
|
+
WHERE c.relkind = 'r'
|
204
|
+
AND abs(a.attsortkeyord) > 0
|
205
|
+
AND a.attnum > 0
|
206
|
+
group by 1,2,3 )
|
207
|
+
UNION (SELECT
|
208
|
+
n.nspname AS schemaname
|
209
|
+
,c.relname AS tablename
|
210
|
+
,500000000 + abs(a.attsortkeyord) AS seq
|
211
|
+
,CASE WHEN abs(a.attsortkeyord) = 1
|
212
|
+
THEN '\t"' + a.attname + '"'
|
213
|
+
ELSE '\t, "' + a.attname + '"'
|
214
|
+
END AS ddl
|
215
|
+
FROM pg_namespace AS n
|
216
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
217
|
+
INNER JOIN pg_attribute AS a ON c.oid = a.attrelid
|
218
|
+
WHERE c.relkind = 'r'
|
219
|
+
AND abs(a.attsortkeyord) > 0
|
220
|
+
AND a.attnum > 0
|
221
|
+
ORDER BY abs(a.attsortkeyord))
|
222
|
+
UNION SELECT
|
223
|
+
n.nspname AS schemaname
|
224
|
+
,c.relname AS tablename
|
225
|
+
,599999999 AS seq
|
226
|
+
,'\t)' AS ddl
|
227
|
+
FROM pg_namespace AS n
|
228
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
229
|
+
INNER JOIN pg_attribute AS a ON c.oid = a.attrelid
|
230
|
+
WHERE c.relkind = 'r'
|
231
|
+
AND abs(a.attsortkeyord) > 0
|
232
|
+
AND a.attnum > 0
|
233
|
+
--END SEMICOLON
|
234
|
+
UNION SELECT n.nspname AS schemaname, c.relname AS tablename, 600000000 AS seq, ';' AS ddl
|
235
|
+
FROM pg_namespace AS n
|
236
|
+
INNER JOIN pg_class AS c ON n.oid = c.relnamespace
|
237
|
+
WHERE c.relkind = 'r' )
|
238
|
+
UNION (
|
239
|
+
SELECT 'zzzzzzzz' || n.nspname AS schemaname,
|
240
|
+
'zzzzzzzz' || c.relname AS tablename,
|
241
|
+
700000000 + CAST(con.oid AS INT) AS seq,
|
242
|
+
'ALTER TABLE ' + n.nspname + '.' + c.relname + ' ADD ' + pg_get_constraintdef(con.oid)::VARCHAR(1024) + ';' AS ddl
|
243
|
+
FROM pg_constraint AS con
|
244
|
+
INNER JOIN pg_class AS c
|
245
|
+
ON c.relnamespace = con.connamespace
|
246
|
+
AND c.oid = con.conrelid
|
247
|
+
INNER JOIN pg_namespace AS n ON n.oid = c.relnamespace
|
248
|
+
WHERE c.relkind = 'r'
|
249
|
+
AND con.contype = 'f'
|
250
|
+
ORDER BY seq
|
251
|
+
)
|
252
|
+
ORDER BY schemaname, tablename, seq
|
253
|
+
)
|
254
|
+
;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
--DROP VIEW admin.v_generate_view_ddl;
|
2
|
+
/**********************************************************************************************
|
3
|
+
Purpose: View to get the DDL for a view.
|
4
|
+
History:
|
5
|
+
2014-02-10 jjschmit Created
|
6
|
+
**********************************************************************************************/
|
7
|
+
CREATE OR REPLACE VIEW admin.v_generate_view_ddl
|
8
|
+
AS
|
9
|
+
SELECT
|
10
|
+
n.nspname AS schemaname
|
11
|
+
,c.relname AS viewname
|
12
|
+
,'--DROP VIEW ' + n.nspname + '.' + c.relname + ';\nCREATE OR REPLACE VIEW ' + n.nspname + '.' + c.relname + ' AS\n' + COALESCE(pg_get_viewdef(c.oid, TRUE), '') AS ddl
|
13
|
+
FROM
|
14
|
+
pg_catalog.pg_class AS c
|
15
|
+
INNER JOIN
|
16
|
+
pg_catalog.pg_namespace AS n
|
17
|
+
ON c.relnamespace = n.oid
|
18
|
+
WHERE relkind = 'v'
|
19
|
+
;
|
data/postshift.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
32
32
|
spec.add_development_dependency 'rake', '~> 10.0'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
-
spec.add_development_dependency 'factory_girl', '~> 4.8
|
35
|
-
spec.add_development_dependency 'database_cleaner', '~> 1.6
|
36
|
-
spec.add_development_dependency 'appraisal', '~> 2.2
|
34
|
+
spec.add_development_dependency 'factory_girl', '~> 4.8'
|
35
|
+
spec.add_development_dependency 'database_cleaner', '~> 1.6'
|
36
|
+
spec.add_development_dependency 'appraisal', '~> 2.2'
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postshift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Krupinski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -106,42 +106,42 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 4.8
|
109
|
+
version: '4.8'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 4.8
|
116
|
+
version: '4.8'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: database_cleaner
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: 1.6
|
123
|
+
version: '1.6'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: 1.6
|
130
|
+
version: '1.6'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
132
|
name: appraisal
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: 2.2
|
137
|
+
version: '2.2'
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: 2.2
|
144
|
+
version: '2.2'
|
145
145
|
description: Thin ActiveRecord Redshift Adapter extension for existing PostgreSQL
|
146
146
|
adapter.
|
147
147
|
email:
|
@@ -176,7 +176,12 @@ files:
|
|
176
176
|
- lib/active_record/connection_adapters/redshift/type_metadata.rb
|
177
177
|
- lib/active_record/connection_adapters/redshift_adapter.rb
|
178
178
|
- lib/postshift.rb
|
179
|
+
- lib/postshift/railtie.rb
|
180
|
+
- lib/postshift/schema.rb
|
179
181
|
- lib/postshift/version.rb
|
182
|
+
- lib/tasks/schema.rake
|
183
|
+
- lib/tasks/v_generate_tbl_ddl.sql
|
184
|
+
- lib/tasks/v_generate_view_ddl.sql
|
180
185
|
- postshift.gemspec
|
181
186
|
homepage: https://github.com/ValiMail/postshift
|
182
187
|
licenses:
|