rails-postgresql

Rspec: How to suppress warnings and notices when running tests?

自闭症网瘾萝莉.ら 提交于 2019-12-10 01:56:51
问题 I was using Mysql database before and decided to switch to Postgresql and now, when I run my tests using rspec, I getting a lot of warnings and notices. WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has link "Suspender" WARNING: there is already a transaction in progress NOTICE: there is no transaction in progress should has css "title" with text "Suspensão de anúncio" WARNING: there is already a transaction in progress NOTICE: there is

Retrieve the nextval from a sequence using activerecord in Ruby on Rails 3.2.14 / Ruby 2.0.0 / PostgreSQL 9.2.4

时光毁灭记忆、已成空白 提交于 2019-12-10 01:44:10
问题 This should be SO simple. I want to retrieve the nextval of a sequence... it's not a default value... it's not a primary key... it's not a foreign key. In rare cases, I need a sequence number for a user supplied value. I've tried the following: @nextid = ActiveRecord::Base.connection.execute("SELECT nextval('xscrpt_id_seq')") and what I get back is: #<PG::Result:0x007fe668a854e8 @connection=#<PG::Connection:0x00000003aeff30>> And by using @nextid[0]["nextval"] I can get the correct value, but

Rails doesn't convert timezone (PostgreSQL)

一曲冷凌霜 提交于 2019-12-09 18:08:32
问题 I have a problem with timezones and a postgresql db (Rails 3.0.4, PostgreSQL 9.0). I'm using a custom scope, in which I append some conditions, do joins etc.pp. The problem is, that Rails don't convert the times to my local timezone. Here is the code of the scope: scope :with_activities_within_range_in_week, lambda{ |latMin, lngMin, latMax, lngMax, date| select("date_trunc('day', activities.starting_at) as date, count(activities.id) as value ") \ .within(latMin, lngMin, latMax, lngMax) \

How can I create a Postgres user and database whenever I create a new rails app?

夙愿已清 提交于 2019-12-09 06:31:47
问题 I have followed this really helpful tutorial: http://blog.willj.net/2011/05/31/setting-up-postgresql-for-ruby-on-rails-development-on-os-x/ I would really like to run rails new myapp and have the postgres db set up automatically. Is there any way I can do that using a Rails application template or something similar? 回答1: On a unix based system: sudo -u postgres createuser -d -R -P APPNAME sudo -u postgres createdb -O APPNAME APPNAME You can create a script and put it somewhere in your $PATH

Ruby on Rails: must appear in the GROUP BY clause or be used in an aggregate function [duplicate]

眉间皱痕 提交于 2019-12-08 14:09:07
问题 This question already has answers here : PostgreSQL -must appear in the GROUP BY clause or be used in an aggregate function (4 answers) Closed 5 years ago . This is my query. ShopifyOrderLineItem.select("shopify_order_line_items.*, sum(amount) as total_price, sum(quantity) as total_quantity").where(:vendor_id => vendor_id).group("shopify_order_line_items.title") I'm getting the following exception. PG::GroupingError: ERROR: column "shopify_order_line_items.id" must appear in the GROUP BY

Newly assigned Sequence is not working

ⅰ亾dé卋堺 提交于 2019-12-07 16:38:10
问题 In PostgreSQL, I created a new table and assigned a new sequence to the id column. If I insert a record from the PostgreSQL console it works but when I try to import a record from from Rails, it raises an exception that it is unable to find the associated sequence. Here is the table: \d+ user_messages; Table "public.user_messages" Column | Type | Modifiers | Storage | Description -------------+-----------------------------+------------------------------------------------------------+---------

Replace NULL values in an array in PostgreSQL

好久不见. 提交于 2019-12-07 06:49:40
问题 SELECT ARRAY[1,2,3] - ARRAY[5,NULL,6] I am using contrib _int.sql package for array operations in postgresql 8.4 In the above query there is a NULL in right hand side array. Because of this NULL value, it throws an error: "ERROR: array must not contain nulls" Can anyone help me to remove the null values from the array? 回答1: 1) Arrays can contain NULL values in PostgreSQL 8.4+ db=# SELECT ARRAY[5,NULL,6]; array ------------ {5,NULL,6} 2) But you cannot subtract one ARRAY from another in

Rails multitenant architecture, scoping access to multiple tenants

天涯浪子 提交于 2019-12-06 10:36:38
问题 We have a single-tenant database architecture at the moment with MySQL running upward of 100 databases. We switch database connection on subdomain using the Apartment gem and all is dandy! However, we have a requirement now to create so-called "Umbrella" clients which can access all the data from a group of our existing clients. I don't see this as immediately feasible with our single-tenant database architecture (I looked into it and querying multiple MySQL databases just seemed hellish), so

Ransack, Postgres - sort on column from associated table with distinct: true

浪子不回头ぞ 提交于 2019-12-05 23:17:44
问题 I have an app that uses the Ransack gem and I'm converting it from Mysql to Postgres. In an instance where the sort column is from an associated table and the distinct option is set to true, Postgres throws this error: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list The Ransack github page says that, in a case like this, "you're on your own." What's the best - any! - strategy for handling this scenario? q = Contact.includes(:contact_type

postgresql 9.3 log slow queries

最后都变了- 提交于 2019-12-05 13:58:20
I am using Rails application with Postgres 9.3 database and doing some performance fixes. I would like to know how to find out slowest queries in log files. let say queries taking more then 30ms. In postgresql.conf you should uncomment line #log_min_duration_statement = -1 and change its value to 30. This way queries longer than 30ms will be logged 来源: https://stackoverflow.com/questions/41746897/postgresql-9-3-log-slow-queries