Skip to content

Make country native field required with name fallback. - #67

Closed
victore13 wants to merge 2 commits into
mainfrom
feature/country-native-required
Closed

Make country native field required with name fallback.#67
victore13 wants to merge 2 commits into
mainfrom
feature/country-native-required

Conversation

@victore13

Copy link
Copy Markdown
Collaborator

The native field on countries is now required instead of nullable. If the source JSON doesn't provide a value for native, the name field is automatically used as a fallback.

Changes

  • Migration: native is no longer nullable()
  • Country model: fromJsonToDBRecord() uses $jsonItem['native'] ?? $jsonItem['name']
  • PHPDoc: Type updated from string|null to string
  • Tests: Added required native field in translations test

Rationale

Ensures all countries always have a native name available, simplifying data consumption without needing to handle null values.

If native is not provided in JSON data, it falls back to the country name.

Changelog: changed
@victore13 victore13 self-assigned this Mar 3, 2026
@victore13
victore13 requested a review from soymgomez March 3, 2026 12:09
The previous change made `native` NOT NULL by editing the create-table
migration, which only affects fresh installs — production databases that
already ran it kept the column nullable, so the constraint was never
applied where it mattered.

- Add a dedicated ALTER migration (0000_03_07_190513) that backfills
  existing null natives from `name` (mirroring the seeder's `native ??
  name` fallback) and then enforces NOT NULL. Guarded for idempotency, so
  it is a safe no-op on fresh installs and reversible via down().
- Fix the single source-data gap: Cote D'Ivoire (CI) had native = null in
  countries.json; set it to "Côte d'Ivoire" so the seeded data is correct
  at source, not only via the runtime fallback.
- Add a schema test asserting `native` is non-nullable after migration.

No primary keys or existing rows are altered; the migration only touches
the `native` column definition and null values.

Changelog: changed
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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