empty_eye 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/empty_eye/active_record/connection_adapters/abstract_mysql_adapter.rb +22 -0
- data/lib/empty_eye/active_record/connection_adapters/oci_adapter.rb +22 -0
- data/lib/empty_eye/active_record/connection_adapters/oracle_adapter.rb +21 -0
- data/lib/empty_eye/active_record/connection_adapters/oracleenhanced_adapter.rb +31 -0
- data/lib/empty_eye/active_record/connection_adapters/postgresql_adapter.rb +26 -0
- data/lib/empty_eye/active_record/connection_adapters/sqlite_adapter.rb +45 -0
- data/lib/empty_eye/active_record/connection_adapters/sqlserver_adapter.rb +21 -0
- data/lib/empty_eye/version.rb +1 -1
- data/lib/empty_eye.rb +7 -1
- metadata +10 -4
- data/lib/empty_eye/active_record/connection_adapter.rb +0 -46
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class AbstractMysqlAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
def tables_without_views(name = nil, database = nil, like = nil) #:nodoc:
|
6
|
+
sql = "SHOW FULL TABLES WHERE table_type = 'BASE TABLE'"
|
7
|
+
|
8
|
+
execute_and_free(sql, 'SCHEMA') do |result|
|
9
|
+
result.collect { |field| field.first }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def views(name = nil, database = nil, like = nil) #:nodoc:
|
14
|
+
sql = "SHOW FULL TABLES WHERE table_type = 'VIEW'"
|
15
|
+
|
16
|
+
execute_and_free(sql, 'SCHEMA') do |result|
|
17
|
+
result.collect { |field| field.first }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class OciAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
def tables(name = nil) #:nodoc:
|
6
|
+
tables_without_views(name) | views(name)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tables_without_views(name = nil) #:nodoc:
|
10
|
+
tables = []
|
11
|
+
execute("SELECT TABLE_NAME FROM USER_TABLES", name).each { |row| tables << row[0] }
|
12
|
+
tables
|
13
|
+
end
|
14
|
+
|
15
|
+
def views(name = nil) #:nodoc:
|
16
|
+
views = []
|
17
|
+
execute("SELECT VIEW_NAME FROM USER_VIEWS", name).each { |row| views << row[0] }
|
18
|
+
views
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class OracleAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
def tables(name = nil) #:nodoc:
|
6
|
+
tables = []
|
7
|
+
execute("SELECT TABLE_NAME FROM USER_TABLES", name).each { |row| tables << row[0] }
|
8
|
+
views = []
|
9
|
+
execute("SELECT VIEW_NAME FROM USER_VIEWS", name).each { |row| views << row[0] }
|
10
|
+
tables | views
|
11
|
+
end
|
12
|
+
|
13
|
+
def tables_without_views(name = nil) #:nodoc:
|
14
|
+
tables = []
|
15
|
+
execute("SELECT TABLE_NAME FROM USER_TABLES", name).each { |row| tables << row[0] }
|
16
|
+
tables
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class OracleEnhancedAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
def tables_without_views(name = nil) #:nodoc:
|
6
|
+
tables = []
|
7
|
+
cursor = execute("SELECT TABLE_NAME FROM USER_TABLES", name)
|
8
|
+
while row = cursor.fetch
|
9
|
+
tables << row[0]
|
10
|
+
end
|
11
|
+
tables
|
12
|
+
end
|
13
|
+
|
14
|
+
def tables(name = nil) #:nodoc:
|
15
|
+
tables = tables_without_views(name)
|
16
|
+
views = views(name)
|
17
|
+
tables | views
|
18
|
+
end
|
19
|
+
|
20
|
+
def views(name = nil) #:nodoc:
|
21
|
+
views = []
|
22
|
+
cursor = execute("SELECT VIEW_NAME FROM USER_VIEWS", name)
|
23
|
+
while row = cursor.fetch
|
24
|
+
views << row[0]
|
25
|
+
end
|
26
|
+
views
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class PostgreSQLAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
def tables(name = nil)
|
6
|
+
tables_without_views(name) | views(name)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tables_without_views(name = nil)
|
10
|
+
query(<<-SQL, 'SCHEMA').map { |row| row[0] }
|
11
|
+
SELECT tablename
|
12
|
+
FROM pg_tables
|
13
|
+
WHERE schemaname = ANY (current_schemas(false))
|
14
|
+
SQL
|
15
|
+
end
|
16
|
+
|
17
|
+
def views(name = nil)
|
18
|
+
query(<<-SQL, 'SCHEMA').map { |row| row[0] }
|
19
|
+
SELECT tablename
|
20
|
+
FROM pg_views
|
21
|
+
WHERE schemaname = ANY (current_schemas(false))
|
22
|
+
SQL
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class SQLiteAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
def tables(name = 'SCHEMA', table_name = nil) #:nodoc:
|
6
|
+
sql = <<-SQL
|
7
|
+
SELECT name
|
8
|
+
FROM sqlite_master
|
9
|
+
WHERE (type = 'table' OR type = 'view') AND NOT name = 'sqlite_sequence'
|
10
|
+
SQL
|
11
|
+
sql << " AND name = #{quote_table_name(table_name)}" if table_name
|
12
|
+
|
13
|
+
exec_query(sql, name).map do |row|
|
14
|
+
row['name']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def tables_without_views(name = 'SCHEMA', table_name = nil) #:nodoc:
|
19
|
+
sql = <<-SQL
|
20
|
+
SELECT name
|
21
|
+
FROM sqlite_master
|
22
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
23
|
+
SQL
|
24
|
+
sql << " AND name = #{quote_table_name(table_name)}" if table_name
|
25
|
+
|
26
|
+
exec_query(sql, name).map do |row|
|
27
|
+
row['name']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def views(name = 'SCHEMA', table_name = nil) #:nodoc:
|
32
|
+
sql = <<-SQL
|
33
|
+
SELECT name
|
34
|
+
FROM sqlite_master
|
35
|
+
WHERE type = 'view' AND NOT name = 'sqlite_sequence'
|
36
|
+
SQL
|
37
|
+
sql << " AND name = #{quote_table_name(table_name)}" if table_name
|
38
|
+
|
39
|
+
exec_query(sql, name).map do |row|
|
40
|
+
row['name']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class SQLServerAdapter < AbstractAdapter
|
4
|
+
|
5
|
+
# Get all of the non-view tables from the currently connected schema
|
6
|
+
def tables_without_views(name = nil)
|
7
|
+
# this is untested
|
8
|
+
select_values("SELECT table_name FROM information_schema.tables", name)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns all the view names from the currently connected schema.
|
12
|
+
def views(name = nil)
|
13
|
+
select_values("SELECT table_name FROM information_schema.views", name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def tables(name = nil)
|
17
|
+
tables_without_views(name) | views(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/empty_eye/version.rb
CHANGED
data/lib/empty_eye.rb
CHANGED
@@ -18,7 +18,13 @@ require "empty_eye/shard_association_reflection"
|
|
18
18
|
|
19
19
|
require "empty_eye/active_record/base"
|
20
20
|
require "empty_eye/active_record/schema_dumper"
|
21
|
-
require "empty_eye/active_record/
|
21
|
+
require "empty_eye/active_record/connection_adapters/abstract_mysql_adapter"
|
22
|
+
require "empty_eye/active_record/connection_adapters/postgresql_adapter"
|
23
|
+
require "empty_eye/active_record/connection_adapters/oci_adapter"
|
24
|
+
require "empty_eye/active_record/connection_adapters/oracle_adapter"
|
25
|
+
require "empty_eye/active_record/connection_adapters/oracleenhanced_adapter"
|
26
|
+
require "empty_eye/active_record/connection_adapters/sqlserver_adapter"
|
27
|
+
require "empty_eye/active_record/connection_adapters/sqlite_adapter"
|
22
28
|
|
23
29
|
module EmptyEye
|
24
30
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: empty_eye
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- thegboat
|
@@ -97,7 +97,13 @@ files:
|
|
97
97
|
- empty_eye.gemspec
|
98
98
|
- lib/empty_eye.rb
|
99
99
|
- lib/empty_eye/active_record/base.rb
|
100
|
-
- lib/empty_eye/active_record/
|
100
|
+
- lib/empty_eye/active_record/connection_adapters/abstract_mysql_adapter.rb
|
101
|
+
- lib/empty_eye/active_record/connection_adapters/oci_adapter.rb
|
102
|
+
- lib/empty_eye/active_record/connection_adapters/oracle_adapter.rb
|
103
|
+
- lib/empty_eye/active_record/connection_adapters/oracleenhanced_adapter.rb
|
104
|
+
- lib/empty_eye/active_record/connection_adapters/postgresql_adapter.rb
|
105
|
+
- lib/empty_eye/active_record/connection_adapters/sqlite_adapter.rb
|
106
|
+
- lib/empty_eye/active_record/connection_adapters/sqlserver_adapter.rb
|
101
107
|
- lib/empty_eye/active_record/schema_dumper.rb
|
102
108
|
- lib/empty_eye/associations/builder/shard_has_one.rb
|
103
109
|
- lib/empty_eye/associations/shard_association_scope.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
class AbstractAdapter
|
4
|
-
#we need this logic to correctly build schema file
|
5
|
-
def tables_without_views
|
6
|
-
#trying to make compatible with rails 2.3.x; failing
|
7
|
-
if respond_to?('execute_and_free')
|
8
|
-
execute_and_free(tables_without_views_sql) do |result|
|
9
|
-
result.collect { |field| field.first }
|
10
|
-
end
|
11
|
-
else
|
12
|
-
result = execute(tables_without_views_sql)
|
13
|
-
rtn = result.collect { |field| field.first }
|
14
|
-
result.free rescue nil
|
15
|
-
rtn
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
#i coulda made this more OO but this seemed to handle more unknown speed bumps
|
22
|
-
#perusing rails_sql_views helped a bit
|
23
|
-
# https://github.com/aeden/rails_sql_views
|
24
|
-
def tables_without_views_sql
|
25
|
-
case self.to_s
|
26
|
-
when /^mysql/i
|
27
|
-
"SHOW FULL TABLES WHERE table_type = 'BASE TABLE'"
|
28
|
-
when /postgresql/i
|
29
|
-
%{SELECT tablename
|
30
|
-
FROM pg_tables
|
31
|
-
WHERE schemaname = ANY (current_schemas(false)) AND table_type = 'BASE TABLE'}
|
32
|
-
when /sqlite/i
|
33
|
-
%{SELECT name
|
34
|
-
FROM sqlite_master
|
35
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'}
|
36
|
-
when /oracle/i
|
37
|
-
"SELECT TABLE_NAME FROM USER_TABLES"
|
38
|
-
when /sqlserver/i
|
39
|
-
"SELECT table_name FROM information_schema.tables"
|
40
|
-
else
|
41
|
-
"SHOW FULL TABLES WHERE table_type = 'BASE TABLE'"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|