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

Table Creation Order matters for Foreign Keys #26

Open
dlazares opened this issue Jul 2, 2021 · 0 comments
Open

Table Creation Order matters for Foreign Keys #26

dlazares opened this issue Jul 2, 2021 · 0 comments

Comments

@dlazares
Copy link

dlazares commented Jul 2, 2021

When I applied diff on my dev db, the generated sql diff did not execute correctly to my prod db.
When I applied it I got Error: rpc error: code = NotFound desc = Table not found: Images.

Example failure:

CREATE TABLE Posts (
  PostId STRING(2048) NOT NULL,
  Text STRING(MAX),
  FOREIGN KEY (ImageId) REFERENCES Images (ImageId),
) PRIMARY KEY(PostId);

CREATE TABLE Images (
  ImageId STRING(2048) NOT NULL,
  URL STRING(2048),
) PRIMARY KEY(ImageId);

Order matters here due to foreign key so should be:


CREATE TABLE Images (
  ImageId STRING(2048) NOT NULL,
  URL STRING(16),
) PRIMARY KEY(ImageId);

CREATE TABLE Posts (
  PostId STRING(2048) NOT NULL,
  PairSymbol STRING(16),
  FOREIGN KEY (ImageId) REFERENCES Images (ImageId),
) PRIMARY KEY(PostId);

I verified by switching manually that this solved the problem. I think we just need some clever ordering in the library to handle this case.

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

1 participant