You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Rails app which uses tables that are spread across several schemas.
The main tables are in dbo, but some tables are in external, sales, etc.
We mostly use the schemas for access control.
I've been creating tables in other schemas like so:
create_table'external.sales_charts',do |t|
end
The tables are correctly created.
However, they are not properly represented in schema.rb (I can't use structure.sql because there are too many bugs)
Expected behavior
I would expect schema.rb to properly represent the schema-specific table like so:
create_table 'external.sales_charts', do |t|
end
Actual behavior
Instead, it strips the schema from the table name:
create_table 'sales_charts', do |t|
end
This breaks the entire approach of using separate schemas.
How to reproduce
This unit test reproduces the issue.
require"bundler/inline"gemfile(true)dosource"https://rubygems.org"gem"tiny_tds"gem"activerecord","7.0.8"gem"activerecord-sqlserver-adapter","7.0.5.1"endrequire"active_record"require"minitest/autorun"require"logger"ActiveRecord::Base.establish_connection(adapter: "sqlserver",timeout: 5000,pool: 100,encoding: "utf8",database: "test_database",username: "sa",password: "yourStrong(!)Password",host: "localhost",port: 1433,)ActiveRecord::Base.logger=Logger.new(STDOUT)###### This fails when annotated with the `example` schema,# and passes when no schema is specified####TABLE_NAME_WITH_SCHEMA='example.bug_tests'# <-- Change thisActiveRecord::Schema.definedodrop_tableTABLE_NAME_WITH_SCHEMArescuenil# Create the `example` schemaexecute<<-SQL IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'example') BEGIN EXEC('CREATE SCHEMA example') END SQLcreate_tableTABLE_NAME_WITH_SCHEMA,force: truedo |t|
t.bigint:external_idendendclassTestBugTest < Minitest::Testdeftest_schema_dumpschema_filename='test_schema.rb'File.open(schema_filename,"w:utf-8")do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection,file)endfile_contents=File.readschema_filenameassert_includesfile_contents,"create_table \"#{TABLE_NAME_WITH_SCHEMA}\""endend
Details
Rails version: 7.0.8
SQL Server adapter version: 7.0.5.1
TinyTDS version: 2.1.7
FreeTDS details: 1.4.6
Output of tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v1.4.6
freetds.conf directory: /opt/homebrew/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
The text was updated successfully, but these errors were encountered:
This is necessary because schema.rb does not support raw SQL.
We'll need to continue manually adding it until the problems in structure.sql are resolved.
@Michoels Schema dumping was only added to Rails in version 7.1 (rails/rails#49164). I have included schema dumping in the adapters' 7.1 and 7.2 (main) branches. When you have upgraded your application to Rails 7.1 then you will be able to should be able to see the schema dumping in the future 7.1.5 release of the adapter.
Issue
I have a Rails app which uses tables that are spread across several schemas.
The main tables are in
dbo
, but some tables are inexternal
,sales
, etc.We mostly use the schemas for access control.
I've been creating tables in other schemas like so:
The tables are correctly created.
However, they are not properly represented in
schema.rb
(I can't usestructure.sql
because there are too many bugs)Expected behavior
I would expect
schema.rb
to properly represent the schema-specific table like so:Actual behavior
Instead, it strips the schema from the table name:
This breaks the entire approach of using separate schemas.
How to reproduce
This unit test reproduces the issue.
Details
7.0.8
7.0.5.1
2.1.7
1.4.6
Output of
tsql -C
The text was updated successfully, but these errors were encountered: