Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the ActiveRecord adapter with Rails 4.1 #32

Closed
just3ws opened this issue Jul 26, 2014 · 26 comments
Closed

Using the ActiveRecord adapter with Rails 4.1 #32

just3ws opened this issue Jul 26, 2014 · 26 comments

Comments

@just3ws
Copy link

just3ws commented Jul 26, 2014

Hi, I've followed the instructions from the README to enable ahoy using the built-in ActiveRecordStore but cannot get events or visits to work. The id is always NULL and the insert fails. The project is on Rails 4.1.4 on Postgres. It's all configured using the default generators and no extra configuration. Any ideas?

PG::NotNullViolation: ERROR:  null value in column "id" violates not-null constraint
DETAIL:  Failing row contains (null, bc0ee5ec-2c25-4fad-801f-5160152c1cfc, 127.0.0.1, Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.3..., null, http://localhost:4321/, null, null, null, Chrome, Mac OS X, Desktop, Reserved, null, null, null, null, null, null, null, Web, null, null, 2014-07-26 03:40:27.652412).
: INSERT INTO "visits" ("browser", "country", "device_type", "ip", "landing_page", "os", "platform", "started_at", "user_agent", "visitor_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)

PG::NotNullViolation - ERROR:  null value in column "id" violates not-null constraint
DETAIL:  Failing row contains (null, bc0ee5ec-2c25-4fad-801f-5160152c1cfc, 127.0.0.1, Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.3..., null, http://localhost:4321/, null, null, null, Chrome, Mac OS X, Desktop, Reserved, null, null, null, null, null, null, null, Web, null, null, 2014-07-26 03:40:27.652412).
:
  activerecord (4.1.4) lib/active_record/connection_adapters/postgresql_adapter.rb:834:in `block in exec_cache'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
  activesupport (4.1.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
  activerecord (4.1.4) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `exec_cache'
  activerecord (4.1.4) lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `exec_query'
  activerecord (4.1.4) lib/active_record/connection_adapters/postgresql/database_statements.rb:177:in `exec_insert'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract/database_statements.rb:95:in `insert'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
  activerecord (4.1.4) lib/active_record/relation.rb:64:in `insert'
  activerecord (4.1.4) lib/active_record/persistence.rb:502:in `_create_record'
  activerecord (4.1.4) lib/active_record/attribute_methods/dirty.rb:87:in `_create_record'
  activerecord (4.1.4) lib/active_record/callbacks.rb:306:in `block in _create_record'
  activesupport (4.1.4) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.4) lib/active_support/callbacks.rb:215:in `block in halting_and_conditional'
  activesupport (4.1.4) lib/active_support/callbacks.rb:86:in `run_callbacks'
  activerecord (4.1.4) lib/active_record/callbacks.rb:306:in `_create_record'
  activerecord (4.1.4) lib/active_record/timestamp.rb:57:in `_create_record'
  activerecord (4.1.4) lib/active_record/persistence.rb:482:in `create_or_update'
  activerecord (4.1.4) lib/active_record/callbacks.rb:302:in `block in create_or_update'
  activesupport (4.1.4) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.4) lib/active_support/callbacks.rb:86:in `run_callbacks'
  activerecord (4.1.4) lib/active_record/callbacks.rb:302:in `create_or_update'
  activerecord (4.1.4) lib/active_record/persistence.rb:125:in `save!'
  activerecord (4.1.4) lib/active_record/validations.rb:57:in `save!'
  activerecord (4.1.4) lib/active_record/attribute_methods/dirty.rb:29:in `save!'
  activerecord (4.1.4) lib/active_record/transactions.rb:273:in `block in save!'
  activerecord (4.1.4) lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
  activerecord (4.1.4) lib/active_record/transactions.rb:208:in `transaction'
  activerecord (4.1.4) lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
  activerecord (4.1.4) lib/active_record/transactions.rb:273:in `save!'
   () Users/mike/.rvm/gems/ruby-2.1.2@uglst/bundler/gems/ahoy-2ebf307c7aa6/lib/ahoy/stores/active_record_store.rb:21:in `track_visit'
   () Users/mike/.rvm/gems/ruby-2.1.2@uglst/bundler/gems/ahoy-2ebf307c7aa6/lib/ahoy/tracker.rb:35:in `track_visit'
   () Users/mike/.rvm/gems/ruby-2.1.2@uglst/bundler/gems/ahoy-2ebf307c7aa6/app/controllers/ahoy/visits_controller.rb:5:in `create'
  actionpack (4.1.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.4) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.4) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.1.4) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.1.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.1.4) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.4) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.4) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.1.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.1.4) lib/action_controller/metal.rb:232:in `block in action'
  actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
  actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:50:in `call'
  actionpack (4.1.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:678:in `call'
  railties (4.1.4) lib/rails/engine.rb:514:in `call'
  railties (4.1.4) lib/rails/railtie.rb:194:in `method_missing'
  actionpack (4.1.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:678:in `call'
  oink (0.10.1) lib/oink/middleware.rb:17:in `call'
  meta_request (0.3.3) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.3.3) lib/meta_request/middlewares/headers.rb:16:in `call'
  meta_request (0.3.3) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  bullet (4.13.0) lib/bullet/rack.rb:12:in `call'
  rack-livereload (0.3.15) lib/rack/livereload.rb:23:in `_call'
  rack-livereload (0.3.15) lib/rack/livereload.rb:14:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/flash.rb:254:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.1.4) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.1.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
  activerecord (4.1.4) lib/active_record/migration.rb:380:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.1.4) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.4) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.4) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
   () Users/mike/.rvm/gems/ruby-2.1.2@uglst/bundler/gems/ahoy-2ebf307c7aa6/lib/ahoy/engine.rb:20:in `call_with_quiet_ahoy'
  quiet_assets (1.0.3) lib/quiet_assets.rb:23:in `call_with_quiet_assets'
  request_store (1.0.7) lib/request_store/middleware.rb:8:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.4) lib/action_dispatch/middleware/static.rb:64:in `call'
  heroku_rails_deflate (1.0.3) lib/heroku_rails_deflate/serve_zipped_assets.rb:58:in `call'
  rack (1.5.2) lib/rack/deflater.rb:25:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.4) lib/rails/engine.rb:514:in `call'
  railties (4.1.4) lib/rails/application.rb:144:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
  /Users/mike/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
  /Users/mike/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
  /Users/mike/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
@ankane
Copy link
Owner

ankane commented Jul 26, 2014

#28 refers to a similar issue, but I was unable to reproduce. Try overriding the track_visit method to debug.

class Ahoy::Store < Ahoy::Stores::ActiveRecord

  def track_visit(options)
    Rails.logger.info ahoy.visit_id
    super
  end

end

@ankane
Copy link
Owner

ankane commented Aug 19, 2014

Any update?

@ChrisBr
Copy link

ChrisBr commented Aug 19, 2014

@ankane
Seems like the id is sometimes 0

  SQL (0.7ms)  INSERT INTO "ahoy_events" ("id", "name", "properties", "time", "user_id", "visit_id") VALUES (?, ?, ?, ?, ?, ?)  [["id", 0], ["name", "Registered"], ["properties", "{\"title\":\"New registration\"}"], ["time", "2014-08-19 11:23:21.894602"], ["user_id", 2], ["visit_id", "\x824l\xA5\xC3\xAEH\xA3\xB8\x91\xAC\xF1j~\xCE\xAC"]]
SQLite3::ConstraintException: PRIMARY KEY must be unique: INSERT INTO "ahoy_events" ("id", "name", "properties", "time", "user_id", "visit_id") VALUES (?, ?, ?, ?, ?, ?)

This happens meanwhile really often with SQLite!

@ankane
Copy link
Owner

ankane commented Aug 20, 2014

Can you try the code above to see what gets logged? This one is perplexing, but seems to affect a decent number of people.

@ChrisBr
Copy link

ChrisBr commented Aug 20, 2014

@ankane I've added the code above in

models/ahoy/store.rb

Unfortunately nothing gets logged!

Can I contact you via IRC or sth similiar?

@ankane
Copy link
Owner

ankane commented Aug 21, 2014

Sure, email me from my Github profile.

@ankane
Copy link
Owner

ankane commented Aug 31, 2014

Any update?

@ckmorris
Copy link

We're running 4.1.5 and seeing quite a few of these in our platform as well.

@sergey-alekseev
Copy link

I have the same issues.

@ankane
Copy link
Owner

ankane commented Oct 1, 2014

@ckmorris @sergey-alekseev which database (and version) and Ahoy::Store are you using? Is activeuuid installed? It definitely sounds like there's an issue, but having trouble reproducing on my own.

@sergey-alekseev
Copy link

@ankane

$ psql --version
psql (PostgreSQL) 9.3.5

> Ahoy::VERSION
=> "1.0.1"

activeuuid is not installed.

@ckmorris
Copy link

ckmorris commented Oct 7, 2014

ditto on the versions

@ankane
Copy link
Owner

ankane commented Oct 7, 2014

Tried this exact setup but still no luck. Tried it with the ossp-uuid extension and without. Does this happen every time, or just occasionally? Not sure where to go from here.

@sergey-alekseev
Copy link

I used ossp-uuid as well, but then switched back.
Also forgot to mention I tried rails 4.1.6, but there were problems, so I switched back too.
Other developers on a project don't have such a bug. I fixed it by adding primary keys manually in psql.

@pbrueske
Copy link

pbrueske commented Oct 9, 2014

I had the same error and fixed it by these migrations:

enable_extension "uuid-ossp"

change_column :visits, :id, :uuid, :default => 'uuid_generate_v4()'
change_column :ahoy_events, :id, :uuid, :default => 'uuid_generate_v4()'

@ankane
Copy link
Owner

ankane commented Oct 9, 2014

@pbrueske unfortunately, adding a default will mask the issue as far as I can tell, since the database will generate its own UUID rather than store the one Ahoy gives it. I'd check that ahoy.getVisitId() in the Javascript console matches the one stored in the id column on visits.

@sergey-alekseev
Copy link

@ankane I enabled the same extension (enable_extension "uuid-ossp") for a while. Maybe it's the reason of the issue.

@grossadamm
Copy link

Not sure if this is the right place for this, but I also occasionally see the Unique constraint fail for ahoy_events.id

module Ahoy
  class Store < Ahoy::Stores::ActiveRecordStore
    def track_event(name, properties, options, &block)
      p options[:id]
      super(name, properties, options, &block)
    end
  end
end

The message

"0b671c01-378a-40b4-b8b9-f9a6442ae519"
SQLite3::ConstraintException: UNIQUE constraint failed: ahoy_events.id: INSERT INTO "ahoy_events" ("id", "name", "properties", "time", "user_id", "visit_id") VALUES (?, ?, ?, ?, ?, ?)

The request payload to /ahoy/events

[{"id":"0b671c01-378a-40b4-b8b9-f9a6442ae519","name":"$view","properties":{"url":"http://localhost:3000/foo_app/people/1/social","title":"John Doe","page":"/foo_app/people/1/social"},"time":1415199863.45}]

Interestingly, the values of the id's in the ahoy_events table are not uuids.

sqlite> select id from ahoy_events;
1
4
5
...

@grossadamm
Copy link

After delving into ActiveUUID, there are some issues with the schema dumper (jashmenn/activeuuid#21). In order to get a uuid id column I had to modify the schema manually, despite having the proper migrations in place and migrated.

before

  create_table "ahoy_events", force: true do |t|
    t.uuid     "visit_id"
    t.integer  "user_id"
    t.string   "name"
    t.text     "properties"
    t.datetime "time"

after

create_table "ahoy_events", id: false, force: true do |t|
    t.uuid     "id", primary_key: true
    t.uuid     "visit_id"
    t.integer  "user_id"
    t.string   "name"
    t.text     "properties"
    t.datetime "time"

That resolved my unique constraint issues in sqlite

@ChrisBr
Copy link

ChrisBr commented Dec 16, 2014

@grossadamm @ankane

Following your suggestions on altering the migration

create_table "ahoy_events", id: false, force: true do |t|
    t.uuid     "id", primary_key: true
    t.uuid     "visit_id"
    t.integer  "user_id"
    t.string   "name"
    t.text     "properties"
    t.datetime "time"

I get in fact an uuid unique id column, unfortunately it's possible to set an not null value to it (and I guess that shouldn't be possible for an primary key!)
If I try to add not null manually in an migration by

   change_column :ahoy_events, :id, :uuid
   change_column_null :ahoy_events, :id, false 
   add_index :ahoy_events, :id, unique: true

ahoy doesn't work properly afterward (I guess it doesn't know whats the primary key anymore...).
Thanks your help in advance!

@lazyatom
Copy link

I think I might've fixed this. I'm using Ahoy 1.1.1 and ActiveRecord 4.1.5 and I hit this issue, and used a debugger to trace it down to the assignment of the generated id into the event model (https://github.com/ankane/ahoy/blob/master/lib/ahoy/stores/active_record_store.rb#L29). Checking the value of e.id after the assignment, it's nil, and it's this nil that causes the database to complain.

It turns out the assignment doesn't happen because active record doesn't know what the primary key attribute of the class is. For ActiveRecord 4.1.5, the appropriate method is in ActiveRecord::AttributeMethods::PrimaryKey#id= (https://github.com/rails/rails/blob/9bb76261d39b59e7e229c80d052ca91a65ff17be/activerecord/lib/active_record/attribute_methods/primary_key.rb#L25). The assignment only occurs if self.class.primary_key is true, but in the case of my Ahoy::Event class, it's nil.

To fix this in the short term, I simply added self.primary_key = :id to my Ahoy::Event class.

@rcrcr-omni
Copy link

Hi. I'm experiencing issues with this too. Tried lazyatom's solution but no joy.

Error here:

Mar 17 08:45:56 squareshaped app/web.1:  PG::UniqueViolation: ERROR:  duplicate key value   violates unique constraint "ahoy_events_pkey" 
Mar 17 08:45:56 squareshaped app/web.1:  DETAIL:  Key (id)=(0) already exists. 
Mar 17 08:45:56 squareshaped app/web.1:  : INSERT INTO "ahoy_events" ("id", "name", "properties", "time", "visit_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id" 

PostgreSQL running on Heroku with Rails 4.2

@turboladen
Copy link

FWIW, I'm running into this and I'm not using ahoy. Only seem to be seeing it with Rails 4.2, but I'm not sure if that's relevant or not. I'm debugging now and see that at some point, something added default: nil (and removed limits on my strings) to my schema. There wasn't anything else significant in my git history that would indicate this change. I did update from PG 9.3.5 to 9.4.1 at that time...

WRT the limit thing, I did come across rails/rails#19001, which seems to point to something in my DB changing which would cause Rails to pick that up and put it in the schema.rb.

I went back through all of my migrations and added default: 'uuid_generate_v4()', then see:

== 20140908235503 CreateImageryProducts: migrating ============================
-- create_table(:imagery_products, {:id=>:uuid, :default=>"uuid_generate_v4()"})

...etc. in my migration output, yet my schema.rb still shows default: nil. Also bizarro is that when I look at my table schemas for my dev vs. test environments, the test environment doesn't pick up the "uuid_generate_v4()".

No solutions yet here, just thought I'd share my findings.

@mikeghen
Copy link

mikeghen commented Feb 5, 2016

I am having a similar issue, any new development? What's the deal with PR #44?

@ankane
Copy link
Owner

ankane commented Jan 13, 2017

Closing the issue, as UUID is no longer the default.

@ankane ankane closed this as completed Jan 13, 2017
@darrenterhune
Copy link

Been seeing this recently in a rails 3.2.22 app, postgres 9.6, ahoy_matey 1.6.1

Failing in rails 3 app:

ahoy_matey-1.6.0
users -> not null default nextval('users_id_seq'::regclass)
ahoy_events -> not null

Working in rails 5 app:

ahoy_matey-1.6.1
users -> not null default nextval('users_id_seq'::regclass)
ahoy_events -> not null default nextval('ahoy_events_id_seq'::regclass)

See how the postgres modifiers are defined? Not sure if this is the problem. Seems to have just started happening. Any new migrations that create a table only list not null and don't have the default nextval from sequence.

\d visits_id_seq
Did not find any relation named "visits_id_seq".
\d ahoy_events_id_seq
Did not find any relation named "ahoy_events_id_seq".
\d users_id_seq
Sequence "public.users_id_seq"
Column     |  Type   |        Value        
---------------+---------+---------------------
 sequence_name | name    | users_id_seq
 last_value    | bigint  | 1
 start_value   | bigint  | 1
 increment_by  | bigint  | 1
 max_value     | bigint  | 9223372036854775807
 min_value     | bigint  | 1
 cache_value   | bigint  | 1
 log_cnt       | bigint  | 32
 is_cycled     | boolean | f
 is_called     | boolean | t
Owned by: public.users.id

🤔 that's strange... ok

rake db:migrate:down versions where ahoy_events and visits are added then specifically adding the sequence to the create_table block:

create_table :ahoy_events, id: :integer, default: -> { "nextval('ahoy_events_id_seq'::regclass)" } do |t|
...
\d ahoy_events;
not null default nextval('ahoy_events_id_seq'::regclass)
mdasap_dev=# \d ahoy_events_id_seq
Sequence "public.ahoy_events_id_seq"
Column     |  Type   |        Value        
---------------+---------+---------------------
 sequence_name | name    | ahoy_events_id_seq
 last_value    | bigint  | 1
 start_value   | bigint  | 1
 increment_by  | bigint  | 1
 max_value     | bigint  | 9223372036854775807
 min_value     | bigint  | 1
 cache_value   | bigint  | 1
 log_cnt       | bigint  | 0
 is_cycled     | boolean | f
 is_called     | boolean | f
Owned by: public.ahoy_events.id

Thats better... and now it seems that failure is working. I'm not sure why that sequence isn't getting added. I have jumped between postgres versions so that could be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests