ClosureTree/closure_tree

support timestamps in hierarchy table

eternal-engineer opened this issue · 0 comments

in the auto generated migration for adding hierarchy table, we added timestamps. but on creating a new node, it is giving a

irb(main):002:0> FactoryBot.create(:team, parent_team_id: 1)
   (0.3ms)  BEGIN
  Team Exists (0.4ms)  SELECT  1 AS one FROM "teams" WHERE "teams"."name" = $1 LIMIT $2  [["name", "team_ac"], ["LIMIT", 1]]
  SQL (0.4ms)  INSERT INTO "teams" ("name", "created_at", "updated_at", "parent_team_id") VALUES ($1, $2, $3, $4) RETURNING "id"  [["name", "team_ac"], ["created_at", "2019-10-22 08:18:37.901023"], ["updated_at", "2019-10-22 08:18:37.901023"], ["parent_team_id", 1]]
  Team Load (0.3ms)  SELECT  "teams".* FROM "teams" WHERE "teams"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
   (0.3ms)  SELECT pg_try_advisory_lock(574075692,0) AS ta7593a24a94afc0487630a879bcaeecb /* 699637a87a17acedd4a1b2deb25dd53e7 */
  SQL (0.3ms)  INSERT INTO "team_hierarchies" ("ancestor_id", "descendant_id", "generations", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5)  [["ancestor_id", 2], ["descendant_id", 2], ["generations", 0], ["created_at", "2019-10-22 08:18:37.910341"], ["updated_at", "2019-10-22 08:18:37.910341"]]
   (1.5ms)  INSERT INTO "team_hierarchies"
  (ancestor_id, descendant_id, generations)
SELECT x.ancestor_id, 2, x.generations + 1
FROM "team_hierarchies" x
WHERE x.descendant_id = 1

   (1.0ms)  SELECT pg_advisory_unlock(574075692,0) AS t2c98fa71268f3a49c8d5496ebfc13008 /* 699637a87a17acedd4a1b2deb25dd53e7 */
   (0.2ms)  ROLLBACK
   (0.3ms)  SELECT pg_advisory_unlock(574075692,0) AS ta49a042f283a32125aef86ed4912fb91 /* 699637a87a17acedd4a1b2deb25dd53e7 */
   (0.2ms)  BEGIN
   (0.2ms)  ROLLBACK
Traceback (most recent call last):
        1: from (irb):2
ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR:  null value in column "created_at" violates not-null constraint
DETAIL:  Failing row contains (1, 2, 1, null, null).
: INSERT INTO "team_hierarchies"
  (ancestor_id, descendant_id, generations)
SELECT x.ancestor_id, 2, x.generations + 1
FROM "team_hierarchies" x
WHERE x.descendant_id = 1
)

the library is not passing timestamps. How do we go about this?