activerecord-sqlserver-adapter
activerecord-sqlserver-adapter copied to clipboard
Not all data sources are found
Issue
When using a database with multiple schemas, not all tables are found for method
ActiveRecord::Base.connection.data_sources
It seems to stem from this line.
When ActiveRecord::Base.connection.data_source_sql
is called, it's called without any parameters and because of that quoted_scope
(inside that method) always returns dbo
.
Maybe this adapter should search all schemas like postgres adapter not just dbo
?
Expected behavior
I'm expecting that all tables with different schemas are found.
Actual behavior
Tables with schemas other than dbo
are not found.
How to reproduce
See example
Details
-
Rails version:
6.0.4.4
-
SQL Server adapter version:
6.0.4.4
-
TinyTDS version:
2.1.5
- FreeTDS details:
Compile-time settings (established with the "configure" script)
Version: freetds v1.3.6
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 7.3
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: yes
GnuTLS: no
MARS: yes
See also: #998 I assume the current user (sa?) has the dbo schema as default schema. Why should we enumerate all others schemas? How should it handled if there are duplicate names?
Why should we enumerate all others schemas?
We should enumerate since other database adapters support this.
For example rails postgres adapter. It also supports which schemas to enumerate using schema_search_path
option in database.yml.
How should it handled if there are duplicate names?
I think data_sources should return names with schema, so that it will be possible to differentiate same table names with different schemas. Also it should be noted that truncating tables doesn't always work if you use a table which has a different schema from default.
Is there an SQL Server equivalent to PostgreSQL's ANY (current_schemas(false))
(https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L749)?
Something like this should work
ANY(SELECT DISTINCT TABLE_SCHEMA from INFORMATION_SCHEMA.TABLES)