Skip to content

Conversation

@imashkanov
Copy link

@imashkanov imashkanov commented Jul 8, 2025

Summary by CodeRabbit

  • New Features
    • Test Management: test plans, cases, folders, milestones, and case versioning with a single default.
    • Manual scenarios (text or steps) with estimates, preconditions, requirement links, and attachments.
    • Full‑text search for test cases and plans.
    • Linkages: plans ↔ cases ↔ steps ↔ executions; environments, datasets, product versions; and attributes/tags for plans/cases/scenarios.
    • Launches now indicate type (Automation or Manual).

@imashkanov imashkanov changed the title Feature/epmrpp migrate tms to develop TMS Migration (to develop) Jul 8, 2025
@imashkanov imashkanov force-pushed the feature/EPMRPP-migrate-tms-to-develop branch from 6f8b9c8 to e72cc3f Compare July 24, 2025 18:04
@imashkanov imashkanov force-pushed the feature/EPMRPP-migrate-tms-to-develop branch from de2a21c to 8576ded Compare July 31, 2025 19:19
@imashkanov imashkanov force-pushed the feature/EPMRPP-migrate-tms-to-develop branch from d9f46fb to bae82c6 Compare August 7, 2025 21:24
@imashkanov imashkanov force-pushed the feature/EPMRPP-migrate-tms-to-develop branch from 202a17d to 600f7a4 Compare August 23, 2025 19:29
@imashkanov imashkanov force-pushed the feature/EPMRPP-migrate-tms-to-develop branch from 600f7a4 to 21fe65d Compare September 9, 2025 20:44
@coderabbitai
Copy link

coderabbitai bot commented Sep 9, 2025

Walkthrough

Adds a comprehensive Test Management System schema (types, tables, FKs, indexes, triggers, functions, attachments, versioning, and full‑text search) and provides a down migration that removes those objects and the added launch.launch_type using ordered, idempotent DROP operations.

Changes

Cohort / File(s) Summary
TMS schema initialization (UP)
migrations/103_tms_initial.up.sql
Introduces enums (tms_dataset_type, tms_manual_scenario_type, LAUNCH_TYPE_ENUM), many TMS tables (attributes, product versions, datasets/data, environments/env-dataset, milestones, test_folders, test_cases, test_case_versions, test_plans, manual_scenarios with text/steps, steps, attachments, join/attribute tables), FKs, composite PKs/unique constraints, GIN indexes, full‑text search functions/triggers, partial unique index for default test case version, adds/backfills launch.launch_type and launch.test_plan_id, and extends filter_condition_enum.
TMS schema rollback (DOWN)
migrations/103_tms_initial.down.sql
Reverts the UP migration by dropping triggers, functions, GIN indexes, all TMS tables and join/attribute tables, and ENUMs; removes launch.launch_type (and related column removals noted) using IF EXISTS and ordered DROP to satisfy dependencies.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant DB as Database
  participant TR_plan as Trigger tms_test_plan_search_vector_trigger
  participant FN_plan as Function update_tms_test_plan_search_vector()
  participant TR_case as Trigger tms_test_case_search_vector_trigger
  participant FN_case as Function update_tms_test_case_search_vector()

  Note over DB: UP migration creates tables, enums, functions, triggers, indexes
  Client->>DB: INSERT/UPDATE tms_test_plan (name, description)
  DB->>TR_plan: BEFORE INSERT/UPDATE fires
  TR_plan->>FN_plan: compute tsvector (name, description, attributes)
  FN_plan-->>DB: set NEW.search_vector
  DB-->>Client: row persisted (GIN index updated)

  Client->>DB: INSERT/UPDATE tms_test_case (name, description)
  DB->>TR_case: BEFORE INSERT/UPDATE fires
  TR_case->>FN_case: compute tsvector (name, description, attributes)
  FN_case-->>DB: set NEW.search_vector
  DB-->>Client: row persisted (GIN index updated)

  Note over DB: DOWN migration removes triggers/functions/indexes then drops TMS objects
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I hop through schemas, enums, and tiny rows,
I plant triggers where the full‑text garden grows.
I nibble columns, stitch relations neat,
Then sweep with DROP to make the pasture sweet. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "TMS Migration (to develop)" is directly related to the main content of the pull request, which introduces two database migration files for a Test Management System. The title clearly indicates that the changeset involves TMS migrations and identifies the target branch. However, the title is somewhat generic and doesn't specify that this migration creates a comprehensive, initial TMS schema with multiple tables, types, enums, triggers, and functions rather than describing a more modest TMS-related change. The "(to develop)" portion describes branch metadata rather than the nature of the changes themselves.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/EPMRPP-migrate-tms-to-develop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (10)
migrations/103_tms_initial.up.sql (10)

202-217: Index FK tms_test_case_version.test_case_id.

Partial unique index on defaults won’t help general joins. Add a regular index.

 CREATE UNIQUE INDEX idx_tms_test_case_version_default
     ON tms_test_case_version (test_case_id)
     WHERE is_default = true;
+
+CREATE INDEX idx_tms_test_case_version_test_case_id
+  ON tms_test_case_version (test_case_id);

254-263: Make step → steps_manual_scenario mandatory.

A step without a parent scenario is likely invalid; enforce NOT NULL.

-    steps_manual_scenario_id bigint
+    steps_manual_scenario_id bigint NOT NULL
         CONSTRAINT tms_step_fk_steps_manual_scenario
             REFERENCES tms_steps_manual_scenario

86-101: Add date integrity check for milestones.

Prevent inverted date ranges.

     end_date           TIMESTAMP,
     type               varchar(255),
@@
     test_plan_id       bigint
         CONSTRAINT tms_milestone_fk_test_plan
             REFERENCES tms_test_plan
 );
+ALTER TABLE tms_milestone
+  ADD CONSTRAINT chk_tms_milestone_dates
+  CHECK (end_date IS NULL OR start_date IS NULL OR end_date >= start_date);

279-296: Guard attachment file_size and avoid truncation risk.

  • Enforce non-negative size.
  • path_to_file can exceed 255; prefer text.
-    file_size      bigint,
-    path_to_file   varchar(255),
+    file_size      bigint CHECK (file_size IS NULL OR file_size >= 0),
+    path_to_file   text,

66-84: Index foreign keys on tms_test_plan.

Typical join/delete paths will benefit from indexes.

 );
 
+CREATE INDEX idx_tms_test_plan_project_id ON tms_test_plan (project_id);
+CREATE INDEX idx_tms_test_plan_environment_id ON tms_test_plan (environment_id);
+CREATE INDEX idx_tms_test_plan_product_version_id ON tms_test_plan (product_version_id);
+CREATE INDEX idx_tms_test_plan_launch_id ON tms_test_plan (launch_id);

52-64: Cover common hierarchy and M2M filters.

  • Add index on test_folder.parent_id for tree navigation.
  • Add secondary index on tms_environment_dataset(dataset_id) to complement the unique (environment_id, dataset_id).
 CREATE INDEX idx_tms_test_folder_project_id ON tms_test_folder (project_id, id);
+CREATE INDEX idx_tms_test_folder_parent_id ON tms_test_folder (parent_id);
@@
     CONSTRAINT tms_environment_dataset_unique UNIQUE (environment_id, dataset_id)
 );
+
+CREATE INDEX idx_tms_environment_dataset_dataset_id
+  ON tms_environment_dataset (dataset_id);

Also applies to: 118-118


168-186: Auto-maintain updated_at; consider generated search_vector.

  • Currently updated_at won’t refresh on UPDATE.
  • Optional: replace trigger-managed tsvector with a generated column for simpler maintenance (PG12+).

Option A (minimal): add timestamp trigger.

CREATE OR REPLACE FUNCTION set_updated_at() RETURNS TRIGGER AS $$
BEGIN
  NEW.updated_at := now();
  RETURN NEW;
END; $$ LANGUAGE plpgsql;

CREATE TRIGGER tms_test_case_set_updated_at
  BEFORE UPDATE ON tms_test_case
  FOR EACH ROW EXECUTE FUNCTION set_updated_at();

Option B (generated column, replaces trigger/function):

-- In table definition:
-- search_vector tsvector GENERATED ALWAYS AS (
--   to_tsvector('simple',
--     coalesce(name,'')||' '||coalesce(description,'')||' '||coalesce(priority,''))
-- ) STORED
-- and drop trigger/function.

Also applies to: 138-139


8-17: Project-level uniqueness on human-readable names (confirm).

Do you require uniqueness for:

  • product_version.version within project,
  • dataset.name within project,
  • environment.name within project?
    If yes, add unique constraints accordingly.
-- Examples:
ALTER TABLE tms_product_version
  ADD CONSTRAINT uq_tms_product_version_proj_ver UNIQUE (project_id, version);

ALTER TABLE tms_dataset
  ADD CONSTRAINT uq_tms_dataset_proj_name UNIQUE (project_id, name);

ALTER TABLE tms_environment
  ADD CONSTRAINT uq_tms_environment_proj_name UNIQUE (project_id, name);

Also applies to: 21-29, 42-50


218-233: One-to-one manual scenario shape (confirm).

Model enforces a single manual_scenario per test_case_version and either TEXT or STEPS via sub-tables. If that’s intended, great; if you need to allow both types simultaneously, remove the UNIQUE on test_case_version_id and add a composite unique (test_case_version_id, type).

-    test_case_version_id      bigint
-        UNIQUE
+    test_case_version_id      bigint
         CONSTRAINT tms_manual_scenario_fk_test_case_version
             REFERENCES tms_test_case_version,
-- Alternative:
-- ALTER TABLE tms_manual_scenario
--   ADD CONSTRAINT uq_manual_scenario_one_per_type
--   UNIQUE (test_case_version_id, type);

Also applies to: 234-250, 254-264, 265-275


1-6: Attributes key length/index (confirm).

If tms_attribute.key is frequently filtered by prefix/exact match, consider adding a dedicated index (btree/trgm as applicable). 255 may be tight for some metadata keys; TEXT is safer.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9503bb5 and 21fe65d.

📒 Files selected for processing (2)
  • migrations/103_tms_initial.down.sql (1 hunks)
  • migrations/103_tms_initial.up.sql (1 hunks)
🔇 Additional comments (1)
migrations/103_tms_initial.down.sql (1)

1-50: Down looks consistent; remember to mirror any new indexes/constraints you add.

The drop order and IF EXISTS usage are solid. If you adopt the suggested new indexes/constraints in the up migration, add corresponding DROP statements here to keep rollbacks clean.

Comment on lines +31 to +40
CREATE TABLE tms_dataset_data
(
id BIGSERIAL
CONSTRAINT tms_dataset_data_pk PRIMARY KEY,
key varchar(255),
value varchar(255),
dataset_id bigint NOT NULL
CONSTRAINT tms_dataset_attribute_fk_tms_dataset
REFERENCES tms_dataset
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure dataset key uniqueness per dataset and fix FK name typo.

  • Prevent duplicate keys within the same dataset.
  • Current FK name looks copy-pasted (“attribute”); align with table naming.
-    dataset_id bigint NOT NULL
-        CONSTRAINT tms_dataset_attribute_fk_tms_dataset
-            REFERENCES tms_dataset
+    dataset_id bigint NOT NULL
+        CONSTRAINT tms_dataset_data_fk_dataset
+            REFERENCES tms_dataset,
+    CONSTRAINT tms_dataset_data_unique_key_per_dataset UNIQUE (dataset_id, key)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CREATE TABLE tms_dataset_data
(
id BIGSERIAL
CONSTRAINT tms_dataset_data_pk PRIMARY KEY,
key varchar(255),
value varchar(255),
dataset_id bigint NOT NULL
CONSTRAINT tms_dataset_attribute_fk_tms_dataset
REFERENCES tms_dataset
);
CREATE TABLE tms_dataset_data
(
id BIGSERIAL
CONSTRAINT tms_dataset_data_pk PRIMARY KEY,
key varchar(255),
value varchar(255),
dataset_id bigint NOT NULL
CONSTRAINT tms_dataset_data_fk_dataset
REFERENCES tms_dataset,
CONSTRAINT tms_dataset_data_unique_key_per_dataset UNIQUE (dataset_id, key)
);
🤖 Prompt for AI Agents
migrations/103_tms_initial.up.sql around lines 31 to 40: the tms_dataset_data
table needs a per-dataset uniqueness guarantee for key and the foreign key
constraint name should reflect this table (not “attribute”); update the CREATE
TABLE so that key is NOT NULL (to ensure meaningful uniqueness), add a UNIQUE
constraint on (dataset_id, key) to prevent duplicate keys within the same
dataset, and rename the FK constraint to something like
tms_dataset_data_fk_dataset referencing tms_dataset(id).

Comment on lines +136 to +152
id BIGSERIAL
CONSTRAINT tms_test_case_pk PRIMARY KEY,
created_at TIMESTAMP DEFAULT now() NOT NULL,
updated_at TIMESTAMP DEFAULT now() NOT NULL,
name varchar(255),
description varchar(255),
priority varchar(255),
search_vector tsvector,
external_id varchar(255),
test_folder_id bigint NOT NULL
CONSTRAINT tms_test_case_fk_test_folder
REFERENCES tms_test_folder,
dataset_id bigint
CONSTRAINT tms_test_case_fk_dataset
REFERENCES tms_dataset,
CONSTRAINT tms_test_case_name_folder_unique UNIQUE (name, test_folder_id)
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add index for tms_test_case lookups by folder.

Queries “all cases in folder” will not use the (name, test_folder_id) unique index efficiently. Add a single-column index.

 CREATE INDEX idx_tms_test_plan_test_case_test_plan_id ON tms_test_plan_test_case (test_plan_id);
 CREATE INDEX idx_tms_test_plan_test_case_test_case_id ON tms_test_plan_test_case (test_case_id);
+
+-- Speed up folder-level listings and deletes
+CREATE INDEX idx_tms_test_case_test_folder_id ON tms_test_case (test_folder_id);

Also applies to: 165-167

🤖 Prompt for AI Agents
In migrations/103_tms_initial.up.sql around lines 136-152 (and also apply the
same change for the table defined at lines 165-167), the schema lacks a
single-column index on test_folder_id which prevents efficient “all cases in
folder” lookups; add a standalone B-tree index for test_folder_id on the
tms_test_case table (e.g. CREATE INDEX ... ON tms_test_case(test_folder_id)) and
also create the equivalent single-column index on the table defined at lines
165-167 so folder-based queries use the index instead of scanning the unique
(name, test_folder_id) constraint.

Comment on lines +334 to +340
CREATE TYPE LAUNCH_TYPE_ENUM AS ENUM ('AUTOMATION', 'MANUAL');
ALTER TABLE launch
ADD COLUMN launch_type LAUNCH_TYPE_ENUM;
ALTER TABLE launch
ALTER COLUMN launch_type SET DEFAULT 'AUTOMATION';
UPDATE launch
SET launch_type = 'AUTOMATION';
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make launch.launch_type NOT NULL after backfill.

Nulls would complicate downstream logic and analytics. You already backfill and set default; lock in integrity with NOT NULL.

 ALTER TABLE launch
     ALTER COLUMN launch_type SET DEFAULT 'AUTOMATION';
 UPDATE launch
 SET launch_type = 'AUTOMATION';
+ALTER TABLE launch
+    ALTER COLUMN launch_type SET NOT NULL;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
CREATE TYPE LAUNCH_TYPE_ENUM AS ENUM ('AUTOMATION', 'MANUAL');
ALTER TABLE launch
ADD COLUMN launch_type LAUNCH_TYPE_ENUM;
ALTER TABLE launch
ALTER COLUMN launch_type SET DEFAULT 'AUTOMATION';
UPDATE launch
SET launch_type = 'AUTOMATION';
CREATE TYPE LAUNCH_TYPE_ENUM AS ENUM ('AUTOMATION', 'MANUAL');
ALTER TABLE launch
ADD COLUMN launch_type LAUNCH_TYPE_ENUM;
ALTER TABLE launch
ALTER COLUMN launch_type SET DEFAULT 'AUTOMATION';
UPDATE launch
SET launch_type = 'AUTOMATION';
ALTER TABLE launch
ALTER COLUMN launch_type SET NOT NULL;
🤖 Prompt for AI Agents
In migrations/103_tms_initial.up.sql around lines 334 to 340, the launch_type
column is created, defaulted and backfilled but not constrained to NOT NULL; add
an ALTER TABLE launch ALTER COLUMN launch_type SET NOT NULL statement after the
backfill and default are applied so the column cannot contain NULLs going
forward and data integrity is enforced.

@imashkanov imashkanov force-pushed the feature/EPMRPP-migrate-tms-to-develop branch 2 times, most recently from df2e346 to 7e1c575 Compare September 16, 2025 07:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (6)
migrations/103_tms_initial.up.sql (6)

247-259: Remove redundant unique index; the column constraint already creates it.

manual_scenario_id has UNIQUE at column-level. The separate UNIQUE INDEX duplicates it.

-CREATE UNIQUE INDEX idx_tms_manual_scenario_preconditions_scenario_unique
-    ON tms_manual_scenario_preconditions(manual_scenario_id);

137-146: Add ON DELETE CASCADE to junction/mapping FKs to prevent orphans and ease cleanup.

These are pure link tables; cascading deletions are expected.

Examples:

--- tms_test_folder_test_item
-        REFERENCES tms_test_folder,
+        REFERENCES tms_test_folder ON DELETE CASCADE,
-        REFERENCES test_item,
+        REFERENCES test_item ON DELETE CASCADE,

--- tms_test_plan_test_case
-            REFERENCES tms_test_plan,
+            REFERENCES tms_test_plan ON DELETE CASCADE,
-            REFERENCES tms_test_case,
+            REFERENCES tms_test_case ON DELETE CASCADE,

--- tms_test_case_test_item
-            REFERENCES tms_test_case,
+            REFERENCES tms_test_case ON DELETE CASCADE,
-            REFERENCES test_item,
+            REFERENCES test_item ON DELETE CASCADE,

--- tms_step_test_item
-            REFERENCES tms_step,
+            REFERENCES tms_step ON DELETE CASCADE,
-            REFERENCES test_item,
+            REFERENCES test_item ON DELETE CASCADE,

--- tms_step_attachment
-            REFERENCES tms_step,
+            REFERENCES tms_step ON DELETE CASCADE,
-            REFERENCES tms_attachment,
+            REFERENCES tms_attachment ON DELETE CASCADE,

--- tms_text_manual_scenario_attachment
-            REFERENCES tms_text_manual_scenario,
+            REFERENCES tms_text_manual_scenario ON DELETE CASCADE,
-            REFERENCES tms_attachment,
+            REFERENCES tms_attachment ON DELETE CASCADE,

--- tms_manual_scenario_preconditions_attachment
-            REFERENCES tms_manual_scenario_preconditions,
+            REFERENCES tms_manual_scenario_preconditions ON DELETE CASCADE,
-            REFERENCES tms_attachment,
+            REFERENCES tms_attachment ON DELETE CASCADE,

Please confirm intended deletion semantics match this.

Also applies to: 171-180, 202-211, 291-300, 323-333, 338-348, 353-363


66-85: Consider nullifying optional references on parent delete.

environment_id, product_version_id, launch_id look optional. Prefer ON DELETE SET NULL to avoid delete conflicts.

-        CONSTRAINT tms_test_plan_fk_environment
-            REFERENCES tms_environment,
+        CONSTRAINT tms_test_plan_fk_environment
+            REFERENCES tms_environment ON DELETE SET NULL,
...
-        CONSTRAINT tms_test_plan_fk_product_version
-            REFERENCES tms_product_version,
+        CONSTRAINT tms_test_plan_fk_product_version
+            REFERENCES tms_product_version ON DELETE SET NULL,
...
-        CONSTRAINT tms_test_plan_fk_launch
-            REFERENCES launch
+        CONSTRAINT tms_test_plan_fk_launch
+            REFERENCES launch ON DELETE SET NULL

155-169: Keep updated_at accurate.

Add a trigger to set updated_at = now() on UPDATE.

CREATE OR REPLACE FUNCTION set_updated_at() RETURNS TRIGGER AS $$
BEGIN
  NEW.updated_at := now();
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER tms_test_case_set_updated_at
  BEFORE UPDATE ON tms_test_case
  FOR EACH ROW EXECUTE FUNCTION set_updated_at();

305-318: Harden attachment metadata.

Default created_at, and enforce non-negative file_size.

-    file_size    bigint,
+    file_size    bigint,
     path_to_file varchar(255) NOT NULL,
-    created_at   TIMESTAMP,
+    created_at   TIMESTAMP DEFAULT now() NOT NULL,
     expires_at   TIMESTAMP,
...
+    CONSTRAINT tms_attachment_file_size_nonnegative
+      CHECK (file_size IS NULL OR file_size >= 0),

103-119: Resolve the “many-to-many?” TODOs or track them.

Milestone ↔ product_version / test_plan likely need junction tables. Create tasks or adjust now.

I can propose junction table DDLs if you confirm the intended relationships.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 688ef47 and 21b74b5.

📒 Files selected for processing (2)
  • migrations/103_tms_initial.down.sql (1 hunks)
  • migrations/103_tms_initial.up.sql (1 hunks)
🔇 Additional comments (3)
migrations/103_tms_initial.up.sql (3)

151-169: Add index for folder-level test case lookups.

Single-column index on test_folder_id avoids scans when listing/deleting cases by folder.

 -- existing table definition...
 );
 
+-- Speed up folder-level listings and deletes
+CREATE INDEX idx_tms_test_case_test_folder_id ON tms_test_case (test_folder_id);

31-40: Ensure per-dataset key uniqueness and correct FK name.

Make key NOT NULL, enforce (dataset_id, key) uniqueness, and fix FK constraint name.

 CREATE TABLE tms_dataset_data
 (
     id         BIGSERIAL
         CONSTRAINT tms_dataset_data_pk PRIMARY KEY,
-    key        varchar(255),
+    key        varchar(255) NOT NULL,
     value      varchar(255),
     dataset_id bigint NOT NULL
-        CONSTRAINT tms_dataset_attribute_fk_tms_dataset
-            REFERENCES tms_dataset
+        CONSTRAINT tms_dataset_data_fk_dataset
+            REFERENCES tms_dataset(id),
+    CONSTRAINT tms_dataset_data_unique_key_per_dataset UNIQUE (dataset_id, key)
 );

405-411: Make launch.launch_type NOT NULL after backfill.

You set default and backfill; lock integrity with NOT NULL.

 ALTER TABLE launch
     ALTER COLUMN launch_type SET DEFAULT 'AUTOMATION';
 UPDATE launch
 SET launch_type = 'AUTOMATION';
+ALTER TABLE launch
+    ALTER COLUMN launch_type SET NOT NULL;

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (3)
migrations/103_tms_initial.up.sql (2)

452-463: Add NOT NULL constraint to launch.launch_type after backfill.

The column is backfilled to 'AUTOMATION' and has a default, but is not constrained to NOT NULL. Nulls would complicate downstream logic and analytics.

Apply this diff:

 CREATE TYPE LAUNCH_TYPE_ENUM AS ENUM ('AUTOMATION', 'MANUAL');
 ALTER TABLE launch
     ADD COLUMN launch_type LAUNCH_TYPE_ENUM;
 ALTER TABLE launch
     ALTER COLUMN launch_type SET DEFAULT 'AUTOMATION';
 UPDATE launch
 SET launch_type = 'AUTOMATION';
+ALTER TABLE launch
+    ALTER COLUMN launch_type SET NOT NULL;
 
 ALTER TABLE launch
     ADD COLUMN test_plan_id bigint;

46-55: Fix tms_dataset_data: add NOT NULL, composite uniqueness, and correct FK name.

The table lacks data integrity constraints:

  • key should be NOT NULL to ensure meaningful uniqueness
  • Missing UNIQUE (dataset_id, key) to prevent duplicate keys per dataset
  • FK name tms_dataset_attribute_fk_tms_dataset is misnamed (should reflect the table being defined)

Apply this diff:

 CREATE TABLE tms_dataset_data
 (
     id         BIGSERIAL
         CONSTRAINT tms_dataset_data_pk PRIMARY KEY,
-    key        varchar(255),
+    key        varchar(255) NOT NULL,
     value      varchar(255),
     dataset_id bigint NOT NULL
-        CONSTRAINT tms_dataset_attribute_fk_tms_dataset
-            REFERENCES tms_dataset
+        CONSTRAINT tms_dataset_data_fk_dataset
+            REFERENCES tms_dataset,
+    CONSTRAINT tms_dataset_data_unique_key_per_dataset UNIQUE (dataset_id, key)
 );
migrations/103_tms_initial.down.sql (1)

1-9: Remove duplicate/incorrect index drops at lines 1-2 and consolidate.

Lines 1-2 attempt to drop indexes with names that don't match the up migration. Specifically, the up migration creates indexes named idx_preconditions_attachment_* (line 391-392), but lines 1-2 try to drop idx_tms_manual_scenario_preconditions_attachment_*. The IF EXISTS guards prevent errors, but the unnecessary drops add noise and confusion.

Compare against up migration:

  • Up: CREATE INDEX idx_preconditions_attachment_preconditions_id ON tms_manual_scenario_preconditions_attachment(preconditions_id); (line 391)
  • Down line 1 tries: DROP INDEX IF EXISTS idx_tms_manual_scenario_preconditions_attachment_attachment_id;
  • Down line 5 correctly: DROP INDEX IF EXISTS idx_preconditions_attachment_attachment_id;

Apply this diff to consolidate:

-DROP INDEX IF EXISTS idx_tms_manual_scenario_preconditions_attachment_attachment_id;
-DROP INDEX IF EXISTS idx_tms_manual_scenario_preconditions_attachment_preconditions_id;
 DROP TABLE IF EXISTS tms_manual_scenario_preconditions_attachment;
 
-DROP INDEX IF EXISTS idx_preconditions_attachment_attachment_id;
-DROP INDEX IF EXISTS idx_preconditions_attachment_preconditions_id;
 DROP INDEX IF EXISTS idx_tms_text_manual_scenario_attachment_scenario_id;
 DROP INDEX IF EXISTS idx_tms_text_manual_scenario_attachment_attachment_id;
 DROP TABLE IF EXISTS tms_text_manual_scenario_attachment;
+
+DROP INDEX IF EXISTS idx_preconditions_attachment_preconditions_id;
+DROP INDEX IF EXISTS idx_preconditions_attachment_attachment_id;
 
 DROP INDEX IF EXISTS idx_tms_step_attachment_attachment_id;
🧹 Nitpick comments (1)
migrations/103_tms_initial.up.sql (1)

163-181: Add single-column index on test_folder_id for efficient folder queries.

Queries like "all test cases in folder X" will scan the composite unique index (name, test_folder_id) inefficiently. Add a dedicated B-tree index on the folder ID.

Add this index after the table definition:

 CREATE TABLE tms_test_case
 (
     id             BIGSERIAL
         CONSTRAINT tms_test_case_pk PRIMARY KEY,
     created_at     TIMESTAMP DEFAULT now() NOT NULL,
     updated_at     TIMESTAMP DEFAULT now() NOT NULL,
     name           varchar(255),
     description    varchar(255),
     priority       varchar(255),
     search_vector  tsvector,
     external_id    varchar(255),
     test_folder_id bigint NOT NULL
         CONSTRAINT tms_test_case_fk_test_folder
             REFERENCES tms_test_folder,
     dataset_id     bigint
         CONSTRAINT tms_test_case_fk_dataset
             REFERENCES tms_dataset,
     CONSTRAINT tms_test_case_name_folder_unique UNIQUE (name, test_folder_id)
 );
+
+CREATE INDEX idx_tms_test_case_test_folder_id ON tms_test_case (test_folder_id);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fac799e and 8b4f24d.

📒 Files selected for processing (2)
  • migrations/103_tms_initial.down.sql (1 hunks)
  • migrations/103_tms_initial.up.sql (1 hunks)

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.

2 participants