Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not all data sources are found #1000

Open
DCrow opened this issue Feb 8, 2022 · 5 comments
Open

Not all data sources are found #1000

DCrow opened this issue Feb 8, 2022 · 5 comments

Comments

@DCrow
Copy link

DCrow commented Feb 8, 2022

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
@KDGundermann
Copy link

KDGundermann commented Feb 8, 2022

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?

@DCrow
Copy link
Author

DCrow commented Feb 9, 2022

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.

@aidanharan
Copy link
Contributor

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)?

@DCrow
Copy link
Author

DCrow commented Apr 4, 2023

Something like this should work

ANY(SELECT DISTINCT TABLE_SCHEMA from INFORMATION_SCHEMA.TABLES)

@abhishekup5338
Copy link

Hi @DCrow assign this task to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants