Skip to content

Commit

Permalink
feat: record changed subgraphs in composition (wundergraph#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnithin authored Sep 5, 2024
1 parent 65d39f4 commit f39ca8c
Show file tree
Hide file tree
Showing 15 changed files with 5,114 additions and 122 deletions.
18 changes: 18 additions & 0 deletions connect/src/wg/cosmo/platform/v1/platform_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12192,6 +12192,16 @@ export class GraphComposition extends Message<GraphComposition> {
*/
deploymentError?: string;

/**
* @generated from field: optional bool hasMultipleChangedSubgraphs = 11;
*/
hasMultipleChangedSubgraphs?: boolean;

/**
* @generated from field: optional string triggeredBySubgraphName = 12;
*/
triggeredBySubgraphName?: string;

constructor(data?: PartialMessage<GraphComposition>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -12210,6 +12220,8 @@ export class GraphComposition extends Message<GraphComposition> {
{ no: 8, name: "routerConfigSignature", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
{ no: 9, name: "admissionError", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
{ no: 10, name: "deploymentError", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
{ no: 11, name: "hasMultipleChangedSubgraphs", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true },
{ no: 12, name: "triggeredBySubgraphName", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GraphComposition {
Expand Down Expand Up @@ -12258,6 +12270,11 @@ export class GraphCompositionSubgraph extends Message<GraphCompositionSubgraph>
*/
isFeatureSubgraph = false;

/**
* @generated from field: string changeType = 6;
*/
changeType = "";

constructor(data?: PartialMessage<GraphCompositionSubgraph>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -12271,6 +12288,7 @@ export class GraphCompositionSubgraph extends Message<GraphCompositionSubgraph>
{ no: 3, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 4, name: "target_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 5, name: "isFeatureSubgraph", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 6, name: "changeType", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GraphCompositionSubgraph {
Expand Down
56 changes: 56 additions & 0 deletions controlplane/migrations/0096_red_bug.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- Custom SQL migration file --

DO $$ BEGIN
CREATE TYPE "public"."graph_composition_subgraph_change_type" AS ENUM('added', 'removed', 'updated', 'unchanged');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "schema_versions" DROP CONSTRAINT "schema_versions_target_id_targets_id_fk";
--> statement-breakpoint
ALTER TABLE "graph_composition_subgraphs" ADD COLUMN "subgraph_id" uuid;--> statement-breakpoint
ALTER TABLE "graph_composition_subgraphs" ADD COLUMN "subgraph_target_id" uuid;--> statement-breakpoint
ALTER TABLE "graph_composition_subgraphs" ADD COLUMN "subgraph_name" text;--> statement-breakpoint
ALTER TABLE "graph_composition_subgraphs" ADD COLUMN "change_type" "graph_composition_subgraph_change_type" DEFAULT 'unchanged';--> statement-breakpoint
ALTER TABLE "graph_composition_subgraphs" ADD COLUMN "is_feature_subgraph" boolean DEFAULT false;--> statement-breakpoint
ALTER TABLE "schema_versions" ADD COLUMN "organization_id" uuid;--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "schema_versions" ADD CONSTRAINT "schema_versions_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "webhook_deliveries" DROP COLUMN IF EXISTS "is_redelivery";

-- Populate new columns with existing data
BEGIN TRANSACTION;
UPDATE "graph_composition_subgraphs" gcs
SET
"subgraph_id" = s.id,
"subgraph_target_id" = t.id,
"subgraph_name" = t.name,
"is_feature_subgraph" = s.is_feature_subgraph
FROM "schema_versions" sv
JOIN "targets" t ON sv.target_id = t.id
JOIN "subgraphs" s ON t.id = s.target_id
WHERE gcs.schema_version_id = sv.id;

UPDATE "graph_composition_subgraphs"
SET "change_type" = 'unchanged'
WHERE "change_type" IS NULL;

UPDATE "schema_versions"
SET "organization_id" = (SELECT "organization_id" FROM "targets" WHERE "id" = "schema_versions"."target_id")
WHERE "organization_id" IS NULL;
COMMIT;

-- Make new columns not null
ALTER TABLE "graph_composition_subgraphs"
ALTER COLUMN "subgraph_id" SET NOT NULL,
ALTER COLUMN "subgraph_target_id" SET NOT NULL,
ALTER COLUMN "subgraph_name" SET NOT NULL,
ALTER COLUMN "change_type" SET NOT NULL,
ALTER COLUMN "is_feature_subgraph" SET NOT NULL;

ALTER TABLE "schema_versions"
ALTER COLUMN "organization_id" SET NOT NULL;
Loading

0 comments on commit f39ca8c

Please sign in to comment.