feat(user): configurable foreign key type (bigint/uuid/ulid)#124
Merged
Conversation
pull Bot
pushed a commit
to KornaLaravel/laravel-level-up
that referenced
this pull request
May 16, 2026
Move the package migration loop out of getEnvironmentSetUp (which fires during config bootstrap, before RegisterProviders/BootProviders) into Testbench's defineDatabaseMigrations() hook, which runs after providers have booted. getEnvironmentSetUp now only handles config plus the host users table schema. This lets the service provider's boot() register Blueprint macros (and anything else container-bound) before any package migration runs — a prerequisite for the configurable entity-id-type work (PR cjmellor#125) and for retrofitting the configurable user-key-type macro (PR cjmellor#124).
42b148f to
b47b0ac
Compare
Add `level-up.user.foreign_key_type` (default `bigint`) so host apps whose User model uses HasUuids or HasUlids can install the package without manually editing every user-FK column. Migrations now route through `LevelUp\Experience\Support\UserForeignKey::on()` which picks `foreignId`/`foreignUuid`/`foreignUlid` from the config. Existing installs see no change. Affected migrations: experiences, streaks, achievement_user, challenge_user, experience_audits, streak_histories. Adds UuidUser/UlidUser fixtures and end-to-end flow tests for both key types covering experience, streak and challenge flows.
b47b0ac to
a534963
Compare
pull Bot
pushed a commit
to KornaLaravel/laravel-level-up
that referenced
this pull request
May 17, 2026
Proof-of-shape for the (b) half of UUID/ULID support: lets host apps choose the primary-key column type for the package's own entities so package IDs can be exposed as UUIDs/ULIDs on a public API surface (christoph-kluge's ask on PR cjmellor#124). Wires: - `level-up.entities.id_type` config (default `bigint`, accepts `uuid`/`ulid`) - `Blueprint::entityId()` / `Blueprint::entityForeignId()` macros registered in `LevelUpServiceProvider::bootingPackage()`. Now safe in tests after PR cjmellor#125 moved package migrations to run after providers boot. - `Concerns\HasConfigurableIds` trait — composes Laravel's `HasUniqueIds`, reads config at runtime, no-ops in bigint mode. - Applied to the `Experience` model + `create_experiences_table` stub as the shape proof; remaining 12 models + migrations follow next. BC: with default config, the trait's `uniqueIds()` returns `[]` so `HasUniqueIds`' creating-hook no-ops, `getKeyType()` returns `int`, and `getIncrementing()` returns `true` — byte-identical to today. Existing installs see no change.
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
Adds
level-up.user.foreign_key_typeso host apps whoseUsermodel usesHasUuidsorHasUlidscan install the package without hand-editing every user-FK column.level-up.user.foreign_key_type(default'bigint', accepts'uuid'or'ulid')LevelUp\Experience\Support\UserForeignKey::on($table)that returns the right column type and is callable from migrationsexperiences,streaks,achievement_user,challenge_user,experience_audits,streak_historiesMigration
This is opt-in and backwards-compatible. The default
'bigint'keeps the currentforeignId(...)behaviour, so existing installs see no change at all. Only setforeign_key_typeto'uuid'/'ulid'on a fresh install where the hostUserPK matches.Out of scope (known limitations)
experiences.id,levels.id) staybigint. The pain point this PR addresses is the user-FK boundary; internal PKs only matter to package code which already treats keys polymorphically through Eloquent.multiplier_scopes.scopeable_idis stillunsignedBigInteger, so scoping a Multiplier directly to a UUID/ULID user viamorphedByManywon't match. Tier scopes are unaffected. Tracked as a follow-up.