-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
feat: constraints through smart comments (view foreign keys, etc) #365
Conversation
f8c57c1
to
4240df8
Compare
Getting this error for create table post (
id text primary key
);
comment on table post is E'@name post_table
@omit';
create table offer (
id serial primary key,
post_id text references post(id) not null,
);
comment on table offer is E'@name offer_table
@omit';
create view post_view as
SELECT
post.id,
FROM mydb.post post;
comment on view post_view is E'@name posts
@uniqueKey id';
create view offer_view as
SELECT
offer.id,
offer.post_id
FROM mydb.offer offer;
comment on view offer_view is E'@name offers
@uniqueKey id
@foreignKey (post_id) references posts'; A fatal error occurred when building the initial schema, so the process will now exit. Error details:
TypeError: Cannot read property 'namespaceId' of undefined |
That’s a misleading error 👍 |
Continue the previous example: comment on view offer_view is E'@name offers
@uniqueKey id
@foreignKey (post_id) references post_view (id)'; Throws: A fatal error occurred when building the initial schema, so the process will now exit. Error details:
Error: No columns specified for 'mydb.post_view' (oid: 119745) and no PK found (@foreignKey (post_id) references post_view(id)). |
@itaied246 Thanks for these; I've added tests for them and fixed the missing parenthesis which caused the "No columns specified" error. Note you've used |
This now opens up "soft references" - i.e. if you have to tables: Clowns:
People:
Then you could link them together to find people named after clowns, but the constraint is not enforced by the database: comment on table people is E'@foreignKey (name) references clowns (name)|@fieldName namedAfterClown|@foreignFieldName peopleSharingName'; {
allPeople {
nodes {
id
name
namedAfterClown { id name }
}
}
} {
allPeople: {
nodes: [
{ id: 7, name: "Alice", namedAfterClown: null },
{ id: 8, name: "Boris", namedAfterClown: { id: 2, name: "Boris" } },
{ id: 9, name: "Caroline", namedAfterClown: null },
]
}
} (You may have also noticed that I've allowed you to tag these fake constraints too, using the pipe syntax instead of newlines. This is going to get old fast.) |
@foreignKey (col1, col2) references other_table (col3, col4)
(fix(jwt): handle bigint / numeric in JWTs #376)@primaryKey (col1, col2)
Fixes graphile/crystal#376