Good day.
Does anybody know how to migrate from partitioned gem to pg_party gem?
We have a super old project and try to update.
The partitioned gem uses other schema for partitioned tables, e.g.:
table p201511, schemaname: my_table_name_partitions
table my_table_name, schemaname: public
Second, the partitioned gem doesn't use native PG table partitioning :(
We use partitioning by date.
Link to question in GitHub: https://github.com/rkrage/pg_party/issues/69
Thanks!
I investigated how partitioned gem works and reviewed the https://github.com/rkrage/pg_party docs.
Related
I have dim_user, dim_role and role_user_map tables. I am using rolify gem for authorisation. I don't have role_id as primary key. In my case role_name is the primary key and my role_user_map table will have 2 columns (user_id, role_name) How to change default join_table name and other table names in rolify.rb?
I'm not familiar with it but I did some reading on the Rolify github page The dim_role dim_user and role_user_map tables you had already before you installed the rolify gem? You're supposed to use the gem's generator to create the role model using the syntax rails g rolify You could pass in DimRole and DimUser as arguments instead of just Role and User but again, you're supposed to be letting the gem create the mapping table for you, not having already created it yourself
Look at /db/schema.rb and see the structure of the tables created by the gem then modify and or rename your existing tables to match what the gem expects their structure and names to be Seemingly if you have pre-existing map or "through" tables you're gonna have to fool the gem Create a temporary app and run the gems generator with the names of your pre-existing tables (i don't know if the gem runs migratoins, if not then you have to run rake db:migrate after) then examine the created tables in schema.rb Then go back to your development app and restructure the tables to match the tables in the temp app
I want to save each modification of any database column. For example, if a user updates his/her contact info then my application should update value but also keep save previous value. How can I do it? Is there any gem available?
You can use the PaperTrail gem to do this. You can selectively track database tables and also specify columns to exclude.
It is pretty well documented on the Github page, but basically to set it up all you have to do is (copied directly from the docs):
# Add PaperTrail to your Gemfile.
gem 'paper_trail', '~> 4.0.0'
# Add a versions table to your database.
bundle exec rails generate paper_trail:install
bundle exec rake db:migrate
# Add has_paper_trail to the models you want to track.
class Widget < ActiveRecord::Base
has_paper_trail
end
I'd like to use a database within a Ruby gem that I'm writing. The gem is meant to be used within Rails applications, and will contain an inverted index of documents passed in from the main Rails app.
I'm a bit confused as to how to go about this. Should I hook into the main Rails database somehow? Or should I have a standalone database? Ideally I'd just like to use ActiveRecord to create, update, delete and query entries but I am not sure how I'd set this up.
Data would go into the database at this point:
module ActiveRecordExtension
extend ActiveSupport::Concern
class_methods do
def foo
"bar"
end
end
included do
after_save :add_to_inverted_index
end
def add_to_inverted_index
# This is where I'd take the fields from the Rails app
# and include them to my inverted index. However, I'm struggling
# to find a way to hook into a database from my gem to do this.
end
end
# Include the extension
ActiveRecord::Base.send(:include, ActiveRecordExtension)
Suggestions are much appreciated! Thanks
Well after your clarification, you should use main Rails database. Just create a migration and insert the table(s) you need. You should do that because:
Everyone that uses your gem will know what is stored at the database.
With migrations, you can easily rollback the migration, making it simple to reverse something, if needed.
There's no need to create extra dependencies. Imagine a project that you did in RoR and think if the mess it would be if every gem that you used created its own database.
Maybe you should take a look at known gems and how they do that. I'm thinking about Devise.
Is there a Ruby gem or PostgreSQL extension that would notify when JOIN or WHERE query is used on column(s) without an index?
I´m newbie in RoR and I would like to know how I can do two things in Rails (both versions 2 and 3):
How I can see all queries generated to database (save, update, find, etc.) in the console of the server?
How I can see all the classes and methods of gems included in my Gemfile?
For example how I can see classes and methods of CanCan, Devise and so on.
gem "devise"
gem "cancan"
gem "rolify"
gem "sass-rails"
And so on...
Sorry for my english and thank in advance!!
In your rails folder there will be a log sub-folder. Depending on where your application is running and on your configurations you'll be able to see something similar to a development.log, staging.log or production.log file in that folder.
Also the .to_sql method can be used to show the sql. e.g.
User.where(:id => 29).to_sql will yield the following:
"SELECT `users`.* FROM `users` WHERE `users`.`id` = 29"
For viewing gems. In terminal type bundle show devise this will return you a path. Go to that path. All the necessary code will be present over there.
/home/sohaib/.rvm/gems/ree-1.8.7-2011.03#moviepass/gems/devise-1.4.9