schema_plus_compatibility 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -5
- data/lib/schema_plus/compatibility.rb +10 -0
- data/lib/schema_plus/compatibility/active_record/connection_adapters/abstract_adapter.rb +4 -4
- data/lib/schema_plus/compatibility/active_record/connection_adapters/mysql2_adapter.rb +11 -0
- data/lib/schema_plus/compatibility/active_record/connection_adapters/postgresql_adapter.rb +17 -0
- data/lib/schema_plus/compatibility/active_record/connection_adapters/sqlite3_adapter.rb +11 -0
- data/lib/schema_plus/compatibility/version.rb +1 -1
- data/spec/migration_spec.rb +1 -11
- data/spec/tables_only_spec.rb +57 -0
- metadata +7 -6
- data/spec/abstract_adapter_spec.rb +0 -32
- data/spec/support/expectations.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e562ca76fbfc4b9802d6546d1d70dd59f5f19f9c
|
4
|
+
data.tar.gz: d2dfef42ed2d63926e4e56341d41dcc205e0b287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75f2becf7f5cccb910c3f6d3d9f0c2692f1344731778daa0f989929775c02a6ea2790a06fcca0aed2886435e275dd7fd692a87b02b05ddf180a3ea7f263ac7cd
|
7
|
+
data.tar.gz: 812dee55b0f698949d8e20a5db998cafcf845a545589da133a88fbead38a07de2161dd6fd2f1290ba9666a6c3f2839ec0e08fc869fa1542e36d1f0e4c7f6ea6a
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/schema_plus_compatibility.svg)](http://badge.fury.io/rb/schema_plus_compatibility)
|
2
2
|
[![Build Status](https://secure.travis-ci.org/SchemaPlus/schema_plus_compatibility.svg)](http://travis-ci.org/SchemaPlus/schema_plus_compatibility)
|
3
|
-
[![Coverage Status](https://
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/github/SchemaPlus/schema_plus_compatibility/badge.svg?branch=master)](https://coveralls.io/github/SchemaPlus/schema_plus_compatibility?branch=master)
|
4
4
|
|
5
5
|
# SchemaPlus::Compatibility
|
6
6
|
|
@@ -25,13 +25,17 @@ gem.add_dependency "schema_plus_compatibility" # in a .gemspec
|
|
25
25
|
|
26
26
|
SchemaPlus::Compatibility provides the following new methods:
|
27
27
|
|
28
|
-
* `connection.
|
28
|
+
* `connection.tables_only`
|
29
29
|
|
30
|
-
In AR 5.0, `connection.tables` is deprecated for some db adapters, and
|
30
|
+
In AR 5.0, `connection.tables` is deprecated for some db adapters, and in AR 4.2 it may actually returns views (if any are defined) as well. This method consistently returns just tables regardless of the ActiveRecord version.
|
31
|
+
|
32
|
+
* `connection.user_tables_only`
|
31
33
|
|
32
|
-
|
34
|
+
In AR 5.0, an internal table (`ActiveRecord::InternalMetadata.table_name`) is added by ActiveRecord. The existence of this table trips up some tests (and possibly real code) which doesn't expect to see it. This method returns all tables except the internal metadata table.
|
33
35
|
|
34
|
-
|
36
|
+
* `Migration.latest_version`
|
37
|
+
|
38
|
+
In AR 5.0, `ActiveRecord::Migration` is versioned using `[]`; in AR 4.2 it's not versioned, making it awkward to create migrations cross-version. This method returns the latest migration version in both AR 4.2 and AR 5.0.
|
35
39
|
|
36
40
|
Note that the methods provided by SchemaPlus::Compatibility are subject to arbitrary change if/when SchemaPlus supports new versions of AR and/or drops support for old versions. But SchemaPlus::Compatibility will of course follow semantic versioning.
|
37
41
|
|
@@ -48,6 +52,7 @@ SchemaPlus::Compatibility is tested on:
|
|
48
52
|
|
49
53
|
## History
|
50
54
|
|
55
|
+
* 0.2.0 - replace the ill-defined `connection.tables_without_deprecation` with `connection.tables_only` which truly returns solely tables.
|
51
56
|
* 0.1.0 - Initial release
|
52
57
|
|
53
58
|
## Development & Testing
|
@@ -4,4 +4,14 @@ require_relative 'compatibility/version'
|
|
4
4
|
require_relative 'compatibility/active_record/connection_adapters/abstract_adapter'
|
5
5
|
require_relative 'compatibility/active_record/migration'
|
6
6
|
|
7
|
+
module SchemaPlus::Compatibility
|
8
|
+
module ActiveRecord
|
9
|
+
module ConnectionAdapters
|
10
|
+
autoload :Mysql2Adapter, 'schema_plus/compatibility/active_record/connection_adapters/mysql2_adapter'
|
11
|
+
autoload :PostgreSQLAdapter, 'schema_plus/compatibility/active_record/connection_adapters/postgresql_adapter'
|
12
|
+
autoload :SQLite3Adapter, 'schema_plus/compatibility/active_record/connection_adapters/sqlite3_adapter'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
7
17
|
SchemaMonkey.register SchemaPlus::Compatibility
|
@@ -2,10 +2,10 @@ module SchemaPlus::Compatibility
|
|
2
2
|
module ActiveRecord
|
3
3
|
module ConnectionAdapters
|
4
4
|
module AbstractAdapter
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def user_tables_only
|
6
|
+
t = tables_only
|
7
|
+
t.delete ::ActiveRecord::InternalMetadata.table_name if defined? ::ActiveRecord::InternalMetadata
|
8
|
+
t
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SchemaPlus::Compatibility
|
2
|
+
module ActiveRecord
|
3
|
+
module ConnectionAdapters
|
4
|
+
module PostgreSQLAdapter
|
5
|
+
def tables_only
|
6
|
+
select_values(<<-SQL, "SCHEMA")
|
7
|
+
SELECT c.relname
|
8
|
+
FROM pg_class c
|
9
|
+
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
10
|
+
WHERE c.relkind IN ('r') -- (r)elation/table
|
11
|
+
AND n.nspname = ANY (current_schemas(false))
|
12
|
+
SQL
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SchemaPlus::Compatibility
|
2
|
+
module ActiveRecord
|
3
|
+
module ConnectionAdapters
|
4
|
+
module SQLite3Adapter
|
5
|
+
def tables_only
|
6
|
+
select_values("SELECT name FROM sqlite_master WHERE type = 'table' AND name <> 'sqlite_sequence'", 'SCHEMA')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/migration_spec.rb
CHANGED
@@ -5,16 +5,6 @@ describe ActiveRecord::Migration do
|
|
5
5
|
|
6
6
|
let(:connection) { ActiveRecord::Base.connection }
|
7
7
|
|
8
|
-
it "does not create deprecation" do
|
9
|
-
expect_not_deprecated {
|
10
|
-
Class.new ActiveRecord::Migration.latest_version do
|
11
|
-
define_method(:up) do
|
12
|
-
create_table :foo
|
13
|
-
end
|
14
|
-
end
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
8
|
it "works with the latest migration object version" do
|
19
9
|
ActiveRecord::Migration.suppress_messages do
|
20
10
|
begin
|
@@ -22,7 +12,7 @@ describe ActiveRecord::Migration do
|
|
22
12
|
create_table :newtable, :force => true
|
23
13
|
end
|
24
14
|
migration.migrate(:up)
|
25
|
-
expect(connection.
|
15
|
+
expect(connection.tables_only).to include 'newtable'
|
26
16
|
ensure
|
27
17
|
connection.drop_table :newtable, if_exists: true
|
28
18
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "tables_only" do
|
5
|
+
let(:connection) { ActiveRecord::Base.connection }
|
6
|
+
|
7
|
+
def drop_dummy_view(v)
|
8
|
+
connection.execute "DROP VIEW IF EXISTS #{v}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_dummy_view(v, t)
|
12
|
+
drop_dummy_view v
|
13
|
+
connection.execute "CREATE VIEW #{v} AS SELECT * FROM #{t}"
|
14
|
+
end
|
15
|
+
|
16
|
+
around(:each) do |example|
|
17
|
+
begin
|
18
|
+
connection.tables_only.each do |table|
|
19
|
+
connection.drop_table table, force: :cascade
|
20
|
+
end
|
21
|
+
ActiveRecord::InternalMetadata.create_table if ActiveRecord::VERSION::MAJOR >= 5 # ensure metadata table exists
|
22
|
+
connection.create_table :t1
|
23
|
+
connection.create_table :t2
|
24
|
+
create_dummy_view :v1, :t1
|
25
|
+
create_dummy_view :v2, :t2
|
26
|
+
example.run
|
27
|
+
ensure
|
28
|
+
drop_dummy_view :v1
|
29
|
+
drop_dummy_view :v2
|
30
|
+
connection.drop_table :t1, if_exists: true
|
31
|
+
connection.drop_table :t2, if_exists: true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "does not cause deprecation" do
|
36
|
+
expect(ActiveSupport::Deprecation).not_to receive(:warn)
|
37
|
+
connection.tables_only
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:ar_internal_tables) {
|
41
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
42
|
+
[ActiveRecord::InternalMetadata.table_name]
|
43
|
+
else
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
}
|
47
|
+
|
48
|
+
it "lists all tables" do
|
49
|
+
expect(connection.tables_only).to match_array %w[t1 t2] + ar_internal_tables
|
50
|
+
end
|
51
|
+
|
52
|
+
it "user_tables_only doesn't list internal tables" do
|
53
|
+
expect(connection.user_tables_only).to match_array %w[t1 t2]
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_plus_compatibility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-09-
|
12
|
+
date: 2016-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -154,15 +154,17 @@ files:
|
|
154
154
|
- gemfiles/activerecord-5.0/Gemfile.sqlite3
|
155
155
|
- lib/schema_plus/compatibility.rb
|
156
156
|
- lib/schema_plus/compatibility/active_record/connection_adapters/abstract_adapter.rb
|
157
|
+
- lib/schema_plus/compatibility/active_record/connection_adapters/mysql2_adapter.rb
|
158
|
+
- lib/schema_plus/compatibility/active_record/connection_adapters/postgresql_adapter.rb
|
159
|
+
- lib/schema_plus/compatibility/active_record/connection_adapters/sqlite3_adapter.rb
|
157
160
|
- lib/schema_plus/compatibility/active_record/migration.rb
|
158
161
|
- lib/schema_plus/compatibility/version.rb
|
159
162
|
- lib/schema_plus_compatibility.rb
|
160
163
|
- schema_dev.yml
|
161
164
|
- schema_plus_compatibility.gemspec
|
162
|
-
- spec/abstract_adapter_spec.rb
|
163
165
|
- spec/migration_spec.rb
|
164
166
|
- spec/spec_helper.rb
|
165
|
-
- spec/
|
167
|
+
- spec/tables_only_spec.rb
|
166
168
|
homepage: https://github.com/SchemaPlus/schema_plus_compatibility
|
167
169
|
licenses:
|
168
170
|
- MIT
|
@@ -188,7 +190,6 @@ signing_key:
|
|
188
190
|
specification_version: 4
|
189
191
|
summary: Compatibility helpers for the SchemaPlus family of gems
|
190
192
|
test_files:
|
191
|
-
- spec/abstract_adapter_spec.rb
|
192
193
|
- spec/migration_spec.rb
|
193
194
|
- spec/spec_helper.rb
|
194
|
-
- spec/
|
195
|
+
- spec/tables_only_spec.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe ActiveRecord::ConnectionAdapters::AbstractAdapter do
|
5
|
-
|
6
|
-
context "tables_without_deprecation" do
|
7
|
-
|
8
|
-
let(:connection) { ActiveRecord::Base.connection }
|
9
|
-
|
10
|
-
around(:each) do |example|
|
11
|
-
begin
|
12
|
-
connection.create_table :t1, force: true
|
13
|
-
connection.create_table :t2, force: true
|
14
|
-
example.run
|
15
|
-
ensure
|
16
|
-
connection.drop_table :t1, if_exists: true
|
17
|
-
connection.drop_table :t2, if_exists: true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it "does not create deprecation" do
|
22
|
-
expect_not_deprecated {
|
23
|
-
connection.tables_without_deprecation
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
it "lists all tables" do
|
28
|
-
expect(connection.tables_without_deprecation).to match_array %w{t1 t2}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|