From c739720cad238a8f14f60c8923f23acf6a3f1e17 Mon Sep 17 00:00:00 2001 From: Raymond Cheng Date: Mon, 20 May 2024 21:48:57 -0700 Subject: [PATCH] fix: Hasura deploy fix (#1464) - GitHub action should specify DBT_TARGET - Add DBT_TARGET to .env and load .env - Generate new tables - genTables should throw errors, not swallow - Build should generate metadata to checkin --- .github/workflows/deploy-hasura.yml | 1 + apps/hasura/.env.example | 1 + .../tables/artifacts_by_project_v1.yaml | 22 +++++++++++ .../cloudsql/tables/artifacts_v1.yaml | 22 +++++++++++ .../tables/code_metrics_by_project_v1.yaml | 22 +++++++++++ .../cloudsql/tables/collections_v1.yaml | 22 +++++++++++ .../event_indexing_status_by_project_v1.yaml | 22 +++++++++++ .../cloudsql/tables/event_types_v1.yaml | 22 +++++++++++ .../tables/onchain_metrics_by_project_v1.yaml | 22 +++++++++++ .../tables/projects_by_collection_v1.yaml | 22 +++++++++++ .../cloudsql/tables/projects_v1.yaml | 22 +++++++++++ .../databases/cloudsql/tables/tables.yaml | 37 +++++-------------- .../databases/cloudsql/tables/users_v1.yaml | 22 +++++++++++ apps/hasura/package.json | 5 ++- apps/hasura/src/genTables.ts | 3 +- 15 files changed, 237 insertions(+), 30 deletions(-) create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/artifacts_by_project_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/artifacts_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/code_metrics_by_project_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/collections_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/event_indexing_status_by_project_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/event_types_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/onchain_metrics_by_project_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/projects_by_collection_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/projects_v1.yaml create mode 100644 apps/hasura/metadata/databases/cloudsql/tables/users_v1.yaml diff --git a/.github/workflows/deploy-hasura.yml b/.github/workflows/deploy-hasura.yml index 37680bcbd..5615db552 100644 --- a/.github/workflows/deploy-hasura.yml +++ b/.github/workflows/deploy-hasura.yml @@ -4,6 +4,7 @@ env: HASURA_GRAPHQL_ADMIN_SECRET: ${{ secrets.HASURA_GRAPHQL_ADMIN_SECRET }} HASURA_GRAPHQL_ENDPOINT: ${{ vars.HASURA_GRAPHQL_ENDPOINT }} HASURA_GRAPHQL_DATABASE_URL: ${{ secrets.HASURA_GRAPHQL_DATABASE_URL }} + DBT_TARGET: "production" GOOGLE_CREDENTIALS_JSON: ${{ vars.GOOGLE_TEST_DUMMY_CREDENTIALS_JSON }} GOOGLE_PROJECT_ID: opensource-observer diff --git a/apps/hasura/.env.example b/apps/hasura/.env.example index 9c32b9d2a..a31b0e796 100644 --- a/apps/hasura/.env.example +++ b/apps/hasura/.env.example @@ -1,3 +1,4 @@ HASURA_GRAPHQL_ADMIN_SECRET= HASURA_GRAPHQL_ENDPOINT=https://opensource-observer.hasura.app/ HASURA_GRAPHQL_DATABASE_URL=postgresql://user:password@host:port +DBT_TARGET=production \ No newline at end of file diff --git a/apps/hasura/metadata/databases/cloudsql/tables/artifacts_by_project_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/artifacts_by_project_v1.yaml new file mode 100644 index 000000000..7aed32fe0 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/artifacts_by_project_v1.yaml @@ -0,0 +1,22 @@ +table: + name: artifacts_by_project_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/artifacts_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/artifacts_v1.yaml new file mode 100644 index 000000000..683896b91 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/artifacts_v1.yaml @@ -0,0 +1,22 @@ +table: + name: artifacts_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/code_metrics_by_project_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/code_metrics_by_project_v1.yaml new file mode 100644 index 000000000..c1be19258 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/code_metrics_by_project_v1.yaml @@ -0,0 +1,22 @@ +table: + name: code_metrics_by_project_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/collections_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/collections_v1.yaml new file mode 100644 index 000000000..9ab490f85 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/collections_v1.yaml @@ -0,0 +1,22 @@ +table: + name: collections_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/event_indexing_status_by_project_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/event_indexing_status_by_project_v1.yaml new file mode 100644 index 000000000..bed4f739c --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/event_indexing_status_by_project_v1.yaml @@ -0,0 +1,22 @@ +table: + name: event_indexing_status_by_project_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/event_types_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/event_types_v1.yaml new file mode 100644 index 000000000..458b36e5c --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/event_types_v1.yaml @@ -0,0 +1,22 @@ +table: + name: event_types_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/onchain_metrics_by_project_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/onchain_metrics_by_project_v1.yaml new file mode 100644 index 000000000..99a2703e8 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/onchain_metrics_by_project_v1.yaml @@ -0,0 +1,22 @@ +table: + name: onchain_metrics_by_project_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/projects_by_collection_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/projects_by_collection_v1.yaml new file mode 100644 index 000000000..07ea39375 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/projects_by_collection_v1.yaml @@ -0,0 +1,22 @@ +table: + name: projects_by_collection_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/projects_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/projects_v1.yaml new file mode 100644 index 000000000..b06a17ac7 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/projects_v1.yaml @@ -0,0 +1,22 @@ +table: + name: projects_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml b/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml index a8e4af6cd..8d3c4689d 100644 --- a/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml +++ b/apps/hasura/metadata/databases/cloudsql/tables/tables.yaml @@ -1,36 +1,19 @@ -- "!include artifacts.yaml" -- "!include artifacts_by_project.yaml" -- "!include code_metrics_by_collection.yaml" -- "!include code_metrics_by_project.yaml" -- "!include collections.yaml" -- "!include deployers_by_project.yaml" -- "!include event_totals_by_project.yaml" -- "!include event_types.yaml" -- "!include events_daily_from_artifact.yaml" -- "!include events_daily_from_collection.yaml" -- "!include events_daily_from_project.yaml" +- "!include artifacts_by_project_v1.yaml" +- "!include artifacts_v1.yaml" +- "!include code_metrics_by_project_v1.yaml" +- "!include collections_v1.yaml" +- "!include event_indexing_status_by_project_v1.yaml" +- "!include event_types_v1.yaml" - "!include events_daily_to_artifact.yaml" - "!include events_daily_to_collection.yaml" - "!include events_daily_to_project.yaml" -- "!include events_monthly_from_artifact.yaml" -- "!include events_monthly_from_collection.yaml" -- "!include events_monthly_from_project.yaml" - "!include events_monthly_to_artifact.yaml" - "!include events_monthly_to_collection.yaml" - "!include events_monthly_to_project.yaml" -- "!include events_weekly_from_artifact.yaml" -- "!include events_weekly_from_collection.yaml" -- "!include events_weekly_from_project.yaml" - "!include events_weekly_to_artifact.yaml" - "!include events_weekly_to_collection.yaml" - "!include events_weekly_to_project.yaml" -- "!include first_contribution_to_project.yaml" -- "!include last_contribution_to_project.yaml" -- "!include onchain_metrics_by_collection.yaml" -- "!include onchain_metrics_by_project.yaml" -- "!include pm_dev_months.yaml" -- "!include pm_new_contribs.yaml" -- "!include projects.yaml" -- "!include projects_by_collection.yaml" -- "!include repos_by_project.yaml" -- "!include users_monthly_to_project.yaml" +- "!include onchain_metrics_by_project_v1.yaml" +- "!include projects_by_collection_v1.yaml" +- "!include projects_v1.yaml" +- "!include users_v1.yaml" diff --git a/apps/hasura/metadata/databases/cloudsql/tables/users_v1.yaml b/apps/hasura/metadata/databases/cloudsql/tables/users_v1.yaml new file mode 100644 index 000000000..4f1694b78 --- /dev/null +++ b/apps/hasura/metadata/databases/cloudsql/tables/users_v1.yaml @@ -0,0 +1,22 @@ +table: + name: users_v1 + schema: public +select_permissions: + - role: anonymous + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: user + permission: + columns: "*" + filter: {} + allow_aggregations: false + comment: "" + - role: developer + permission: + columns: "*" + filter: {} + allow_aggregations: true + comment: "" diff --git a/apps/hasura/package.json b/apps/hasura/package.json index b2e85719f..fc3e29511 100644 --- a/apps/hasura/package.json +++ b/apps/hasura/package.json @@ -17,11 +17,12 @@ "node": ">=20" }, "scripts": { - "build": "tsc", + "build:ts": "tsc", + "build": "pnpm build:ts && pnpm metadata:genTables", "lint": "tsc --noEmit && pnpm lint:eslint && pnpm lint:prettier", "lint:eslint": "eslint --ignore-path ../../.gitignore --max-warnings 0 .", "lint:prettier": "prettier --ignore-path ../../.gitignore --log-level warn --check **/*.{js,jsx,ts,tsx,sol,md,json}", - "metadata:genTables": "node --loader ts-node/esm src/genTables.ts", + "metadata:genTables": "dotenv -- node --loader ts-node/esm src/genTables.ts", "metadata:pull": "hasura metadata export", "metadata:reload": "hasura metadata reload", "metadata:apply": "hasura metadata apply", diff --git a/apps/hasura/src/genTables.ts b/apps/hasura/src/genTables.ts index 44af6dcc0..1b14fca44 100644 --- a/apps/hasura/src/genTables.ts +++ b/apps/hasura/src/genTables.ts @@ -163,5 +163,6 @@ async function main(): Promise { main() .then(() => console.log("Done")) .catch((e) => { - console.warn(e); + //console.warn(e); + throw e; });