Tag: postgresql

找出当前时间是否介于两次之间

我有两个时间列存储在Postgresql数据库中: open_time和close_time 。 我试图找出当前时间,忽略日期,是否在两次之间,忽略了日期。 此代码比较日期和时间: current_time = Time.now if current_time.between?(store.open_time, store.close_time) puts “IN BETWEEN” end 例如,当current_time # => 2018-06-06 23:59:49 -0600和open_time # => 2000-01-01 22:59:00 UTC时,它不起作用。 如何让它不包括日期,只是比较时间?

获取意外的用户参数并且无法访问Rails中的密码参数

我开始在Rails with React中设置用户身份validation系统,并且发生了两件奇怪的事情: 1)我的POST请求包括一个user参数,我很确定我没有自己配置(我跟着一本Rails指南书)。 此user参数包含所有其他参数的重复,如下所示: Started POST “/api/user” for 127.0.0.1 at 2018-01-29 21:54:42 -0800 Processing by Api::UserController#create as JSON Parameters: {“email”=>”test@test.com”, “password”=>”[FILTERED]”, “first_name”=>”test”, “last_name”=>”test”, “groupname”=>”test”, “admin”=>”true”, “user”=>{“email”=>”test@test.com”, “first_name”=>”test”, “last_name”=>”test”, “groupname”=>”test”, “admin”=>”true”}} Can’t verify CSRF token authenticity. No template found for Api::UserController#create, rendering head :no_content Completed 204 No Content in 39ms (ActiveRecord: 0.0ms) 2)如果您没有注意到,我的password参数是唯一一个未包含在我的user参数中的password (可能是因为我在我的users模型中调用了has_secure_password ?),我无法弄清楚如何添加它到我的private变量。 […]

Ruby – >将pg_hba.conf的PostgreSQL连接设置为“ident sameuser”而不是“trust”

我已经尝试了我能想到的所有Google搜索词,但是我挖掘的所有东西都在说设置本地连接以trust pg_hba.conf (如果任何人在本地可以登录并访问数据库,就像他们说的那样,这似乎是一个安全漏洞是)。 在pg_hba.conf本地连接设置为ident sameuser 。 该脚本应该以该用户身份运行,但是我收到此错误: A database error occurred: fe_sendauth: no password supplied Ruby代码非常通用: conn_str = “DBI:pg:dbname=mydb;host=” + localhost @connection = DBI.connect(conn_str, “myuser”, ”) 我可以通过创建这里描述的~/.pgpass文件来解决这个问题 ,但我更希望能够让用户登录并只访问数据库服务器。 有没有人能够使PostgreSQL的ident sameuser能够正常使用本地脚本?

Ruby on Rails:搜索后,列出不显示所有数据

我有一个问题,我在搜索中获得了重复的结果,在我的rails应用程序中允许用户搜索数据库中的项目。 这是项目模型中的搜索function: def self.search(search_industry, search_role, search_techs_ids) _projects = Project.scoped if search_industry.present? _projects = _projects.where [‘industry LIKE ?’, like(search_industry)] end if search_role.present? _projects = _projects.where [‘role LIKE ?’, like(search_role)] end if search_techs_ids.present? _projects = _projects.includes(:technols).where(“technols.id” => search_techs_ids) end _projects end 这是我的搜索页面的一部分 Technologies : true} ) %> true, :selected => tech_ids } ) %> 这是我的搜索操作: def search […]

Rails&Heroku:PG db无法创建数据库

我几乎已经阅读了关于部署到heroku的每个问题和文档,这不是我的第一次,但现在在我部署的一个非常奇怪的scnario我无法创建数据库: Running `rake db:create –trace` attached to terminal… up, run.8982 ** Invoke db:create (first_time) ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:create FATAL: permission denied for database “postgres” DETAIL: User does not have CONNECT privilege. /app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.2/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize’ /app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.2/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new’ . . . . Couldn’t create database for {“adapter”=>”postgresql”, “host”=>”ec2-23-23-244-144.compute-1.amazonaws.com”, “encoding”=>”unicode”, “database”=>”d80e387p61nnl1”, “pool”=>5, “template”=>”template0”, […]

防止双向同步进入无限循环

我正在两个数据库之间进行双向同步,就像cloudconnect.com所做的那样。 我正在使用数据库触发器在数据库之间来回发送数据。 我想知道是否可以阻止本地PG数据库在从远程数据库进行更新时调用更新触发器(防止连续循环)。 我尝试使用SET session_replication_role: ‘replica’ ,它有效,但这也会通过禁用列约束来违反数据库完整性。 我当时想要有一个名为disable_trigger的额外字段,并在查询中将其设置为true,我希望触发器不会发生。 但我不想改变数据库的架构。 有谁能建议这样做的方法?

ruby迁移回滚但在再次运行迁移时出错

这是我在RoR应用程序中运行迁移时遇到的错误: PG::Error: ERROR: column “bulk_bill” of relation “questionnaires” already exists 一点背景:我回滚了一个迁移,以便我可以更改列的默认设置。 一旦我再次运行迁移,我就得到了上面的错误。 我可以在开发中的postgresql表中看到该列确实存在。 我在表和bulk_bill列中有一个数据,它的默认设置为false。 我需要采取哪些建议步骤才能成功运行迁移。 我是ruby的初学者,发现ruby文档仍然有点难以理解。 def up add_column :questionnaires, :bulk_bill, :boolean, :default => false end def down remove_column :pnp_questionnaires, :bulk_bill end

请求卡在PG :: Connection #async_exec中

我试图让rails应用程序在passenger下工作,到目前为止没有运气。 它使用sequel连接到postgresql 。 请求随机需要花费太多时间才能完成。 我能够找到应用程序花费时间的地方: %self total self wait child calls name 99.92 65.713 65.713 0.000 0.000 5 PG::Connection#async_exec 0.00 0.002 0.002 0.000 0.000 264 Set#delete … 据说, webrick不会发生这种情况,我会尝试在unicorn下运行它。 这是一些相关的 链接 。 我使用的是passenger-5.0.30 , ruby-2.3.0 , postgresql-9.4 , pg-0.19.0 , rails-5.0.0.1 。 unicorn-5.1.0 。 该应用程序在lxc容器中运行。 主机和客户操作系统是ubuntu/xenial 。

我无法将我的rails应用程序推送到Heroku /获取’pg’gem安装?

最初我无法将我的rails 4应用程序推送到heroku因为我的数据库是sqlite,所以现在我一直在尝试安装Postgresql gem(’pg’),但我没有运气。 这是我在运行bundle install后在终端中收到的错误消息: checking for pg_config… no No pg_config… trying anyway. If building fails, please try again with –with-pg-config=/path/to/pg_config checking for libpq-fe.h… no Can’t find the ‘libpq-fe.h header *** extconf.rb failed *** 跑完之后 gem install pg -v’0.17.1′–with-pg-config 我在终端中收到此错误: ERROR: While executing gem … (Gem::Requirement::BadRequirementError) Illformed requirement [“0.17.1–with-pg_config”] /project$ gem install pg -v ‘0.17.1’–with-pg-config […]

如何使用续集声明postgresql json / jsonb字段?

我坚持认为。 在docs中找不到如何将这样的空间数据类型声明为inet和jsonb或json。 ruby2.4.1,续集4.47 普通ruby脚本require ‘sequel’ 。 宣言如 DB.create_table :requests do primary_key :id foreign_key :client_id, :clients foreign_key :service_id, :services DateTime :created_at, null: false DateTime :answered_at, null: false JsonBType :request, null: false end