Skip to content

feat: migrate station_* and uex_* catalog table PKs to UUIDv7#288

Open
GitAddRemote wants to merge 2 commits into
mainfrom
feature/ISSUE-219
Open

feat: migrate station_* and uex_* catalog table PKs to UUIDv7#288
GitAddRemote wants to merge 2 commits into
mainfrom
feature/ISSUE-219

Conversation

@GitAddRemote
Copy link
Copy Markdown
Owner

Summary

  • Adds migration 1780030000000-MigrateTablePksToUuidV7 that converts all station_* and uex_* catalog table PKs from BIGSERIAL/bigint to UUID with gen_random_uuid() default
  • Drops and restores FK constraints on station_terminal and station_terminal_distance around the column type changes
  • Updates all 11 uex_* TypeORM entity files — id changed from @PrimaryGeneratedColumn({ type: 'bigint' }) id!: number to @PrimaryGeneratedColumn('uuid') id!: string
  • Updates 5 entity spec files and the org-inventory service spec to use UUID string values for mock id fields
  • Registers the new migration in data-source.ts

Test plan

  • pnpm --filter backend typecheck passes
  • pnpm --filter backend test --testPathPattern="uex.*entity|org-inventory" passes
  • pnpm migration:run completes without error on a fresh dev database
  • SELECT id FROM station_star_system LIMIT 1 returns a UUID
  • SELECT id FROM uex_star_system LIMIT 1 returns a UUID
  • GET /api/uex/star-systems returns id fields as UUIDs
  • Re-running the ETL after migration produces no errors
  • pnpm migration:revert rolls back cleanly

Closes #219

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
Copilot AI review requested due to automatic review settings June 2, 2026 20:12
Copy link
Copy Markdown
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 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_* and uex_* table PKs to UUID and adjust station_terminal / station_terminal_distance FK constraints.
  • Updated UEX TypeORM entities to use @PrimaryGeneratedColumn('uuid') and changed id typings from number to string.
  • 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;

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.

Migrate pre-existing catalog tables to UUIDv7 primary keys

2 participants