我目前遇到了一个问题,在我的本地计算机上,我可以创建一个记录并将其插入到名为Devices的表中,但在我的heroku部署中,如果标识符和push_token的长度太长,我就无法创建记录。下面粘贴了我正在使用的设备表迁移。
class CreateDevices < ActiveRecord::Migration[6.1]
def change
create_table :devices do |t|
t.string :identifier, null: false
t.string :push_token, null: false
end
end
end
我尝试了一个简单的端点测试,以查看是否使用
get "/test/devices/:device_id/:push_tokens" do
Device.create(identifier: params[:device_id], push_token: params[:push_tokens])
puts "device_count is"
puts Device.count
end
在我的本地机器上,如果我将params[:device_id]和params[:push_tokens]分别设置为例如278 b5 d5668 b7 e2 df 3b 686 e0 c 0 d19 a0 b 9和1319 f7 e0 f6 dd 345304 c5 e8 e84 e5 ec 3f 52213 b8 f485 e4783861 b476373 f000 dde,那么活动记录将更新,设备计数将随之更新。但是,如果我在heroku deploy上尝试这些值,设备计数将不会更新,也不会创建任何记录。我正在努力弄清楚这是否是我在heroku上的postgresql计划的问题,如果我的代码没有等待创建记录
2022-09-23T13:47:45.399683+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789/123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=21779202-b9b6-4e02-9195-6ead6cc63ba6 fwd="147.12.186.203" dyno=web.1 connect=0ms service=9ms status=200 bytes=191 protocol=https
2022-09-23T13:47:45.394194+00:00 app[web.1]: device_count is
2022-09-23T13:47:45.395126+00:00 app[web.1]: 8
2022-09-23T13:47:59.284900+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789/123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=04ef6dab-71c3-4237-b52f-bf2ea16576f0 fwd="147.12.186.203" dyno=web.1 connect=0ms service=7ms status=200 bytes=191 protocol=https
2022-09-23T13:47:59.279643+00:00 app[web.1]: device_count is
2022-09-23T13:47:59.280339+00:00 app[web.1]: 9
2022-09-23T13:48:17.720446+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789/123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=1c221b82-f142-44a0-b0ec-774a8515365a fwd="147.12.186.203" dyno=web.1 connect=0ms service=9ms status=200 bytes=191 protocol=https
2022-09-23T13:48:17.715182+00:00 app[web.1]: device_count is
2022-09-23T13:48:17.715917+00:00 app[web.1]: 10
2022-09-23T13:48:35.566064+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789123456789/123456789123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=2539f65b-7f82-42dc-9c4e-c078b93412d1 fwd="147.12.186.203" dyno=web.1 connect=0ms service=6ms status=200 bytes=191 protocol=https
2022-09-23T13:48:35.560941+00:00 app[web.1]: device_count is
2022-09-23T13:48:35.561519+00:00 app[web.1]: 11
2022-09-23T13:49:00.943300+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789123456789123456789/123456789123456789123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=01acc954-8cf9-4327-8e84-b1958298b14d fwd="147.12.186.203" dyno=web.1 connect=0ms service=8ms status=200 bytes=191 protocol=https
2022-09-23T13:49:00.937948+00:00 app[web.1]: device_count is
2022-09-23T13:49:00.938685+00:00 app[web.1]: 12
2022-09-23T13:49:52.814962+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789123456789123456789/123456789123456789123456789123456789123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=c834c2df-b822-4796-b8ae-ab29cce6bdc2 fwd="147.12.186.203" dyno=web.1 connect=0ms service=5ms status=200 bytes=191 protocol=https
2022-09-23T13:49:52.809811+00:00 app[web.1]: device_count is
2022-09-23T13:49:52.810427+00:00 app[web.1]: 12
我对heroku部署上的端点进行了一些测试,似乎在某个时候,如果字符串对于标识符或push_token来说太长,则不会创建任何记录,但我仍然会收到状态200。我将非常感谢有关此问题的任何帮助!
1条答案
按热度按时间e5nszbig1#
原来在使用Device.create!而不是Device.create之后,没有创建设备的原因是因为device_id已经被占用或push_token已经被占用,这是我的设备型号的问题,而不是活动记录的问题。