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

relation of the Identifier table to the Entity table is not created, gives an error when executing structure.sql #291

Open
turone opened this issue May 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@turone
Copy link

turone commented May 20, 2024

Describe the bug
https://github.com/metatech-university/NodeJS-Application/blob/5749fece58d3c1c060ea668fe1a354d133f708eb/schemas/Identifier.js#L4
One-to-one relations should be to the Entity table. So line 4 should be:
entity: '?Entity',

({
  Entity: {},

  entity: '?Entity',
});

in structure.sql file:
https://github.com/metatech-university/NodeJS-Application/blob/5749fece58d3c1c060ea668fe1a354d133f708eb/db/structure.sql#L9
So line 9 should be:
ALTER TABLE "Identifier" ADD CONSTRAINT "fkIdentifierEntity" FOREIGN KEY ("entityId") REFERENCES "Entity" ("id");
But this generates an error - since the Entity table has not yet been created.

To Reproduce
Identifier.js
({
Entity: {},

entity: '?Entity',
});

Actual behavior
generates in structure.sql file,
CREATE TABLE "Identifier" (
"id" bigint generated always as identity,
"entityId" bigint NULL,
. . .
);
. . .
ALTER TABLE "Identifier" ADD CONSTRAINT "fkIdentifierEntity" FOREIGN KEY ("entityId") REFERENCES "Entity" ("id");
. . .
. . .
CREATE TABLE "Entity" (
. . .
);

Expected behavior
The line must be generated after the Entity table creation line:
generates in structure.sql file,
CREATE TABLE "Identifier" (
. . .
);
. . .
CREATE TABLE "Entity" (
. . .
);
ALTER TABLE "Identifier" ADD CONSTRAINT "fkIdentifierEntity" FOREIGN KEY ("entityId") REFERENCES "Entity" ("id");
Desktop (please complete the following information):

@turone turone added the bug Something isn't working label May 20, 2024
turone added a commit to turone/metasql that referenced this issue May 24, 2024
Fixed an error when creating structure.sql file for a database, when it is necessary to create a relation for tables that refer to each other.
Fixed ussues Metasql metarhia#291
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant