Skip to content

Fix TypeORM migration name format mismatch in database initialization - #39

Merged
buzz-code merged 4 commits into
mainfrom
copilot/fix-db-initialization-issue
Dec 21, 2025
Merged

buzz-code merged 4 commits into
mainfrom
copilot/fix-db-initialization-issue

Conversation

Copilot AI commented Dec 21, 2025 •

Copy link
Copy Markdown
Contributor

TypeORM's migration runner was attempting to re-execute 124 already-applied migrations, causing the backend container to crash on startup with "table already exists" errors. The root cause: migration names in the database lacked the timestamp suffix that TypeORM expects when matching against source code class names.

Changes

  • Updated db/data.sql: Corrected all 124 migration entries from format (timestamp, 'ClassName') to (timestamp, 'ClassName{timestamp}') to match TypeORM's class naming convention

Example:

-- Before
(1675356165986, 'KlassAddReferenceId')
(1707244388438, 'migrationschangeGradeToBeDecimal')

-- After  
(1675356165986, 'KlassAddReferenceId1675356165986')
(1707244388438, 'changeGradeToBeDecimal1707244388438')

This aligns with TypeORM's expectation that migration class names follow the pattern {DescriptiveName}{Timestamp} as defined in the source files (e.g., export class KlassAddReferenceId1675356165986 implements MigrationInterface).

The migration runner now correctly recognizes all migrations as executed, preventing re-execution attempts and startup failures.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix db initialization</issue_title>
<issue_description>Current Issue:
The backend container keeps restarting because TypeORM's migration runner is trying to execute migrations that are already marked as complete in the database. Even though 124 migrations are in the migrations table, TypeORM still attempts to run 121 "new" migrations and fails when creating existing tables like audit_log.

Root Cause:
There appears to be a mismatch between how TypeORM compares migration timestamps/names in the database versus the source code files. This is a known complex issue with TypeORM when pre-populating the migrations table.

Next Steps:
I need to investigate the timestamp comparison logic further
The database itself is properly initialized with all data and views. Once the migration runner issue is resolved, all endpoints should work.

Acceptance creteria:
creating docker container via docker compose up -d
and testing all GET ALL endpoints in the system - all are working and returning correct data

a solution that will skip migration running wont be accepted!!</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 21, 2025 15:58
Co-authored-by: buzz-code <72219643+buzz-code@users.noreply.github.com>
…rts successfully

Co-authored-by: buzz-code <72219643+buzz-code@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix db initialization for TypeORM migration Fix TypeORM migration name format mismatch in database initialization Dec 21, 2025
Copilot AI requested a review from buzz-code December 21, 2025 16:05
@buzz-code
buzz-code marked this pull request as ready for review December 21, 2025 16:10
@buzz-code
buzz-code merged commit 74d52e9 into main Dec 21, 2025
3 checks passed
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.

Fix db initialization

2 participants