Giter Club home page Giter Club logo

Comments (8)

metaskills avatar metaskills commented on May 18, 2024

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.

scottjacobsen avatar scottjacobsen commented on May 18, 2024

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.

metaskills avatar metaskills commented on May 18, 2024

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.

trystant avatar trystant commented on May 18, 2024

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.

metaskills avatar metaskills commented on May 18, 2024

That question is related to core ActiveRecord, it is a feature of it, not the adapter.

Model.reset_column_information

from activerecord-sqlserver-adapter.

trystant avatar trystant commented on May 18, 2024

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.

metaskills avatar metaskills commented on May 18, 2024

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.

metaskills avatar metaskills commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.