From 1d0d6088f83b46ce86c0b60aa40e1c8e16751dd1 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:38:24 +0400 Subject: [PATCH 01/12] chore: validate db schemas CI test --- .github/workflows/validate-db-schemas.yml | 71 +++++++++++++++++++++++ .infisicalignore | 2 + 2 files changed, 73 insertions(+) create mode 100644 .github/workflows/validate-db-schemas.yml diff --git a/.github/workflows/validate-db-schemas.yml b/.github/workflows/validate-db-schemas.yml new file mode 100644 index 000000000..14dfa9b6a --- /dev/null +++ b/.github/workflows/validate-db-schemas.yml @@ -0,0 +1,71 @@ +name: "Validate DB schemas" + +on: + pull_request: + types: [opened, synchronize] + paths: + - "backend/src/db/**" + + workflow_call: + +jobs: + check-be-pr: + name: Validate DB schemas + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: ☁️ Checkout source + uses: actions/checkout@v3 + - uses: KengoTODA/actions-setup-docker-compose@v1 + if: ${{ env.ACT }} + name: Install `docker compose` for local simulations + with: + version: "2.14.2" + - name: 🔧 Setup Node 20 + uses: actions/setup-node@v3 + with: + node-version: "20" + cache: "npm" + cache-dependency-path: backend/package-lock.json + + - name: Install dependencies + run: npm install + working-directory: backend + + - name: Start PostgreSQL and Redis + run: touch .env && docker compose -f docker-compose.dev.yml up -d db redis + + - name: Apply migrations + run: npm run migration:latest-dev + working-directory: backend + env: + NODE_OPTIONS: "--max-old-space-size=8192" + REDIS_URL: redis://172.17.0.1:6379 + DB_CONNECTION_URI: postgres://infisical:infisical@172.17.0.1:5432/infisical?sslmode=disable + AUTH_SECRET: something-random + ENCRYPTION_KEY: 4bnfe4e407b8921c104518903515b218 + + - name: Run schema generation + run: npm run generate:schema + working-directory: backend + env: + NODE_OPTIONS: "--max-old-space-size=8192" + REDIS_URL: redis://172.17.0.1:6379 + DB_CONNECTION_URI: postgres://infisical:infisical@172.17.0.1:5432/infisical?sslmode=disable + AUTH_SECRET: something-random + ENCRYPTION_KEY: 4bnfe4e407b8921c104518903515b218 + + - name: Check for schema changes + run: | + if ! git diff --exit-code --quiet src/db/schemas; then + echo "❌ Generated schemas differ from committed schemas!" + echo "Run 'npm run generate:schema' locally and commit the changes." + git diff src/db/schemas + exit 1 + fi + echo "✅ Schemas are up to date" + working-directory: backend + + - name: Cleanup + run: | + docker compose -f "docker-compose.dev.yml" down diff --git a/.infisicalignore b/.infisicalignore index d705c0d66..0f430e377 100644 --- a/.infisicalignore +++ b/.infisicalignore @@ -46,3 +46,5 @@ cli/detect/config/gitleaks.toml:gcp-api-key:582 .github/workflows/helm-release-infisical-core.yml:generic-api-key:47 backend/src/services/smtp/smtp-service.ts:generic-api-key:79 frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflarePagesSyncFields.tsx:cloudflare-api-key:7 +.github/workflows/validate-db-schemas.yml:generic-api-key:56 +.github/workflows/validate-db-schemas.yml:generic-api-key:46 From 01054bbae0269491548b5f70b424a24b39bd3aee Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:40:52 +0400 Subject: [PATCH 02/12] Create 20250713154007_test-migration.ts --- .../migrations/20250713154007_test-migration.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 backend/src/db/migrations/20250713154007_test-migration.ts diff --git a/backend/src/db/migrations/20250713154007_test-migration.ts b/backend/src/db/migrations/20250713154007_test-migration.ts new file mode 100644 index 000000000..d26f446fb --- /dev/null +++ b/backend/src/db/migrations/20250713154007_test-migration.ts @@ -0,0 +1,15 @@ +import { Knex } from "knex"; + +import { TableName } from "../schemas"; + +export async function up(knex: Knex): Promise { + await knex.schema.alterTable(TableName.SuperAdmin, (table) => { + table.string("test_column").notNullable().defaultTo("test_value"); + }); +} + +export async function down(knex: Knex): Promise { + await knex.schema.alterTable(TableName.SuperAdmin, (table) => { + table.dropColumn("test_column"); + }); +} From fed264c07b24d3b61d385ec79a057eb421fb503c Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:49:22 +0400 Subject: [PATCH 03/12] Delete 20250713154007_test-migration.ts --- .../migrations/20250713154007_test-migration.ts | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 backend/src/db/migrations/20250713154007_test-migration.ts diff --git a/backend/src/db/migrations/20250713154007_test-migration.ts b/backend/src/db/migrations/20250713154007_test-migration.ts deleted file mode 100644 index d26f446fb..000000000 --- a/backend/src/db/migrations/20250713154007_test-migration.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Knex } from "knex"; - -import { TableName } from "../schemas"; - -export async function up(knex: Knex): Promise { - await knex.schema.alterTable(TableName.SuperAdmin, (table) => { - table.string("test_column").notNullable().defaultTo("test_value"); - }); -} - -export async function down(knex: Knex): Promise { - await knex.schema.alterTable(TableName.SuperAdmin, (table) => { - table.dropColumn("test_column"); - }); -} From 7e032221043aa4fe3dd52dcb5fe440861970e236 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:50:58 +0400 Subject: [PATCH 04/12] Update validate-db-schemas.yml --- .github/workflows/validate-db-schemas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-db-schemas.yml b/.github/workflows/validate-db-schemas.yml index 14dfa9b6a..060e151e7 100644 --- a/.github/workflows/validate-db-schemas.yml +++ b/.github/workflows/validate-db-schemas.yml @@ -4,7 +4,7 @@ on: pull_request: types: [opened, synchronize] paths: - - "backend/src/db/**" + - "backend/**" workflow_call: From ef2f4e095cabbf30b6b3fd54dd0af948aaeff8b7 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:51:12 +0400 Subject: [PATCH 05/12] Update access-approval-policies-bypassers.ts --- backend/src/db/schemas/access-approval-policies-bypassers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/db/schemas/access-approval-policies-bypassers.ts b/backend/src/db/schemas/access-approval-policies-bypassers.ts index 278e4b416..8690638eb 100644 --- a/backend/src/db/schemas/access-approval-policies-bypassers.ts +++ b/backend/src/db/schemas/access-approval-policies-bypassers.ts @@ -1,7 +1,7 @@ // Code generated by automation script, DO NOT EDIT. // Automated by pulling database and generating zod schema // To update. Just run npm run generate:schema -// Written by akhilmhdh. +// Written by akhilmhdh. test import { z } from "zod"; From 899ed14ecd0cb0c82877cf4182942e4a72be0109 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:51:21 +0400 Subject: [PATCH 06/12] Update access-approval-policies-bypassers.ts --- backend/src/db/schemas/access-approval-policies-bypassers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/db/schemas/access-approval-policies-bypassers.ts b/backend/src/db/schemas/access-approval-policies-bypassers.ts index 8690638eb..278e4b416 100644 --- a/backend/src/db/schemas/access-approval-policies-bypassers.ts +++ b/backend/src/db/schemas/access-approval-policies-bypassers.ts @@ -1,7 +1,7 @@ // Code generated by automation script, DO NOT EDIT. // Automated by pulling database and generating zod schema // To update. Just run npm run generate:schema -// Written by akhilmhdh. test +// Written by akhilmhdh. import { z } from "zod"; From a21ebf000f8662b91d06066b7939e23067781bea Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:52:08 +0400 Subject: [PATCH 07/12] Update package.json --- backend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 128de7bd6..f669bb1fd 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,7 +1,7 @@ { "name": "backend", "version": "1.0.0", - "description": "", + "description": "test", "main": "./dist/main.mjs", "bin": "dist/main.js", "pkg": { From de6ebca351356f181934dfc79d51ca101fee1af4 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Sun, 13 Jul 2025 19:52:27 +0400 Subject: [PATCH 08/12] Update .github/workflows/validate-db-schemas.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .github/workflows/validate-db-schemas.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/validate-db-schemas.yml b/.github/workflows/validate-db-schemas.yml index 060e151e7..185ec1a3d 100644 --- a/.github/workflows/validate-db-schemas.yml +++ b/.github/workflows/validate-db-schemas.yml @@ -67,5 +67,6 @@ jobs: working-directory: backend - name: Cleanup + if: always() run: | docker compose -f "docker-compose.dev.yml" down From 520fb6801d078b046531e0530629222dc31bb747 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 19:57:25 +0400 Subject: [PATCH 09/12] Update package.json --- backend/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index f669bb1fd..128de7bd6 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,7 +1,7 @@ { "name": "backend", "version": "1.0.0", - "description": "test", + "description": "", "main": "./dist/main.mjs", "bin": "dist/main.js", "pkg": { From ed247a794a7bda511e9cadc6364e5e98a7c96a2e Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 23:36:59 +0400 Subject: [PATCH 10/12] requested changes --- .github/workflows/validate-db-schemas.yml | 29 ++++++++++------------- .infisicalignore | 3 +-- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.github/workflows/validate-db-schemas.yml b/.github/workflows/validate-db-schemas.yml index 185ec1a3d..1a3f7f23c 100644 --- a/.github/workflows/validate-db-schemas.yml +++ b/.github/workflows/validate-db-schemas.yml @@ -9,13 +9,21 @@ on: workflow_call: jobs: - check-be-pr: + validate-db-schemas: name: Validate DB schemas runs-on: ubuntu-latest timeout-minutes: 15 + env: + NODE_OPTIONS: "--max-old-space-size=8192" + REDIS_URL: redis://172.17.0.1:6379 + DB_CONNECTION_URI: postgres://infisical:infisical@172.17.0.1:5432/infisical?sslmode=disable + AUTH_SECRET: something-random + ENCRYPTION_KEY: 4bnfe4e407b8921c104518903515b218 steps: - name: ☁️ Checkout source - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: KengoTODA/actions-setup-docker-compose@v1 if: ${{ env.ACT }} name: Install `docker compose` for local simulations @@ -28,32 +36,19 @@ jobs: cache: "npm" cache-dependency-path: backend/package-lock.json + - name: Start PostgreSQL and Redis + run: touch .env && docker compose -f docker-compose.dev.yml up -d db redis - name: Install dependencies run: npm install working-directory: backend - - name: Start PostgreSQL and Redis - run: touch .env && docker compose -f docker-compose.dev.yml up -d db redis - - name: Apply migrations run: npm run migration:latest-dev working-directory: backend - env: - NODE_OPTIONS: "--max-old-space-size=8192" - REDIS_URL: redis://172.17.0.1:6379 - DB_CONNECTION_URI: postgres://infisical:infisical@172.17.0.1:5432/infisical?sslmode=disable - AUTH_SECRET: something-random - ENCRYPTION_KEY: 4bnfe4e407b8921c104518903515b218 - name: Run schema generation run: npm run generate:schema working-directory: backend - env: - NODE_OPTIONS: "--max-old-space-size=8192" - REDIS_URL: redis://172.17.0.1:6379 - DB_CONNECTION_URI: postgres://infisical:infisical@172.17.0.1:5432/infisical?sslmode=disable - AUTH_SECRET: something-random - ENCRYPTION_KEY: 4bnfe4e407b8921c104518903515b218 - name: Check for schema changes run: | diff --git a/.infisicalignore b/.infisicalignore index 0f430e377..1f02492d6 100644 --- a/.infisicalignore +++ b/.infisicalignore @@ -46,5 +46,4 @@ cli/detect/config/gitleaks.toml:gcp-api-key:582 .github/workflows/helm-release-infisical-core.yml:generic-api-key:47 backend/src/services/smtp/smtp-service.ts:generic-api-key:79 frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/CloudflarePagesSyncFields.tsx:cloudflare-api-key:7 -.github/workflows/validate-db-schemas.yml:generic-api-key:56 -.github/workflows/validate-db-schemas.yml:generic-api-key:46 +.github/workflows/validate-db-schemas.yml:generic-api-key:21 From 89b91544676e8da33e977b840c312f6df9ee9e57 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 23:37:19 +0400 Subject: [PATCH 11/12] Update 20250711005900_github-app-connection-to-environments.ts --- .../20250711005900_github-app-connection-to-environments.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts b/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts index 14e9ddd65..b576dec7b 100644 --- a/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts +++ b/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts @@ -1,5 +1,5 @@ import { Knex } from "knex"; - +// test import { inMemoryKeyStore } from "@app/keystore/memory"; import { selectAllTableCols } from "@app/lib/knex"; From 69c64c76dd57b57fdc34c6cfdf9db2e703ddffc1 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Sun, 13 Jul 2025 23:41:57 +0400 Subject: [PATCH 12/12] Update 20250711005900_github-app-connection-to-environments.ts --- .../20250711005900_github-app-connection-to-environments.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts b/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts index b576dec7b..14e9ddd65 100644 --- a/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts +++ b/backend/src/db/migrations/20250711005900_github-app-connection-to-environments.ts @@ -1,5 +1,5 @@ import { Knex } from "knex"; -// test + import { inMemoryKeyStore } from "@app/keystore/memory"; import { selectAllTableCols } from "@app/lib/knex";