feat: migrate station_* and uex_* catalog table PKs to UUIDv7#288
Open
GitAddRemote wants to merge 2 commits into
Open
feat: migrate station_* and uex_* catalog table PKs to UUIDv7#288GitAddRemote wants to merge 2 commits into
GitAddRemote wants to merge 2 commits into
Conversation
Converts all pre-existing station_* and uex_* catalog table primary keys from BIGSERIAL/bigint to UUID with gen_random_uuid() default. FK columns on station_terminal and station_terminal_distance are also converted. TypeORM entity id fields updated from number to string. Entity spec mocks and the org-inventory service spec updated to use UUID string values. Closes #219
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to migrate catalog table primary keys for station_* and uex_* tables from BIGSERIAL/bigint to UUIDs, aligning TypeORM entity definitions and unit tests with the new UUID id type and registering a new migration in the backend data source.
Changes:
- Added a new TypeORM migration to alter
station_*anduex_*table PKs to UUID and adjuststation_terminal/station_terminal_distanceFK constraints. - Updated UEX TypeORM entities to use
@PrimaryGeneratedColumn('uuid')and changedidtypings fromnumbertostring. - Updated affected unit tests/mocks to use string IDs and registered the migration in
backend/src/data-source.ts.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/src/migrations/1780030000000-MigrateTablePksToUuidV7.ts | Adds PK/FK alteration migration for station_* and uex_* tables |
| backend/src/data-source.ts | Registers the new migration |
| backend/src/modules/uex/entities/uex-star-system.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-planet.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-moon.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-city.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-space-station.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-outpost.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-poi.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-company.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-category.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-commodity.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-item.entity.ts | Switches UEX entity PK to UUID string |
| backend/src/modules/uex/entities/uex-star-system.entity.spec.ts | Updates entity test to use string UUID-like ID |
| backend/src/modules/uex/entities/uex-planet.entity.spec.ts | Updates entity test to use string UUID-like ID |
| backend/src/modules/uex/entities/uex-company.entity.spec.ts | Updates entity test to use string UUID-like ID |
| backend/src/modules/uex/entities/uex-category.entity.spec.ts | Updates entity test to use string UUID-like ID |
| backend/src/modules/uex/entities/uex-item.entity.spec.ts | Updates entity test to use string UUID-like ID |
| backend/src/modules/org-inventory/org-inventory.service.spec.ts | Updates mocked UexItem.id to a string to match new typing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+15
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| // ------------------------------------------------------------------------- | ||
| // station_* tables — pure SQL tables, no TypeORM entity management | ||
| // Order: leaf tables first, then tables with FKs pointing at them | ||
| // ------------------------------------------------------------------------- | ||
|
|
||
| // Drop FK constraints on station_terminal before altering referenced tables | ||
| await queryRunner.query(` |
Comment on lines
+55
to
+59
| ALTER TABLE "${table}" | ||
| ALTER COLUMN id DROP DEFAULT, | ||
| ALTER COLUMN id TYPE UUID USING gen_random_uuid(), | ||
| ALTER COLUMN id SET DEFAULT gen_random_uuid() | ||
| `); |
Comment on lines
+75
to
+80
| for (const col of terminalFkCols) { | ||
| await queryRunner.query(` | ||
| ALTER TABLE station_terminal | ||
| ALTER COLUMN ${col} TYPE UUID USING NULL::UUID | ||
| `); | ||
| } |
Comment on lines
+219
to
+226
| for (const table of stationTables) { | ||
| await queryRunner.query(` | ||
| CREATE SEQUENCE IF NOT EXISTS "${table}_id_seq"; | ||
| ALTER TABLE "${table}" | ||
| ALTER COLUMN id DROP DEFAULT, | ||
| ALTER COLUMN id TYPE BIGINT USING NULL::BIGINT, | ||
| ALTER COLUMN id SET DEFAULT nextval('"${table}_id_seq"') | ||
| `); |
Comment on lines
27
to
30
| export class UexItem extends BaseUexEntity { | ||
| @PrimaryGeneratedColumn({ type: 'bigint' }) | ||
| id!: number; | ||
| @PrimaryGeneratedColumn('uuid') | ||
| id!: string; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
1780030000000-MigrateTablePksToUuidV7that converts allstation_*anduex_*catalog table PKs fromBIGSERIAL/biginttoUUIDwithgen_random_uuid()defaultstation_terminalandstation_terminal_distancearound the column type changesuex_*TypeORM entity files —idchanged from@PrimaryGeneratedColumn({ type: 'bigint' }) id!: numberto@PrimaryGeneratedColumn('uuid') id!: stringidfieldsdata-source.tsTest plan
pnpm --filter backend typecheckpassespnpm --filter backend test --testPathPattern="uex.*entity|org-inventory"passespnpm migration:runcompletes without error on a fresh dev databaseSELECT id FROM station_star_system LIMIT 1returns a UUIDSELECT id FROM uex_star_system LIMIT 1returns a UUIDGET /api/uex/star-systemsreturnsidfields as UUIDspnpm migration:revertrolls back cleanlyCloses #219