Comments (8)
When I added stronger view support to the adapter back in the day, I created a method chain to the standard #reset_column_information for ActiveRecord.
http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb#L42
http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/schema_statements.rb#L324
This basically gives us our own column information cache before handing things back up to ActiveRecord. The benefits were that we included column information for views as well. Most schema statements that alter a table call remove_sqlserver_columns_cache_for(table_name). I'm sure that would be the hook point.
Lastly, I dont want to get into the A depends on T, depends on B situation. If a person's views structure is that complicated. Let them use :execute_procedure inside the migration and do the leg work on their own. I'm for a simple tested patch when you have the time :)
from activerecord-sqlserver-adapter.
Thanks. I'll take a look at those links.
The tree of dependencies is exactly the itch I need to scratch on our project. I'm trying to move us away from tools that handle that nicely (redgate), but do everything else worse than migrations (IMHO). Maybe I'll try and implement it as a module you can just drop into your project's lib or vendor directory. Could think of it as a sqlserver adapter plugin. Adapter plugins sound like a cool idea to me :)
from activerecord-sqlserver-adapter.
Me too, IE, method chain our method chain or a core method like remove_sqlserver_columns_cache_for. Very interested to see what you come up with! Cheers.
from activerecord-sqlserver-adapter.
Hi,
I'm running into a related issue where I've updated a table, but the Adapter has old columns from a previous migration in the list of attributes. Here's the table:
Column_name Type Computed Length Prec Scale Nullable TrimTrailingBlanks FixedLenNullInSource Collation
id int no 4 10 0 no (n/a) (n/a) NULL
client_id int no 4 10 0 no (n/a) (n/a) NULL
model_name varchar no 50 no no no SQL_Latin1_General_CP1_CI_AS
population decimal no 9 18 4 yes (n/a) (n/a) NULL
currency_code varchar no 3 yes no yes SQL_Latin1_General_CP1_CI_AS
first_landing int no 4 10 0 yes (n/a) (n/a) NULL
created_at datetime no 8 yes (n/a) (n/a) NULL
updated_at datetime no 8 yes (n/a) (n/a) NULL
and here's the attributes for the Model:
ree-1.8.7-2010.02 :001 > m = Model.new
=> #<Model id: nil, id: nil, client_id: nil, client_id: nil, model_name: nil, dimension_name: nil, dimension_value: nil, population: nil, currency_code: nil, custom_value: nil, created_at: nil, custom_value: nil, first_landing: 0, updated_at: nil, created_at: nil, updated_at: nil
How can I flush the column cache or reset column information? Thanks,
from activerecord-sqlserver-adapter.
That question is related to core ActiveRecord, it is a feature of it, not the adapter.
Model.reset_column_information
from activerecord-sqlserver-adapter.
Ah, thanks for the tip. I tried calling that method in the console, but unfortunately the stale column definitions are still being recognized by the database
ree-1.8.7-2010.02 :003 > Model.reset_column_information
m = Model.new
=> #<Model id: nil, id: nil, client_id: nil, client_id: nil, model_name: nil, dimension_name: nil, dimension_value: nil, population: nil, currency_code: nil, custom_value: nil, created_at: nil, first_landing: 0, created_at: nil, updated_at: nil, updated_at: nil>
I only posted here because I'm using both mysql and sqlserver adapters in different environment; sqlserver for dev and mysql for test. The test environment using the MySQL adapter shows the correct # of columns, while the SQL Server Adapter does not:
[mnyon@nyon ~/Documents/workspace/mroi (svn::39689:/apps) ] RAILS_ENV=test s-c
Loading test environment (Rails 2.3.5)
ree-1.8.7-2010.02 :001 > m = Model.new
=> #<Model id: nil, client_id: nil, model_name: nil, population: nil, currency_code: nil, first_landing: 0, created_at: nil, updated_at: nil>
If there's another place I should submit this, please let me know. Thanks,
from activerecord-sqlserver-adapter.
I think you just have a simple problem of knowing what the code is doing. Migrations are run against a connection, not all connections & environments to different DBs. These queries are (1) outside the scope of this ticket and (2) outside the scope of the adapter, please ask questions for help on rails-talk, etc.
from activerecord-sqlserver-adapter.
Closing this old issue out. I think using sp_refresh is best left as (a) something the user knowingly needs to do when altering view dependent schemas or (b) part of another library that would like to take up the work in solving this problem in an abstract way for multiple adapters.
from activerecord-sqlserver-adapter.
Related Issues (20)
- ActiveRecord::ConnectionAdapters::SQLServerAdapter does not support upsert HOT 2
- Warning: undefining the allocator of T_DATA class TinyTds::Result HOT 1
- TinyTds::Error: Server name not found in configuration files HOT 1
- 7.0.2.0 identity insert issue
- Tests failing following release of Rails v7.0.5
- Rails 7.1 HOT 1
- Copyright missing the Copyright owner
- [Rails 7.1] Upgrading the MSSQL adapter HOT 7
- Migration to Create Stored Procedure Incorrectly Treated as an Insert Statement HOT 1
- NotNullViolation in boolean field of view HOT 7
- TinyTds::Error: Error converting data type varchar to numeric. HOT 6
- String default value not retrieved when using views HOT 4
- Tracking rails/solid_cache compatibility
- Default value read from another field HOT 1
- Is add_check_constraint supported? HOT 3
- `raw_connection_do` method removed in 7.1.0 but still referenced in Readme HOT 2
- Composite Primary Keys not being recognised HOT 2
- limit() method with subqueries HOT 3
- Tables that are in schemas other than `dbo` are not properly reproduced in schema.rb HOT 1
- exclude_output_inserted_table_names does not support composite primary keys with different data types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activerecord-sqlserver-adapter.