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

feat: Add team_integrations table #2499

Merged
merged 3 commits into from
Dec 1, 2023
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
20 changes: 20 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,18 @@
- locked_at:
_is_null: true
check: null
- table:
schema: public
name: team_integrations
select_permissions:
- role: api
permission:
columns:
- id
- team_id
- staging_bops_submission_url
- production_bops_submission_url
filter: {}
- table:
schema: public
name: team_members
Expand Down Expand Up @@ -1284,6 +1296,14 @@
- table:
schema: public
name: teams
object_relationships:
- name: integrations
using:
foreign_key_constraint_on:
column: team_id
table:
schema: public
name: team_integrations
array_relationships:
- name: flows
using:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."team_integrations";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE "public"."team_integrations" (
"id" serial NOT NULL,
"team_id" integer NOT NULL,
"staging_bops_submission_url" text,
"production_bops_submission_url" text,
PRIMARY KEY ("id"),
FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON UPDATE restrict ON DELETE cascade,
UNIQUE ("team_id")
);

COMMENT ON TABLE "public"."team_integrations" IS E'Tracks URLs and API keys for integrations';
76 changes: 76 additions & 0 deletions hasura.planx.uk/tests/team_integrations.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { introspectAs } = require("./utils");

describe("team_integrations", () => {
describe("public", () => {
let i;
beforeAll(async () => {
i = await introspectAs("public");
});

test("cannot query team_integrations", () => {
expect(i.queries).not.toContain("team_integrations");
});

test("cannot create, update, or delete team_integrations", () => {
expect(i).toHaveNoMutationsFor("team_integrations");
});
});

describe("admin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("admin");
});

test("has full access to query and mutate team_integrations", () => {
expect(i.queries).toContain("team_integrations");
expect(i.mutations).toContain("insert_team_integrations");
expect(i.mutations).toContain("update_team_integrations_by_pk");
expect(i.mutations).toContain("delete_team_integrations");
});
});

describe("platformAdmin", () => {
let i;
beforeAll(async () => {
i = await introspectAs("platformAdmin");
});

test("cannot query team_integrations", () => {
expect(i.queries).not.toContain("team_integrations");
});

test("cannot create, update, or delete team_integrations", () => {
expect(i).toHaveNoMutationsFor("team_integrations");
});
});

describe("teamEditor", () => {
beforeAll(async () => {
i = await introspectAs("teamEditor");
});

test("cannot query team_integrations", () => {
expect(i.queries).not.toContain("team_integrations");
});

test("cannot create, update, or delete team_integrations", () => {
expect(i).toHaveNoMutationsFor("team_integrations");
});
});

describe("api", () => {
let i;
beforeAll(async () => {
i = await introspectAs("api");
});

test("can query team_integrations", () => {
expect(i.queries).toContain("team_integrations");
});

test("cannot create, update, or delete team_integrations", () => {
expect(i).toHaveNoMutationsFor("team_integrations");
});
});
});
5 changes: 5 additions & 0 deletions scripts/seed-database/container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ for table in "${tables[@]}"; do
fi
done

# Copy subset of team_integrations columns
# Do not copy production values
psql --quiet ${REMOTE_PG} --command="\\copy (SELECT id, team_id, staging_bops_submission_url FROM team_integrations TO '/tmp/team_integrations.csv' (FORMAT csv, DELIMITER ';');"
echo team_integrations downloaded

psql --quiet ${REMOTE_PG} --command="\\copy (SELECT DISTINCT ON (flow_id) id, data, flow_id, summary, publisher_id, created_at FROM published_flows ORDER BY flow_id, created_at DESC) TO '/tmp/published_flows.csv' (FORMAT csv, DELIMITER ';');"
echo published_flows downloaded

Expand Down
3 changes: 2 additions & 1 deletion scripts/seed-database/write/main.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
\include write/flows.sql
\include write/flow_document_templates.sql
\include write/published_flows.sql
\include write/team_members.sql
\include write/team_members.sql
\include write/team_integrations.sql
23 changes: 23 additions & 0 deletions scripts/seed-database/write/team_integrations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- insert team_integrations overwriting conflicts
CREATE TEMPORARY TABLE sync_team_integrations (
id serial,
team_id integer,
staging_bops_submission_url text
);

\ COPY sync_team_integrations
FROM
'/tmp/team_integrations.csv' WITH (FORMAT csv, DELIMITER ';');

INSERT INTO
team_integrations (id, team_id, staging_bops_submission_url)
SELECT
id,
team_id,
staging_bops_submission_url
FROM
sync_team_integrations ON CONFLICT (id) DO
UPDATE
SET
team_id = EXCLUDED.team_id,
staging_bops_submission_url = EXCLUDED.staging_bops_submission_url;
Loading