activerecord-postgresql-extensions 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +4 -0
- data/Gemfile +1 -0
- data/Guardfile +3 -3
- data/MIT-LICENSE +1 -1
- data/README.rdoc +10 -3
- data/lib/active_record/postgresql_extensions/adapter_extensions.rb +100 -60
- data/lib/active_record/postgresql_extensions/constraints.rb +13 -17
- data/lib/active_record/postgresql_extensions/event_triggers.rb +129 -0
- data/lib/active_record/postgresql_extensions/extensions.rb +14 -15
- data/lib/active_record/postgresql_extensions/features.rb +80 -41
- data/lib/active_record/postgresql_extensions/functions.rb +1 -1
- data/lib/active_record/postgresql_extensions/geometry.rb +6 -8
- data/lib/active_record/postgresql_extensions/indexes.rb +19 -11
- data/lib/active_record/postgresql_extensions/languages.rb +1 -1
- data/lib/active_record/postgresql_extensions/materialized_views.rb +272 -0
- data/lib/active_record/postgresql_extensions/permissions.rb +60 -22
- data/lib/active_record/postgresql_extensions/roles.rb +18 -7
- data/lib/active_record/postgresql_extensions/rules.rb +5 -0
- data/lib/active_record/postgresql_extensions/schemas.rb +39 -3
- data/lib/active_record/postgresql_extensions/sequences.rb +6 -3
- data/lib/active_record/postgresql_extensions/tables.rb +47 -19
- data/lib/active_record/postgresql_extensions/tablespaces.rb +1 -1
- data/lib/active_record/postgresql_extensions/text_search.rb +3 -3
- data/lib/active_record/postgresql_extensions/triggers.rb +3 -3
- data/lib/active_record/postgresql_extensions/types.rb +104 -1
- data/lib/active_record/postgresql_extensions/utils.rb +35 -13
- data/lib/active_record/postgresql_extensions/vacuum.rb +1 -1
- data/lib/active_record/postgresql_extensions/version.rb +1 -1
- data/lib/active_record/postgresql_extensions/views.rb +137 -6
- data/lib/activerecord-postgresql-extensions.rb +13 -11
- data/test/{adapter_tests.rb → adapter_extensions_tests.rb} +96 -3
- data/test/constraints_tests.rb +216 -104
- data/test/event_triggers_tests.rb +109 -0
- data/test/extensions_tests.rb +47 -39
- data/test/functions_tests.rb +47 -38
- data/test/geometry_tests.rb +268 -135
- data/test/{index_tests.rb → indexes_tests.rb} +16 -16
- data/test/languages_tests.rb +26 -9
- data/test/materialized_views_tests.rb +174 -0
- data/test/permissions_tests.rb +159 -45
- data/test/roles_tests.rb +17 -7
- data/test/rules_tests.rb +14 -6
- data/test/schemas_tests.rb +35 -9
- data/test/sequences_tests.rb +9 -11
- data/test/tables_tests.rb +132 -42
- data/test/tablespace_tests.rb +21 -15
- data/test/test_helper.rb +56 -10
- data/test/text_search_tests.rb +42 -44
- data/test/trigger_tests.rb +1 -3
- data/test/types_tests.rb +95 -0
- data/test/vacuum_tests.rb +1 -3
- data/test/views_tests.rb +203 -0
- metadata +22 -16
data/test/roles_tests.rb
CHANGED
@@ -2,11 +2,19 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class RolesTests <
|
6
|
-
include PostgreSQLExtensionsTestHelper
|
7
|
-
|
5
|
+
class RolesTests < PostgreSQLExtensionsTestCase
|
8
6
|
def test_create_role
|
9
7
|
ARBC.create_role('foo')
|
8
|
+
|
9
|
+
ARBC.create_role('foo', {
|
10
|
+
:password => 'testing',
|
11
|
+
:encrypted_password => false
|
12
|
+
})
|
13
|
+
|
14
|
+
ARBC.create_role('foo', {
|
15
|
+
:valid_until => 'foo'
|
16
|
+
})
|
17
|
+
|
10
18
|
ARBC.create_role('foo', {
|
11
19
|
:superuser => true,
|
12
20
|
:create_db => true,
|
@@ -23,7 +31,9 @@ class RolesTests < MiniTest::Unit::TestCase
|
|
23
31
|
})
|
24
32
|
|
25
33
|
assert_equal([
|
26
|
-
|
34
|
+
%{CREATE ROLE "foo";},
|
35
|
+
%{CREATE ROLE "foo" UNENCRYPTED PASSWORD 'testing';},
|
36
|
+
%{CREATE ROLE "foo" VALID UNTIL 'foo';},
|
27
37
|
%{CREATE ROLE "foo" SUPERUSER CREATEDB CREATEROLE NOINHERIT LOGIN CONNECTION LIMIT 10 ENCRYPTED PASSWORD 'testing' VALID UNTIL '2011-10-12' IN ROLE "bar" ROLE "baz" ADMIN "blort";}
|
28
38
|
], statements)
|
29
39
|
end
|
@@ -55,9 +65,9 @@ class RolesTests < MiniTest::Unit::TestCase
|
|
55
65
|
ARBC.drop_role(%w{ foo bar baz }, :if_exists => true)
|
56
66
|
|
57
67
|
assert_equal([
|
58
|
-
|
59
|
-
|
60
|
-
|
68
|
+
%{DROP ROLE "foo";},
|
69
|
+
%{DROP ROLE "foo", "bar", "baz";},
|
70
|
+
%{DROP ROLE IF EXISTS "foo", "bar", "baz";}
|
61
71
|
], statements)
|
62
72
|
end
|
63
73
|
end
|
data/test/rules_tests.rb
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class RulesTests <
|
6
|
-
include PostgreSQLExtensionsTestHelper
|
7
|
-
|
5
|
+
class RulesTests < PostgreSQLExtensionsTestCase
|
8
6
|
def test_create_rule
|
9
7
|
ARBC.create_rule(
|
10
8
|
:ignore_root, :update, :foos, :instead, :nothing, :conditions => 'user_id = 0'
|
@@ -17,8 +15,8 @@ class RulesTests < MiniTest::Unit::TestCase
|
|
17
15
|
)
|
18
16
|
|
19
17
|
assert_equal([
|
20
|
-
|
21
|
-
|
18
|
+
%{CREATE RULE "ignore_root" AS ON UPDATE TO "foos" WHERE user_id = 0 DO INSTEAD NOTHING;},
|
19
|
+
%{CREATE OR REPLACE RULE "ignore_root" AS ON UPDATE TO "foos" WHERE user_id > 0 DO INSTEAD SELECT * FROM non_admins;}
|
22
20
|
], statements)
|
23
21
|
end
|
24
22
|
|
@@ -26,7 +24,17 @@ class RulesTests < MiniTest::Unit::TestCase
|
|
26
24
|
ARBC.drop_rule(:foo, :bar)
|
27
25
|
|
28
26
|
assert_equal([
|
29
|
-
|
27
|
+
%{DROP RULE "foo" ON "bar";}
|
28
|
+
], statements)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_rename_rule
|
32
|
+
skip unless ActiveRecord::PostgreSQLExtensions::Features.rename_rule?
|
33
|
+
|
34
|
+
Mig.rename_rule(:foo, :bar, :baz)
|
35
|
+
|
36
|
+
assert_equal([
|
37
|
+
%{ALTER RULE "foo" ON "bar" RENAME TO "baz";}
|
30
38
|
], statements)
|
31
39
|
end
|
32
40
|
end
|
data/test/schemas_tests.rb
CHANGED
@@ -2,16 +2,24 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class SchemasTests <
|
6
|
-
include PostgreSQLExtensionsTestHelper
|
7
|
-
|
5
|
+
class SchemasTests < PostgreSQLExtensionsTestCase
|
8
6
|
def test_create_schema
|
9
7
|
Mig.create_schema(:foo)
|
10
8
|
Mig.create_schema(:foo, :authorization => 'bar')
|
11
9
|
|
12
10
|
assert_equal([
|
13
|
-
|
14
|
-
|
11
|
+
%{CREATE SCHEMA "foo";},
|
12
|
+
%{CREATE SCHEMA "foo" AUTHORIZATION "bar";}
|
13
|
+
], statements)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create_schema_if_not_exists
|
17
|
+
skip unless ActiveRecord::PostgreSQLExtensions::Features.create_schema_if_not_exists?
|
18
|
+
|
19
|
+
Mig.create_schema(:foo, :if_not_exists => true)
|
20
|
+
|
21
|
+
assert_equal([
|
22
|
+
%{CREATE SCHEMA IF NOT EXISTS "foo";}
|
15
23
|
], statements)
|
16
24
|
end
|
17
25
|
|
@@ -20,8 +28,8 @@ class SchemasTests < MiniTest::Unit::TestCase
|
|
20
28
|
Mig.drop_schema(:foo, :if_exists => true, :cascade => true)
|
21
29
|
|
22
30
|
assert_equal([
|
23
|
-
|
24
|
-
|
31
|
+
%{DROP SCHEMA "foo";},
|
32
|
+
%{DROP SCHEMA IF EXISTS "foo" CASCADE;}
|
25
33
|
], statements)
|
26
34
|
end
|
27
35
|
|
@@ -29,7 +37,7 @@ class SchemasTests < MiniTest::Unit::TestCase
|
|
29
37
|
Mig.alter_schema_name(:foo, :bar)
|
30
38
|
|
31
39
|
assert_equal([
|
32
|
-
|
40
|
+
%{ALTER SCHEMA "foo" RENAME TO "bar";}
|
33
41
|
], statements)
|
34
42
|
end
|
35
43
|
|
@@ -37,7 +45,25 @@ class SchemasTests < MiniTest::Unit::TestCase
|
|
37
45
|
Mig.alter_schema_owner(:foo, :bar)
|
38
46
|
|
39
47
|
assert_equal([
|
40
|
-
|
48
|
+
%{ALTER SCHEMA "foo" OWNER TO "bar";}
|
49
|
+
], statements)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_create_schema_authorization
|
53
|
+
Mig.create_schema_authorization(:foo)
|
54
|
+
|
55
|
+
assert_equal([
|
56
|
+
%{CREATE SCHEMA AUTHORIZATION "foo";}
|
57
|
+
], statements)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_create_schema_authorization_if_not_exists
|
61
|
+
skip unless ActiveRecord::PostgreSQLExtensions::Features.create_schema_if_not_exists?
|
62
|
+
|
63
|
+
Mig.create_schema_authorization(:foo, :if_not_exists => true)
|
64
|
+
|
65
|
+
assert_equal([
|
66
|
+
%{CREATE SCHEMA IF NOT EXISTS AUTHORIZATION "foo";}
|
41
67
|
], statements)
|
42
68
|
end
|
43
69
|
end
|
data/test/sequences_tests.rb
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class SequenceTests <
|
6
|
-
include PostgreSQLExtensionsTestHelper
|
7
|
-
|
5
|
+
class SequenceTests < PostgreSQLExtensionsTestCase
|
8
6
|
def test_create_sequence
|
9
7
|
Mig.create_sequence(
|
10
8
|
'what_a_sequence_of_events',
|
@@ -21,8 +19,8 @@ class SequenceTests < MiniTest::Unit::TestCase
|
|
21
19
|
)
|
22
20
|
|
23
21
|
assert_equal([
|
24
|
-
|
25
|
-
|
22
|
+
%{CREATE SEQUENCE "what_a_sequence_of_events" START WITH 10;},
|
23
|
+
%{CREATE SEQUENCE "what_a_sequence_of_events" INCREMENT BY 2 NO MINVALUE MAXVALUE 10 CACHE 2 OWNED BY "foo"."id";}
|
26
24
|
], statements)
|
27
25
|
end
|
28
26
|
|
@@ -34,7 +32,7 @@ class SequenceTests < MiniTest::Unit::TestCase
|
|
34
32
|
)
|
35
33
|
|
36
34
|
assert_equal([
|
37
|
-
|
35
|
+
%{DROP SEQUENCE IF EXISTS "foo_id_seq" CASCADE;}
|
38
36
|
], statements)
|
39
37
|
end
|
40
38
|
|
@@ -42,7 +40,7 @@ class SequenceTests < MiniTest::Unit::TestCase
|
|
42
40
|
Mig.rename_sequence(:foo, :bar)
|
43
41
|
|
44
42
|
assert_equal([
|
45
|
-
|
43
|
+
%{ALTER SEQUENCE "foo" RENAME TO "bar";}
|
46
44
|
], statements)
|
47
45
|
end
|
48
46
|
|
@@ -51,8 +49,8 @@ class SequenceTests < MiniTest::Unit::TestCase
|
|
51
49
|
Mig.alter_sequence_schema(:foo, :public)
|
52
50
|
|
53
51
|
assert_equal([
|
54
|
-
|
55
|
-
|
52
|
+
%{ALTER SEQUENCE "foo" SET SCHEMA "bar";},
|
53
|
+
%{ALTER SEQUENCE "foo" SET SCHEMA PUBLIC;}
|
56
54
|
], statements)
|
57
55
|
end
|
58
56
|
|
@@ -61,8 +59,8 @@ class SequenceTests < MiniTest::Unit::TestCase
|
|
61
59
|
Mig.set_sequence_value(:foo, 42, :is_called => false)
|
62
60
|
|
63
61
|
assert_equal([
|
64
|
-
|
65
|
-
|
62
|
+
%{SELECT setval('foo', 42, true);},
|
63
|
+
%{SELECT setval('foo', 42, false);}
|
66
64
|
], statements)
|
67
65
|
end
|
68
66
|
end
|
data/test/tables_tests.rb
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
$: << File.dirname(__FILE__)
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
class TablesTests <
|
6
|
-
include PostgreSQLExtensionsTestHelper
|
7
|
-
|
5
|
+
class TablesTests < PostgreSQLExtensionsTestCase
|
8
6
|
def test_default_with_expression
|
9
7
|
Mig.create_table('foo') do |t|
|
10
8
|
t.integer :foo_id, :default => { :expression => '10 + 20' }
|
@@ -12,19 +10,21 @@ class TablesTests < MiniTest::Unit::TestCase
|
|
12
10
|
end
|
13
11
|
|
14
12
|
if ActiveRecord::VERSION::STRING >= "3.2"
|
15
|
-
assert_equal([
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
);
|
13
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
14
|
+
CREATE TABLE "foo" (
|
15
|
+
"id" serial primary key,
|
16
|
+
"foo_id" integer DEFAULT 10 + 20,
|
17
|
+
"bar_id" integer DEFAULT 20
|
18
|
+
);
|
19
|
+
SQL
|
21
20
|
else
|
22
|
-
assert_equal([
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
);
|
21
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
22
|
+
CREATE TABLE "foo" (
|
23
|
+
"id" serial primary key,
|
24
|
+
"foo_id" integer DEFAULT 10 + 20,
|
25
|
+
"bar_id" integer DEFAULT '20 + 10'
|
26
|
+
);
|
27
|
+
SQL
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,36 +35,46 @@ class TablesTests < MiniTest::Unit::TestCase
|
|
35
35
|
:excluding => %w{ storage comments }
|
36
36
|
end
|
37
37
|
|
38
|
-
assert_equal([
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
);
|
43
|
-
|
38
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
39
|
+
CREATE TABLE "foo" (
|
40
|
+
"id" serial primary key,
|
41
|
+
LIKE "bar" INCLUDING CONSTRAINTS INCLUDING INDEXES EXCLUDING STORAGE EXCLUDING COMMENTS
|
42
|
+
);
|
43
|
+
SQL
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_option_unlogged
|
47
|
+
skip unless ActiveRecord::PostgreSQLExtensions::Features.create_table_unlogged?
|
48
|
+
|
47
49
|
Mig.create_table('foo', :unlogged => true)
|
48
50
|
|
49
|
-
assert_equal([
|
50
|
-
|
51
|
-
|
51
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
52
|
+
CREATE UNLOGGED TABLE "foo" (
|
53
|
+
"id" serial primary key
|
54
|
+
);
|
55
|
+
SQL
|
52
56
|
end
|
53
57
|
|
54
58
|
def test_option_temporary
|
55
59
|
Mig.create_table('foo', :temporary => true)
|
56
60
|
|
57
|
-
assert_equal([
|
58
|
-
|
59
|
-
|
61
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
62
|
+
CREATE TEMPORARY TABLE "foo" (
|
63
|
+
"id" serial primary key
|
64
|
+
);
|
65
|
+
SQL
|
60
66
|
end
|
61
67
|
|
62
68
|
def test_option_if_not_exists
|
69
|
+
skip unless ActiveRecord::PostgreSQLExtensions::Features.create_table_if_not_exists?
|
70
|
+
|
63
71
|
Mig.create_table('foo', :if_not_exists => true)
|
64
72
|
|
65
|
-
assert_equal([
|
66
|
-
|
67
|
-
|
73
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
74
|
+
CREATE TABLE IF NOT EXISTS "foo" (
|
75
|
+
"id" serial primary key
|
76
|
+
);
|
77
|
+
SQL
|
68
78
|
end
|
69
79
|
|
70
80
|
def test_option_on_commit
|
@@ -72,27 +82,52 @@ class TablesTests < MiniTest::Unit::TestCase
|
|
72
82
|
Mig.create_table('foo', :on_commit => :delete_rows)
|
73
83
|
Mig.create_table('foo', :on_commit => :drop)
|
74
84
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
85
|
+
expected = []
|
86
|
+
|
87
|
+
expected << strip_heredoc(<<-SQL)
|
88
|
+
CREATE TABLE "foo" (
|
89
|
+
"id" serial primary key
|
90
|
+
)
|
91
|
+
ON COMMIT PRESERVE ROWS;
|
92
|
+
SQL
|
93
|
+
|
94
|
+
expected << strip_heredoc(<<-SQL)
|
95
|
+
CREATE TABLE "foo" (
|
96
|
+
"id" serial primary key
|
97
|
+
)
|
98
|
+
ON COMMIT DELETE ROWS;
|
99
|
+
SQL
|
100
|
+
|
101
|
+
expected << strip_heredoc(<<-SQL)
|
102
|
+
CREATE TABLE "foo" (
|
103
|
+
"id" serial primary key
|
104
|
+
)
|
105
|
+
ON COMMIT DROP;
|
106
|
+
SQL
|
107
|
+
|
108
|
+
assert_equal(expected, statements)
|
80
109
|
end
|
81
110
|
|
82
111
|
def test_option_inherits
|
83
112
|
Mig.create_table('foo', :inherits => 'bar')
|
84
113
|
|
85
|
-
assert_equal([
|
86
|
-
|
87
|
-
|
114
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
115
|
+
CREATE TABLE "foo" (
|
116
|
+
"id" serial primary key
|
117
|
+
)
|
118
|
+
INHERITS ("bar");
|
119
|
+
SQL
|
88
120
|
end
|
89
121
|
|
90
122
|
def test_option_tablespace
|
91
123
|
Mig.create_table('foo', :tablespace => 'bar')
|
92
124
|
|
93
|
-
assert_equal([
|
94
|
-
|
95
|
-
|
125
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
126
|
+
CREATE TABLE "foo" (
|
127
|
+
"id" serial primary key
|
128
|
+
)
|
129
|
+
TABLESPACE "bar";
|
130
|
+
SQL
|
96
131
|
end
|
97
132
|
|
98
133
|
def test_option_of_type
|
@@ -128,8 +163,63 @@ class TablesTests < MiniTest::Unit::TestCase
|
|
128
163
|
})
|
129
164
|
end
|
130
165
|
|
166
|
+
assert_equal([ strip_heredoc(<<-SQL) ], statements)
|
167
|
+
CREATE TABLE "foo" (
|
168
|
+
"id" serial primary key,
|
169
|
+
"blort" text,
|
170
|
+
CONSTRAINT "exclude_blort_length" EXCLUDE (length(blort) WITH =)
|
171
|
+
);
|
172
|
+
SQL
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_index
|
176
|
+
Mig.create_table('foo') do |t|
|
177
|
+
t.text :blort
|
178
|
+
t.index :foo_blort_idx, :blort, :using => :gist
|
179
|
+
t.index :foo_blort_idx, :blort, :index_parameters => {
|
180
|
+
:fillfactor => 10
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
131
184
|
assert_equal([
|
132
|
-
%{
|
185
|
+
strip_heredoc(%{
|
186
|
+
CREATE TABLE "foo" (
|
187
|
+
"id" serial primary key,
|
188
|
+
"blort" text
|
189
|
+
);
|
190
|
+
}),
|
191
|
+
|
192
|
+
strip_heredoc(%{
|
193
|
+
CREATE INDEX "foo_blort_idx" ON "foo" USING "gist"("blort");
|
194
|
+
}),
|
195
|
+
|
196
|
+
strip_heredoc(%{
|
197
|
+
CREATE INDEX "foo_blort_idx" ON "foo"("blort") WITH ("fillfactor" = 10);
|
198
|
+
})
|
199
|
+
], statements)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_storage_parameters
|
203
|
+
Mig.create_table('foo', :storage_parameters => {
|
204
|
+
:fillfactor => 10
|
205
|
+
})
|
206
|
+
|
207
|
+
Mig.create_table('foo', :storage_parameters => "FILLFACTOR=10")
|
208
|
+
|
209
|
+
assert_equal([
|
210
|
+
strip_heredoc(%{
|
211
|
+
CREATE TABLE "foo" (
|
212
|
+
"id" serial primary key
|
213
|
+
)
|
214
|
+
WITH ("fillfactor" = 10);
|
215
|
+
}),
|
216
|
+
|
217
|
+
strip_heredoc(%{
|
218
|
+
CREATE TABLE "foo" (
|
219
|
+
"id" serial primary key
|
220
|
+
)
|
221
|
+
WITH (FILLFACTOR=10);
|
222
|
+
})
|
133
223
|
], statements)
|
134
224
|
end
|
135
225
|
end
|