Closed its-a-feature closed 3 years ago
Can you check your database for what all foreign keys are present on your Payload
table. Many ways to do this, one way using psql : \d+ tablename
These relationships are being inferred from the underlying foreign keys in the database.
Table "public.payload"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------------------+-----------------------------+-----------+----------+-------------------------------------+----------+--------------+-------------
id | integer | | not null | nextval('payload_id_seq'::regclass) | plain | |
uuid | text | | not null | | extended | |
tag | text | | | | extended | |
operator_id | integer | | not null | | plain | |
creation_time | timestamp without time zone | | not null | | plain | |
payload_type_id | integer | | not null | | plain | |
operation_id | integer | | not null | | plain | |
wrapped_payload_id | integer | | | | plain | |
deleted | boolean | | not null | | plain | |
build_container | text | | not null | | extended | |
build_phase | text | | not null | | extended | |
build_message | text | | not null | | extended | |
callback_alert | boolean | | not null | | plain | |
auto_generated | boolean | | not null | | plain | |
pcallback_id | integer | | | | plain | |
task_id | integer | | | | plain | |
file_id | integer | | | | plain | |
Indexes:
"payload_pkey" PRIMARY KEY, btree (id)
"payload_file_id" btree (file_id)
"payload_operation_id" btree (operation_id)
"payload_operator_id" btree (operator_id)
"payload_payload_type_id" btree (payload_type_id)
"payload_pcallback_id" btree (pcallback_id)
"payload_task_id" btree (task_id)
"payload_uuid" UNIQUE, btree (uuid)
"payload_wrapped_payload_id" btree (wrapped_payload_id)
Foreign-key constraints:
"fk_payload_file_id_refs_filemeta" FOREIGN KEY (file_id) REFERENCES filemeta(id)
"fk_payload_pcallback_id_refs_callback" FOREIGN KEY (pcallback_id) REFERENCES callback(id)
"fk_payload_task_id_refs_task" FOREIGN KEY (task_id) REFERENCES task(id)
"fk_payload_wrapped_payload_id_refs_payload" FOREIGN KEY (wrapped_payload_id) REFERENCES payload(id)
"payload_operation_id_fkey" FOREIGN KEY (operation_id) REFERENCES operation(id)
"payload_operator_id_fkey" FOREIGN KEY (operator_id) REFERENCES operator(id)
"payload_payload_type_id_fkey" FOREIGN KEY (payload_type_id) REFERENCES payloadtype(id)
"payload_wrapped_payload_id_fkey" FOREIGN KEY (wrapped_payload_id) REFERENCES payload(id)
Referenced by:
TABLE "buildparameterinstance" CONSTRAINT "buildparameterinstance_payload_id_fkey" FOREIGN KEY (payload_id) REFERENCES payload(id)
TABLE "c2profileparametersinstance" CONSTRAINT "c2profileparametersinstance_payload_id_fkey" FOREIGN KEY (payload_id) REFERENCES payload(id)
TABLE "callback" CONSTRAINT "callback_registered_payload_id_fkey" FOREIGN KEY (registered_payload_id) REFERENCES payload(id)
TABLE "payload" CONSTRAINT "fk_payload_wrapped_payload_id_refs_payload" FOREIGN KEY (wrapped_payload_id) REFERENCES payload(id)
TABLE "payload" CONSTRAINT "payload_wrapped_payload_id_fkey" FOREIGN KEY (wrapped_payload_id) REFERENCES payload(id)
TABLE "payloadc2profiles" CONSTRAINT "payloadc2profiles_payload_id_fkey" FOREIGN KEY (payload_id) REFERENCES payload(id)
TABLE "payloadcommand" CONSTRAINT "payloadcommand_payload_id_fkey" FOREIGN KEY (payload_id) REFERENCES payload(id)
TABLE "payloadonhost" CONSTRAINT "payloadonhost_payload_id_fkey" FOREIGN KEY (payload_id) REFERENCES payload(id)
Triggers:
newpayload_trigger AFTER INSERT ON payload FOR EACH ROW EXECUTE FUNCTION notify_newpayload()
updatedpayload_trigger AFTER UPDATE ON payload FOR EACH ROW EXECUTE FUNCTION notify_updatedpayload()
In there I also see the two offending lines:
"payload_wrapped_payload_id_fkey" FOREIGN KEY (wrapped_payload_id) REFERENCES payload(id)
"fk_payload_wrapped_payload_id_refs_payload" FOREIGN KEY (wrapped_payload_id) REFERENCES payload(id)
But what's causing it to appear twice and what's the difference? Half of those foreign-key constraints are fk_*_refs_*
and half are *_id_fkey
but I don't see a rhyme or reason what makes the determination
But what's causing it to appear twice and what's the difference? Half of those foreign-key constraints are fk_refs and half are *_id_fkey but I don't see a rhyme or reason what makes the determination
This was already there in the database (i.e. Hasura wouldn't know why it exists). You should check the method by which the table was created initially.
I think i figured it out. Apparently postgres is ok with things being double defined for relationships and doesn't complain. So something was double-defining that relationship which i guess didn't matter with how I was using it before, but when hasura imported and saw the double define, it barfed.
Thanks!
I have an already created Postgres database instance that I'm pointing a new Hasura docker container to. It's successfully reading and ingesting data, but there's one odd quirk that's preventing me from automatically importing everything, and I can't find any documentation on it.
I have a table called
payload
that is defined as the following:The main thing to look at here is:
wrapped_payload = p.ForeignKeyField("self", null=True)
- a field in this table that references anotherPayload
row. When the resulting database is imported by Hasura, I get the following relationships:I can't find out why there are two instance of
wrapped_payload_id
or what the difference is between them. Because two are created, I can't automatically import and have to delete one for the relationships to be added. I can't determine the difference or meaning behind the foreign relationship that ends infkey
or the one that starts withfk
and ends with arefs
. What's confusing me is I have another table, below that works just fine:In this case, I also have
parent = p.ForeignKeyField('self', null=True)
- a field that references an instance of the same table. In this case though, upon parsing the database, only the following entry is created:So, what's the difference between the two examples?