Skip to content

Commit

Permalink
Merge branch 'main' into global-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
lolopinto committed Aug 2, 2022
2 parents 478544a + 8b67155 commit d6395f2
Show file tree
Hide file tree
Showing 29 changed files with 9,486 additions and 5,164 deletions.
13,682 changes: 8,598 additions & 5,084 deletions examples/simple/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
"license": "ISC",
"devDependencies": {
"@alex_neo/jest-expect-message": "^1.0.5",
"@snowtop/ent-graphql-tests": "^0.1.0-alpha2",
"@snowtop/ent-graphql-tests": "^0.1.0-alpha3",
"@types/bcryptjs": "^2.4.2",
"@types/express": "^4.17.11",
"@types/jest": "^27.0.3",
"@types/jest": "^28.1.6",
"@types/jest-expect-message": "^1.0.3",
"@types/jsonwebtoken": "^8.5.1",
"@types/supertest": "^2.0.11",
"cookie-parser": "^1.4.5",
"jest": "^27.4.3",
"jest": "^28.1.3",
"jest-date-mock": "^1.0.8",
"supertest": "^6.1.3",
"ts-jest": "^27.0.5",
"ts-jest": "^28.0.7",
"tsconfig-paths": "^3.11.0"
},
"dependencies": {
"@snowtop/ent": "^0.1.0-alpha51",
"@snowtop/ent": "^0.1.0-alpha56",
"@snowtop/ent-email": "^0.1.0-alpha1",
"@snowtop/ent-passport": "^0.1.0-alpha1",
"@snowtop/ent-password": "^0.0.1",
"@snowtop/ent-password": "^0.1.0-alpha1",
"@snowtop/ent-phonenumber": "^0.1.0-alpha1",
"@types/express-session": "^1.17.3",
"@types/graphql-upload": "^8.0.11",
Expand Down
4 changes: 4 additions & 0 deletions examples/simple/src/ent/generated/contact_base.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions examples/simple/src/ent/tests/contact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CreateContactAction, {
import { UserToContactsQuery } from "../user/query/user_to_contacts_query";
import EditContactAction from "../contact/actions/edit_contact_action";
import { LoggedOutExampleViewer, ExampleViewer } from "../../viewer/viewer";
import { query } from "@snowtop/ent";

const loggedOutViewer = new LoggedOutExampleViewer();

Expand Down Expand Up @@ -200,6 +201,22 @@ test("multiple emails", async () => {
})
.sort(sortFn),
);

const r = await Contact.loadCustom(
contact.viewer,
query.PostgresArrayContainsValue("email_ids", emails[0].id),
);
expect(r.length).toBe(1);
expect(r[0].id).toBe(contact.id);
const r2 = await Contact.loadCustom(
contact.viewer,
query.PostgresArrayContains(
"email_ids",
emails.map((email) => email.id),
),
);
expect(r2.length).toBe(1);
expect(r2[0].id).toBe(contact.id);
});

test("multiple phonenumbers", async () => {
Expand Down Expand Up @@ -241,4 +258,20 @@ test("multiple phonenumbers", async () => {
})
.sort(sortFn),
);

const r = await Contact.loadCustom(
contact.viewer,
query.PostgresArrayContainsValue("phone_number_ids", phoneNumbers[0].id),
);
expect(r.length).toBe(1);
expect(r[0].id).toBe(contact.id);
const r2 = await Contact.loadCustom(
contact.viewer,
query.PostgresArrayContains(
"phone_number_ids",
phoneNumbers.map((p) => p.id),
),
);
expect(r2.length).toBe(1);
expect(r2[0].id).toBe(contact.id);
});
2 changes: 2 additions & 0 deletions examples/simple/src/schema/contact_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ const ContactSchema = new EntSchema({

fields: {
email_ids: UUIDListType({
index: true,
defaultValueOnCreate: () => [],
fieldEdge: { schema: "ContactEmail" },
}),
phone_number_ids: UUIDListType({
index: true,
defaultValueOnCreate: () => [],
fieldEdge: { schema: "ContactPhoneNumber" },
}),
Expand Down
2 changes: 2 additions & 0 deletions examples/simple/src/schema/schema.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/simple/src/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ CREATE TABLE contacts (
CONSTRAINT contacts_user_id_fkey FOREIGN KEY(user_id) REFERENCES users (id) ON DELETE CASCADE
);

CREATE INDEX contacts_email_ids_idx ON contacts USING gin (email_ids);

CREATE INDEX contacts_phone_number_ids_idx ON contacts USING gin (phone_number_ids);

CREATE INDEX contacts_user_id_idx ON contacts (user_id);

INSERT INTO assoc_edge_config(edge_name, edge_type, edge_table, symmetric_edge, inverse_edge_type, created_at, updated_at) VALUES('AddressToHostedEventsEdge', 'd1979d4b-d033-4562-b078-cc528fec25bb', 'address_hosted_events_edges', false, NULL, now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('CommentToPostEdge', 'f430af94-d38a-4aaa-a92f-cfc56b6f811b', 'object_comments_edges', false, '8caba9c4-8035-447f-9eb1-4dd09a2d250c', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('EventToAttendingEdge', '6ebc0c47-ea29-4635-b991-95e44162174d', 'event_rsvps_edges', false, '2a98ba02-e342-4bb4-93f6-5d7ed02f5c48', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('EventToDeclinedEdge', 'db8d2454-f7b2-4147-aae1-e666daf3f3c3', 'event_rsvps_edges', false, '1c7c173b-63ce-4002-b121-4a87f82047dd', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('EventToHostsEdge', 'ebe3e709-845c-4723-ac9c-29f983f2b8ea', 'event_hosts_edges', false, 'cf6542a4-8bae-427f-8a1f-01194047afb3', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('EventToInvitedEdge', 'a72f5f64-3580-44fd-9bd0-d1335b803a46', 'event_rsvps_edges', false, 'e439f2b2-d93a-4d1a-83f0-865bda5c8337', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('EventToMaybeEdge', 'b0f6311b-fdab-4c26-b6bf-b751e0997735', 'event_rsvps_edges', false, '8d5b1dee-ce65-452e-9f8d-78eca1993800', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('GlobalToLoginAuthEdge', '13eb6687-d226-4272-ba65-d5e33e00954c', 'global_login_auth_edges', false, NULL, now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('ObjectToCommentsEdge', '8caba9c4-8035-447f-9eb1-4dd09a2d250c', 'object_comments_edges', false, 'f430af94-d38a-4aaa-a92f-cfc56b6f811b', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('ObjectToLikersEdge', 'c9ccdad9-7aff-40e4-9a69-2c29cfa19763', 'object_likers_edges', false, '745a20bf-4fdc-4862-b39f-569c4451db8f', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToCreatedEventsEdge', 'daa3b2a3-8245-40ca-ae77-25bfb82578a7', 'user_created_events_edges', false, NULL, now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToDeclinedEventsEdge', '1c7c173b-63ce-4002-b121-4a87f82047dd', 'event_rsvps_edges', false, 'db8d2454-f7b2-4147-aae1-e666daf3f3c3', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToEventsAttendingEdge', '2a98ba02-e342-4bb4-93f6-5d7ed02f5c48', 'event_rsvps_edges', false, '6ebc0c47-ea29-4635-b991-95e44162174d', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToFriendsEdge', 'd1a9316d-090f-4b02-b393-fd9372e2c905', 'user_friends_edges', true, NULL, now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToHostedEventsEdge', 'cf6542a4-8bae-427f-8a1f-01194047afb3', 'event_hosts_edges', false, 'ebe3e709-845c-4723-ac9c-29f983f2b8ea', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToInvitedEventsEdge', 'e439f2b2-d93a-4d1a-83f0-865bda5c8337', 'event_rsvps_edges', false, 'a72f5f64-3580-44fd-9bd0-d1335b803a46', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToLikesEdge', '745a20bf-4fdc-4862-b39f-569c4451db8f', 'object_likers_edges', false, 'c9ccdad9-7aff-40e4-9a69-2c29cfa19763', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToMaybeEventsEdge', '8d5b1dee-ce65-452e-9f8d-78eca1993800', 'event_rsvps_edges', false, 'b0f6311b-fdab-4c26-b6bf-b751e0997735', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToPostEdge', '4b725578-e9f5-472c-8e57-e47481c9e1b8', 'object_comments_edges', false, '8caba9c4-8035-447f-9eb1-4dd09a2d250c', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToSelfContactEdge', 'd504201d-cf3f-4eef-b6a0-0b46a7ae186b', 'user_self_contact_edges', false, NULL, now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC'), ('UserToUserToHostedEventsEdge', 'e5555185-91bf-4322-8130-d0a00eb605b7', 'event_hosts_edges', false, 'ebe3e709-845c-4723-ac9c-29f983f2b8ea', now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC') ON CONFLICT DO NOTHING;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions internal/db/db_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/lolopinto/ent/internal/codegen"
"github.com/lolopinto/ent/internal/codegen/codegenapi"
"github.com/lolopinto/ent/internal/edge"
"github.com/lolopinto/ent/internal/enttype"
"github.com/lolopinto/ent/internal/file"
"github.com/lolopinto/ent/internal/schema/base"
"github.com/lolopinto/ent/internal/schema/input"
Expand Down Expand Up @@ -213,6 +214,7 @@ type indexConstraint struct {
tableName string
unique bool
name string
indexType input.IndexType
}

func (constraint *indexConstraint) getInfo() (string, []string) {
Expand Down Expand Up @@ -242,6 +244,9 @@ func (constraint *indexConstraint) getConstraintString() string {
if constraint.unique {
args = append(args, "unique=True")
}
if constraint.indexType != "" {
args = append(args, fmt.Sprintf("postgresql_using=%s", strconv.Quote(string(constraint.indexType))))
}

return fmt.Sprintf(
"sa.Index(%s)", strings.Join(args, ", "),
Expand Down Expand Up @@ -474,6 +479,7 @@ func (s *dbSchema) processConstraints(nodeData *schema.NodeData, columns []*dbCo
tableName: nodeData.GetTableName(),
unique: index.Unique,
name: index.Name,
indexType: index.IndexType,
}
if index.FullText != nil {
fullText := &fullTextConstraint{
Expand Down Expand Up @@ -1087,6 +1093,10 @@ func (s *dbSchema) addIndexConstraint(f *field.Field, tableName string, col *dbC
dbColumns: []*dbColumn{col},
tableName: tableName,
}
// default index type for lists when not specified is gin type
if enttype.IsListType(f.GetFieldType()) {
constraint.indexType = input.Gin
}
*constraints = append(*constraints, constraint)
}

Expand Down
Loading

0 comments on commit d6395f2

Please sign in to comment.