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

chore: Make flow.name column required #3284

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion e2e/tests/api-driven/src/permissions/queries/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { gql } from "graphql-tag";
export const INSERT_FLOW_QUERY = gql`
mutation InsertFlowE2E($team1Id: Int) {
result: insert_flows(
objects: { slug: "e2e-test-flow", team_id: $team1Id }
objects: {
slug: "e2e-test-flow"
team_id: $team1Id
name: "E2E Test Flow"
}
) {
returning {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."flows" alter column "name" drop not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."flows" alter column "name" set not null;
6 changes: 3 additions & 3 deletions hasura.planx.uk/tests/portals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe("portals", () => {
let res = await gqlAdmin(`
mutation {
insert_flows(objects: [
{slug: "TEST_root"},
{slug: "TEST_portal"},
{slug: "TEST_subportal"}
{slug: "TEST_root", name: "Test root"},
{slug: "TEST_portal", name: "Test portal"},
{slug: "TEST_subportal", name: "Test subportal"}
]) {
returning {
id
Expand Down
5 changes: 4 additions & 1 deletion hasura.planx.uk/tests/sessions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ describe("sessions", () => {
`mutation InsertFlow(
$data: jsonb!,
$slug: String!,
$name: String!,
$teamId: Int!,
) {
insert_flows_one(
object: {
data: $data
slug: $slug
team_id: $teamId,
name: $name
team_id: $teamId
version: 1
}
) {
Expand All @@ -97,6 +99,7 @@ describe("sessions", () => {
data: { x: 1 },
slug: "flow1",
teamId: teamId,
name: "flow 1",
}
);
flowId = res2.data.insert_flows_one.id;
Expand Down
6 changes: 3 additions & 3 deletions sharedb.planx.uk/sharedb-postgresql.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ PostgresDB.prototype.commit = function (

client.query("BEGIN", (err) => {
client.query(
"INSERT INTO flows (id, slug) VALUES ($1, $2) ON CONFLICT DO NOTHING",
[id, id],
"INSERT INTO flows (id, slug, name) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING",
[id, id, id],
Comment on lines +84 to +85
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an interesting one - without this I could create a flow, but not update it via ShareDB without an error.

I actually think this like of SQL will never get truly executed (it will always hit the ON CONFLICT clause). This is because the flow is created via Hasura prior to any ShareDB interaction takes place. Postgres must just be "clever enough" to know that this query is incorrect without a name value, despite it never actually being executed. This is why id, id, id is ok as these values are never actually read.

(err, _res) => {
if (err) {
rollback(client, done);
Expand Down Expand Up @@ -156,7 +156,7 @@ PostgresDB.prototype.commit = function (
};

// Get the named document from the database. The callback is called with (err,
// snapshot). A snapshot with a version of zero is returned if the docuemnt
// snapshot). A snapshot with a version of zero is returned if the document
// has never been created in the database.
PostgresDB.prototype.getSnapshot = function (
_collection,
Expand Down
Loading