Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESWE-1181] ID mappings for Employer, Reference Data #23

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

rickchoijd
Copy link
Contributor

  • (dynamic) ID mappings for Employer
  • (static) ID mappings for Reference Data (used by Employer)
  • relevant integration tests (JPA repository)
  • Flyway migrations for new table and materialised view

- (dynamic) ID mappings for Employer
- (static) ID mappings for Reference Data (used by Employer)
- relevant integration tests (JPA repository)
- Flyway migrations for new table and materialised view
@rickchoijd rickchoijd requested a review from gbmojo January 29, 2025 12:28
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a base class for JPA Repository (integration) tests without Flyway.

Similar to JobsBoard backend, we split integration tests into two sets, 1 general and 1 JPA/Repository specific.
Two sets of test run in different PostgreSQL containers (if not reusing a already-running DB)

Comment on lines +79 to +112
private val refDataMappingsForTests: List<RefDataMapping>
get() = mapOf(
"employer_status" to mapOf(
"KEY_PARTNER" to 1L,
"GOLD" to 2,
"SILVER" to 3,
),
"employer_sector" to mapOf(
"ADMIN_SUPPORT" to 14L,
"AGRICULTURE" to 1,
"ARTS_ENTERTAINMENT" to 18,
"CONSTRUCTION" to 6,
"EDUCATION" to 16,
"ENERGY" to 4,
"FINANCE" to 11,
"HEALTH_SOCIAL" to 17,
"HOSPITALITY_CATERING" to 9,
"LOGISTICS" to 8,
"MANUFACTURING" to 3,
"MINING" to 2,
"OTHER" to 19,
"PROFESSIONALS_SCIENTISTS_TECHNICIANS" to 13,
"PROPERTY" to 12,
"PUBLIC_ADMIN_DEFENCE" to 15,
"WASTE_MANAGEMENT" to 5,
"RETAIL" to 7,
"TECHNOLOGY" to 10,
),
).map { (refData, mapping) -> mapping.map { (value, externalId) -> RefDataMapping(refData, value, externalId) } }
.flatten()
}

@Repository
internal interface RefDataMappingTestOnlyRepository : JpaRepository<RefDataMapping, RefDataMappingKey>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These mappings is to feed testing data for the "Materialised View" in absence of Flyway (which create it via repeatable migration)

This repository is thus created only for JPA Repository tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing configuration for JPA Repository tests


@Repository
interface EmployerExternalIdRepository : JpaRepository<EmployerExternalId, ExternalIdKey> {
fun findByKeyId(id: String): EmployerExternalId?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

look up by internal ID

@Repository
interface EmployerExternalIdRepository : JpaRepository<EmployerExternalId, ExternalIdKey> {
fun findByKeyId(id: String): EmployerExternalId?
fun findByKeyExternalId(externalId: Long): EmployerExternalId?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

look up by external ID

import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.shared.domain.ReadOnlyRepository

@Entity
@Table(name = "ref_data_mappings")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually not a table but a materialised view (MV) with static data in DB

This restrict only known reference data.
Maintenance shall be done via Flyway's repeatable migration of this MV.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

helper (base) class to help injecting audit fields (timestamps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A read-only repository interface, is added for the static materialised view of Reference Data mappings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a repeatable migration of Flyway.
This is the maintenance point of reference data mappings with MN.

Unique indexes have been added to reinforce unique mapping either direction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Versioned migration of Flyway

This version is expected to hold all relevant DB changes until it was promoted to production/live DB.
Next change will be adding Job ID's mapping table

@rickchoijd rickchoijd merged commit 5168863 into main Jan 29, 2025
6 checks passed
@rickchoijd rickchoijd deleted the ESWE-1181-init-db-2 branch January 29, 2025 14:27
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