Skip to content

chore(db): add database migration service to docker-compose#301

Merged
l1ttps merged 5 commits intomainfrom
migration-database
Mar 14, 2026
Merged

chore(db): add database migration service to docker-compose#301
l1ttps merged 5 commits intomainfrom
migration-database

Conversation

@l1ttps
Copy link
Copy Markdown
Member

@l1ttps l1ttps commented Mar 14, 2026

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the database management strategy by integrating TypeORM for schema migrations. This change ensures that database schema updates are version-controlled, repeatable, and automatically applied when the application starts within a Dockerized environment, improving consistency and reducing manual intervention for database setup and evolution.

Highlights

  • Database Migrations: Introduced TypeORM for managing database schema migrations, providing a structured approach to evolving the database.
  • Docker Integration: Integrated a dedicated migration service into docker-compose.yml to automatically apply database schema changes upon service startup.
  • Configuration Updates: Refactored database connection configurations to align with TypeORM's DataSourceOptions and removed synchronize: true from the TypeORM module.
  • Task Automation: Added new Taskfile commands for generating, running, and reverting TypeORM migrations, streamlining development workflows.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • core-api/package.json
    • Added a typeorm script to facilitate running TypeORM CLI commands.
  • core-api/src/database/database-config.ts
    • Refactored database connection configuration to align with TypeORM's DataSourceOptions.
    • Replaced the pg Pool with a TypeORM AppDataSource instance.
    • Configured entities, migrations paths, and conditional migrationsRun for development.
  • core-api/src/database/database.module.ts
    • Updated the TypeOrmModule.forRoot configuration to use the newly defined dataSourceOptions.
    • Removed synchronize: true in favor of explicit migrations.
  • core-api/src/database/migrations/1773452480784-Initialization.ts
    • Added an initial TypeORM migration file that defines the complete database schema, including all tables, enums, indexes, and foreign key constraints.
  • core-api/taskfile.yml
    • Introduced new Taskfile commands (migration:generate, migration:run, migration:revert) to simplify TypeORM migration operations.
  • docker-compose.yml
    • Added a new migration service responsible for executing database migrations before the main api service starts.
    • Configured the api service to depend on the successful completion of the migration service.
    • Applied minor formatting adjustments to string literals.
  • taskfile.yml
    • Added top-level Taskfile commands (migration:generate, migration:run, migration:revert) that delegate to the core-api specific migration tasks.
Activity
  • No specific activity or comments were provided in the context for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a database migration system using TypeORM, which is a significant improvement for managing database schema changes. A dedicated migration service has been added to docker-compose.yml to ensure migrations are applied before the application starts. The database configuration has been refactored to support this new setup. My review has identified a critical issue in the initial migration file that will prevent it from running successfully. Please see the specific comment for details.

await queryRunner.query(`CREATE INDEX "IDX_27118f1a1f2a0b32462665b591" ON "http_responses" ("assetServiceId") `);
await queryRunner.query(`CREATE TABLE "ports" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "ports" integer array NOT NULL, "assetId" character varying, "jobHistoryId" uuid, CONSTRAINT "PK_291c9f372b1ce97c885e96f5ff4" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "vulnerability_dismissals" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "vulnerabilityId" uuid NOT NULL, "userId" uuid NOT NULL, "reason" character varying NOT NULL, "comment" character varying, CONSTRAINT "UQ_ba00c6117325d322aa2b3683b23" UNIQUE ("vulnerabilityId"), CONSTRAINT "REL_ba00c6117325d322aa2b3683b2" UNIQUE ("vulnerabilityId"), CONSTRAINT "PK_40a07ee5c602766acec8bb4a3af" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "vulnerabilities" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "name" character varying NOT NULL, "description" character varying, "synopsis" character varying, "severity" character varying NOT NULL DEFAULT 'info', "tags" text array, "references" text array, "authors" text array, "affectedUrl" character varying, "ipAddress" character varying, "host" character varying, "ports" text array, "cvssMetric" character varying, "cvssScore" double precision, "epssScore" double precision, "vprScore" double precision, "cveId" text array, "bidId" text array, "cweId" text array, "ceaId" text array, "iava" text array, "cveUrl" text, "cweUrl" text, "solution" text, "extractorName" character varying, "extractedResults" text array, "publicationDate" TIMESTAMP WITH TIME ZONE, "modificationDate" TIMESTAMP WITH TIME ZONE, "filePath" character varying, "jobHistoryId" uuid, "isArchived" boolean NOT NULL DEFAULT false, "fingerprint" character varying, "toolId" uuid, "assetId" uuid, CONSTRAINT "UQ_f5a93b9c006858e4b051713eac2" UNIQUE ("fingerprint"), CONSTRAINT "UQ_f5a93b9c006858e4b051713eac2" UNIQUE ("fingerprint"), CONSTRAINT "PK_ee96a1a8d70c431bc2d86485502" PRIMARY KEY ("id"))`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The CREATE TABLE "vulnerabilities" statement contains a duplicate unique constraint on the fingerprint column. This will cause a SQL error and fail the migration. Please remove the duplicate constraint.

Suggested change
await queryRunner.query(`CREATE TABLE "vulnerabilities" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "name" character varying NOT NULL, "description" character varying, "synopsis" character varying, "severity" character varying NOT NULL DEFAULT 'info', "tags" text array, "references" text array, "authors" text array, "affectedUrl" character varying, "ipAddress" character varying, "host" character varying, "ports" text array, "cvssMetric" character varying, "cvssScore" double precision, "epssScore" double precision, "vprScore" double precision, "cveId" text array, "bidId" text array, "cweId" text array, "ceaId" text array, "iava" text array, "cveUrl" text, "cweUrl" text, "solution" text, "extractorName" character varying, "extractedResults" text array, "publicationDate" TIMESTAMP WITH TIME ZONE, "modificationDate" TIMESTAMP WITH TIME ZONE, "filePath" character varying, "jobHistoryId" uuid, "isArchived" boolean NOT NULL DEFAULT false, "fingerprint" character varying, "toolId" uuid, "assetId" uuid, CONSTRAINT "UQ_f5a93b9c006858e4b051713eac2" UNIQUE ("fingerprint"), CONSTRAINT "UQ_f5a93b9c006858e4b051713eac2" UNIQUE ("fingerprint"), CONSTRAINT "PK_ee96a1a8d70c431bc2d86485502" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "vulnerabilities" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "name" character varying NOT NULL, "description" character varying, "synopsis" character varying, "severity" character varying NOT NULL DEFAULT 'info', "tags" text array, "references" text array, "authors" text array, "affectedUrl" character varying, "ipAddress" character varying, "host" character varying, "ports" text array, "cvssMetric" character varying, "cvssScore" double precision, "epssScore" double precision, "vprScore" double precision, "cveId" text array, "bidId" text array, "cweId" text array, "ceaId" text array, "iava" text array, "cveUrl" text, "cweUrl" text, "solution" text, "extractorName" character varying, "extractedResults" text array, "publicationDate" TIMESTAMP WITH TIME ZONE, "modificationDate" TIMESTAMP WITH TIME ZONE, "filePath" character varying, "jobHistoryId" uuid, "isArchived" boolean NOT NULL DEFAULT false, "fingerprint" character varying, "toolId" uuid, "assetId" uuid, CONSTRAINT "UQ_f5a93b9c006858e4b051713eac2" UNIQUE ("fingerprint"), CONSTRAINT "PK_ee96a1a8d70c431bc2d86485502" PRIMARY KEY ("id"))`);

@l1ttps l1ttps merged commit 15881aa into main Mar 14, 2026
15 checks passed
@l1ttps l1ttps deleted the migration-database branch March 22, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant