Skip to content

refactor(migrations): use explicit column name for activity FK#126

Merged
cjmellor merged 1 commit into
mainfrom
chore/normalize-foreign-id-style
May 16, 2026
Merged

refactor(migrations): use explicit column name for activity FK#126
cjmellor merged 1 commit into
mainfrom
chore/normalize-foreign-id-style

Conversation

@cjmellor
Copy link
Copy Markdown
Owner

@cjmellor cjmellor commented May 16, 2026

Summary

Normalises the activity foreign key in the create_streak_histories_table stub to match the package's established foreignId('column_name') convention used by every other FK declaration across the 20 migration stubs.

Changes:

  • $table->foreignIdFor(Activity::class)$table->foreignId('activity_id')
  • Removes the now-unused use LevelUp\Experience\Models\Activity; import

Why

This was the only FK declaration in the package's migration stubs using foreignIdFor(Model::class) — the other 14 all use the explicit-column form. Standardising on a single style makes the stubs easier to read and audit.

Backward compatibility

Schema is byte-identical for both new and existing installs:

  • foreignIdFor(Activity::class) derives the column name as Str::snake(class_basename(Activity::class)) . '_id'activity_id
  • Activity does not override getForeignKey()
  • Both produce the same unsignedBigInteger column with the same name and same chained constraint

Existing installs already ran this migration; their streak_histories.activity_id column exists unchanged and Laravel will not re-run it. Fresh installs after this lands produce the same schema as fresh installs today.

Replaces `foreignIdFor(Activity::class)` with `foreignId('activity_id')`
in the streak_histories stub to match the package's established convention
(14 other FK declarations all use the explicit-column form). Schema is
byte-identical for both new and existing installs — `foreignIdFor` derives
the same `activity_id` column name from the model basename. Also removes
the now-unused `Activity` import.
@cjmellor cjmellor self-assigned this May 16, 2026
@cjmellor cjmellor merged commit 8db78c7 into main May 16, 2026
9 checks passed
@cjmellor cjmellor deleted the chore/normalize-foreign-id-style branch May 16, 2026 20:58
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.

1 participant