Skip to content

Fix post-migration-first: update tests, Dockerfile, and docs to match new schema approach#34

Merged
alvagante merged 2 commits into082from
copilot/sub-pr-32
Mar 14, 2026
Merged

Fix post-migration-first: update tests, Dockerfile, and docs to match new schema approach#34
alvagante merged 2 commits into082from
copilot/sub-pr-32

Conversation

Copy link
Contributor

Copilot AI commented Mar 14, 2026

After consolidating to a migration-first schema approach, several artifacts still referenced the removed schema.sql base file and the old hybrid layout. This PR addresses review feedback from #32.

Test fixes

Three test files loaded the deleted schema.sql directly for in-memory DB setup:

  • 006_add_batch_executions.test.ts — load migrations/000_initial_schema.sql instead
  • database-performance.test.ts — use MigrationRunner to apply all migrations (removes the manual ALTER TABLE hack for batch columns)
  • performance-test.ts — load migrations/000_initial_schema.sql instead

Two tests also had stale expectations from before migration 000 existed:

  • migration-integration.test.ts — expected 6 migrations (001–006); updated to 7 (000–006)
  • index-verification.test.ts — expected composite indexes (idx_user_roles_composite, etc.) that were never added to any migration; updated to verify the single-column junction table indexes that do exist

Dockerfile

Changed the runtime COPY from the entire src/database/ tree (TypeScript sources included) to just the migrations directory:

# Before — copies .ts sources into the runtime image
COPY --from=backend-builder --chown=pabawi:pabawi /app/backend/src/database/ ./dist/database/

# After — only the SQL files needed at runtime
COPY --from=backend-builder --chown=pabawi:pabawi /app/backend/src/database/migrations ./dist/database/migrations

Documentation

Updated .kiro/database-cleanup-prompt.md "Current File Structure" section to reflect the post-cleanup state (removed references to deleted schema.sql, rbac-schema.sql, audit-schema.sql, migrations.sql) and fixed a truncated sentence.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: alvagante <283804+alvagante@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 14, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • httpstat.us
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/dist/workers/forks.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/dist/workers/forks.js lude nings.cjs /forks.js -x ase/obj.target/cpu_features/deps/cpu_features/sr-I -o de/node/bin/as - (dns block)
  • puppetdb.example.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/dist/workers/forks.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/dist/workers/forks.js l/config (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/pabawi/pabawi/node_modules/vitest/dist/workers/forks.js 14.0/deps/openssstash nings.cjs /forks.js Rele�� 14.0/include/node (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] [082] Consolidate backend SQLite schema management Fix post-migration-first: update tests, Dockerfile, and docs to match new schema approach Mar 14, 2026
Copilot AI requested a review from alvagante March 14, 2026 16:10
@alvagante alvagante marked this pull request as ready for review March 14, 2026 18:41
Copilot AI review requested due to automatic review settings March 14, 2026 18:41
@alvagante alvagante merged commit 566b1cb into 082 Mar 14, 2026
1 check passed
@alvagante alvagante deleted the copilot/sub-pr-32 branch March 14, 2026 18:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns tests, Docker packaging, and internal docs with the repository’s migration-first SQLite schema approach (after removal of the legacy schema.sql/hybrid layout).

Changes:

  • Updated DB test setup to use migration files (and in one case MigrationRunner) instead of the removed schema.sql.
  • Adjusted migration/index expectations in tests to match the actual set of migrations and indexes.
  • Updated Docker runtime image to copy only SQL migrations, and refreshed the .kiro prompt’s schema file structure section.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
backend/test/performance/database-performance.test.ts Uses MigrationRunner to apply all migrations for in-memory performance setup.
backend/test/database/performance-test.ts Switches schema bootstrap to 000_initial_schema.sql (but currently not enough for ExecutionRepository).
backend/test/database/migration-integration.test.ts Updates expectations to include migration 000.
backend/test/database/index-verification.test.ts Removes expectations for non-existent composite indexes; validates real junction-table indexing.
backend/test/database/006_add_batch_executions.test.ts Bootstraps from migration 000 instead of deleted schema.sql.
Dockerfile Copies only src/database/migrations into runtime image.
.kiro/database-cleanup-prompt.md Updates “Current File Structure” and fixes a truncated checklist line.
Comments suppressed due to low confidence (1)

backend/test/database/performance-test.ts:34

  • ExecutionRepository.create() inserts batch_id/batch_position columns unconditionally, but this script only applies migration 000, which does not add those columns (they’re introduced in migration 006). As a result, the first repo.create() call will fail with “no such column: batch_id”. Apply migrations through 006 (preferably via MigrationRunner) or update the setup to create the latest executions schema before using ExecutionRepository.
  // Load and execute migration 000 (initial schema)
  const schemaPath = join(__dirname, '../../src/database/migrations/000_initial_schema.sql');
  const schema = readFileSync(schemaPath, 'utf-8');

  // Split by semicolon and execute each statement
  const statements = schema.split(';').filter(s => s.trim().length > 0);
  for (const statement of statements) {
    await runAsync(db, statement);
  }

Comment on lines 14 to +19
backend/src/database/
├── schema.sql # Base schema: executions table
├── rbac-schema.sql # Base schema: RBAC tables (DUPLICATE of 001)
├── audit-schema.sql # ⚠️ ORPHANED - never loaded, duplicates 004
├── migrations.sql # ⚠️ ORPHANED - never loaded, superseded
├── DatabaseService.ts # Loads schema.sql + rbac-schema.sql, then runs migrations
├── DatabaseService.ts # Runs only MigrationRunner (migration-first approach)
├── MigrationRunner.ts # Runs numbered migrations from migrations/
└── migrations/
├── 001_initial_rbac.sql # Creates RBAC tables (duplicates rbac-schema.sql)
├── 000_initial_schema.sql # Initial schema: executions + revoked_tokens tables
├── 001_initial_rbac.sql # Creates RBAC tables
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.

3 participants