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 audit table for data migration scripts #4095

Merged
merged 2 commits into from
Dec 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
13 changes: 13 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,19 @@
- subdomain
filter: {}
comment: ""
- table:
name: temp_data_migrations_audit
schema: public
object_relationships:
- name: flows
using:
manual_configuration:
column_mapping:
flow_id: id
insertion_order: null
remote_table:
name: flows
schema: public
- table:
name: uniform_applications
schema: public
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."temp_data_migrations_audit";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE "public"."temp_data_migrations_audit" (
"flow_id" uuid NOT NULL,
"team_id" integer NOT NULL,
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

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

Would relationships here be helpful for queries in the migration scripts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so ! As I see it we'll simply return the flow_id from this table (it's the primary key so indexed) then pass into a GraphQL relational query which will fetch the flow and its' latest published version (so meaningful foreign key is at GraphQL & existing flows table level rather than on this one?). But please object if I'm missing a benefit of fkeys directly here!

Copy link
Member Author

@jessicamcinchak jessicamcinchak Dec 19, 2024

Choose a reason for hiding this comment

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

Oof slow brain today - answered my own question there - you're totally right, if we set a proper relationship to flows here then migration script will be able to make a single query rather than two 👍 update incoming!

Copy link
Member Author

Choose a reason for hiding this comment

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

query MyQuery {
  temp_data_migrations_audit(where: {updated: {_eq: false}}, limit: 1) {
    flow_id
    flows {
      data
      published_flows(order_by: {created_at: desc}, limit: 1) {
        data
      }
    }
  }
}

"updated" boolean NOT NULL DEFAULT false,
"updated_at" timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY ("flow_id")
);
COMMENT ON TABLE "public"."temp_data_migrations_audit" IS E'Basic table structure that we can use to track status of data migrations. Contents of this table are ephemeral and may be truncated between migrations';
Loading