Skip to content

fix: align database schema with model definitions - #107

Merged
danielhe4rt merged 10 commits into
3.xfrom
fix/resolver-files
Nov 18, 2025
Merged

fix: align database schema with model definitions#107
danielhe4rt merged 10 commits into
3.xfrom
fix/resolver-files

Conversation

@gvieira18

@gvieira18 gvieira18 commented Nov 18, 2025

Copy link
Copy Markdown
Member

This pull request includes several improvements and fixes across configuration, database schema, and code quality. The main focus is on aligning environment files, correcting table names and relationships in models and migrations, and enhancing developer tooling and command usage.

Environment and Configuration Updates:

  • The file .env.pipeline isn't used anymore;
  • The fields on .env.example are also unused;
  • Included the last environment changes to .env.testing.example file.

Database and Model Corrections:

  • Added a migration for the characters_wallet table with correct schema, ensuring proper relationships and naming conventions;
  • Updated the Wallet model and factory to use the correct table name characters_wallet and improved factory typing and usage of HasFactory;
  • Fixed table names in pivot models: EventAttend now uses events_attendees and SponsorAttend uses events_sponsors for consistency with database naming conventions;
  • Changed the user_id column in the sessions table migration to use a UUID foreign key.

Developer Tooling and Command Improvements:

  • Updated the route-list cmd in both Makefile and Taskfile.yml to ignore vendor routes;
  • Fixed the ide-helper composer script to include models from both app-modules/*/src/Models and app/Models, improving IDE support for the codebase.

Summary by CodeRabbit

  • Chores

    • Removed default/pipeline environment definitions and cleaned example env of test DB credentials; added OAuth/testing keys and consolidated OAuth settings.
    • Updated tooling to exclude vendor routes and to generate IDE helpers for multiple model directories.
  • Database

    • Added wallet infrastructure and standardized wallet/events/sponsor pivot table names.
    • Updated sessions user reference to use UUID and fixed migration reversal to match table naming.

@gvieira18 gvieira18 self-assigned this Nov 18, 2025
@coderabbitai

coderabbitai Bot commented Nov 18, 2025

Copy link
Copy Markdown

Walkthrough

Removes test DB credentials and pipeline environment defaults, adds Discord/Twitch OAuth env keys for testing, adjusts route-list commands to exclude vendor routes, updates Wallet model/factory and related migrations, and renames several pivot table mappings and a sessions column type.

Changes

Cohort / File(s) Change Summary
Environment examples & pipeline
\.env.example, \.env.pipeline, \.env.testing.example
Removed three DB_TEST_* entries from .env.example; deleted all contents of .env.pipeline; added Discord and Twitch OAuth env variables to .env.testing.example.
Build & task commands
Makefile, Taskfile.yml
Added --except-vendor to php artisan route:list invocations to exclude vendor routes (php artisan route:list --except-vendor --ansi).
Wallet model & factory
app-modules/character/src/Models/Wallet.php, app-modules/character/database/factories/WalletFactory.php
Wallet model now uses HasFactory and maps table to characters_wallet; factory PHPDoc generic changed from Factory<Model> to Factory<Wallet> and unused import removed.
New wallet migration
app-modules/character/database/migrations/..._create_character_wallet_table.php
Added migration creating characters_wallet with id, balance (int, default 0), character_id (UUID FK → characters, cascade on delete), and timestamps; migration provides up() only.
Sessions migration change
app-modules/season/database/migrations/..._create_sessions_table.php
Changed user_id column from foreignId('user_id') to foreignUuid('user_id') (retained nullable and index).
Pivot model table mappings
app-modules/events/src/Models/Pivot/EventAttend.php, app-modules/sponsors/src/Models/Pivot/SponsorAttend.php
Renamed pivot tables: EventAttend::$tableevents_attendees; SponsorAttend::$tableevents_sponsors.
Composer scripts
composer.json
ide-helper:models script updated to include --dir='app-modules/*/src/Models' and --dir='app/Models' when generating model helpers.
Sponsors migration fix
app-modules/sponsors/database/migrations/..._create_events_sponsors_table.php
Fixed down() to drop events_sponsors (plural) to match up().

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer
  participant Migrate as Migration runner
  participant DB as Database
  note right of Dev `#DDFFDD`: New migration + model change
  Dev->>Migrate: php artisan migrate
  Migrate->>DB: CREATE TABLE characters_wallet (id, balance, character_id UUID FK -> characters, timestamps)
  DB-->>Migrate: OK
  Migrate-->>Dev: Migration completed
  note right of Dev `#FFF0CC`: Wallet model has HasFactory for test data generation
  Dev->>Dev: Wallet::factory()->create(...)
  Dev->>DB: INSERT INTO characters_wallet ...
  DB-->>Dev: OK
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas to review closely:
    • Migration sequence and presence/ordering of the new characters_wallet migration relative to existing migrations.
    • Consistency of table name changes (characters_wallet, events_attendees, events_sponsors) across relationships, seeders, and queries.
    • The foreignUuid change for sessions.user_id and compatibility with existing user primary key types and foreign keys.
    • Removal of .env.pipeline contents — verify CI/CD pipelines or deployment scripts don't rely on it.
    • Verify factory annotation change does not affect code generation tools and that HasFactory usage matches project conventions.

Poem

🐰 I hopped through migrations, tidy and bright,
I nudged env secrets out of sight,
Factories planted, wallets take root,
Vendor routes hidden — neat and astute,
A carrot-sized cheer for changes done right. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main objective of the pull request: aligning database schema with model definitions, which is the core theme across all changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/resolver-files

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 421e344 and ac0fb3c.

📒 Files selected for processing (1)
  • app-modules/sponsors/database/migrations/2025_11_05_193141_create_events_sponsors_table.php (1 hunks)
🔇 Additional comments (1)
app-modules/sponsors/database/migrations/2025_11_05_193141_create_events_sponsors_table.php (1)

29-29: Rollback fix: down() now matches the table created in up()

Updating dropIfExists to events_sponsors correctly aligns the rollback with the table created in up(), preventing failed or no-op rollbacks for this pivot table. Looks good.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
app-modules/season/database/migrations/2025_10_30_072203_create_sessions_table.php (1)

9-24: Consider adding a down() method for rollback capability.

The migration lacks a down() method, which prevents rolling back this migration if needed during development or deployment issues.

Add the following method to enable rollback:

public function down(): void
{
    Schema::dropIfExists('sessions');
}
.env.testing.example (1)

68-76: Consider alphabetizing OAuth environment variables.

The static analysis tool suggests reordering these variables alphabetically within their respective groups (Discord and Twitch) for consistency. While this doesn't affect functionality, it improves maintainability.

Apply this reordering:

-DISCORD_OAUTH_CLIENT_ID=
-DISCORD_OAUTH_CLIENT_SECRET=
-DISCORD_OAUTH_SCOPES=
-DISCORD_OAUTH_REDIRECT_URI=
+DISCORD_OAUTH_CLIENT_ID=
+DISCORD_OAUTH_CLIENT_SECRET=
+DISCORD_OAUTH_REDIRECT_URI=
+DISCORD_OAUTH_SCOPES=

-TWITCH_OAUTH_SCOPES=
-TWITCH_OAUTH_CLIENT_ID=
-TWITCH_OAUTH_CLIENT_SECRET=
-TWITCH_OAUTH_REDIRECT_URI=
+TWITCH_OAUTH_CLIENT_ID=
+TWITCH_OAUTH_CLIENT_SECRET=
+TWITCH_OAUTH_REDIRECT_URI=
+TWITCH_OAUTH_SCOPES=
app-modules/character/database/migrations/2025_11_18_100010_create_character_wallet_table.php (1)

9-20: Consider adding a down() method for rollback capability.

The migration lacks a down() method, preventing rollback during development or in case of deployment issues.

Add the following method:

public function down(): void
{
    Schema::dropIfExists('characters_wallet');
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ced24bf and 421e344.

📒 Files selected for processing (12)
  • .env.example (0 hunks)
  • .env.pipeline (0 hunks)
  • .env.testing.example (1 hunks)
  • Makefile (1 hunks)
  • Taskfile.yml (1 hunks)
  • app-modules/character/database/factories/WalletFactory.php (1 hunks)
  • app-modules/character/database/migrations/2025_11_18_100010_create_character_wallet_table.php (1 hunks)
  • app-modules/character/src/Models/Wallet.php (2 hunks)
  • app-modules/events/src/Models/Pivot/EventAttend.php (1 hunks)
  • app-modules/season/database/migrations/2025_10_30_072203_create_sessions_table.php (1 hunks)
  • app-modules/sponsors/src/Models/Pivot/SponsorAttend.php (1 hunks)
  • composer.json (1 hunks)
💤 Files with no reviewable changes (2)
  • .env.example
  • .env.pipeline
🧰 Additional context used
🧬 Code graph analysis (1)
app-modules/character/src/Models/Wallet.php (2)
app-modules/character/src/Models/Character.php (1)
  • Character (27-119)
app-modules/character/database/factories/WalletFactory.php (1)
  • WalletFactory (14-30)
🪛 dotenv-linter (4.0.0)
.env.testing.example

[warning] 71-71: [UnorderedKey] The DISCORD_OAUTH_REDIRECT_URI key should go before the DISCORD_OAUTH_SCOPES key

(UnorderedKey)


[warning] 74-74: [UnorderedKey] The TWITCH_OAUTH_CLIENT_ID key should go before the TWITCH_OAUTH_SCOPES key

(UnorderedKey)


[warning] 75-75: [UnorderedKey] The TWITCH_OAUTH_CLIENT_SECRET key should go before the TWITCH_OAUTH_SCOPES key

(UnorderedKey)


[warning] 76-76: [UnorderedKey] The TWITCH_OAUTH_REDIRECT_URI key should go before the TWITCH_OAUTH_SCOPES key

(UnorderedKey)

🔇 Additional comments (9)
app-modules/character/database/factories/WalletFactory.php (1)

12-12: Excellent type-safety improvement!

Updating the PHPDoc annotation from Factory<Model> to Factory<Wallet> provides better IDE support and type checking.

composer.json (1)

97-97: Good improvement for modular architecture!

Extending the ide-helper:models command to cover both app-modules/*/src/Models and app/Models ensures IDE support for models across the entire modular codebase structure.

app-modules/character/src/Models/Wallet.php (2)

7-20: Excellent factory integration with proper type annotations!

The addition of HasFactory trait with the typed docblock /** @use HasFactory<WalletFactory> */ provides excellent IDE support and type safety for factory operations.


21-21: Table name change aligns with the new migration.

The table name change from character_wallet to characters_wallet is consistent with the new migration file 2025_11_18_100010_create_character_wallet_table.php and follows Laravel's pluralization conventions.

app-modules/season/database/migrations/2025_10_30_072203_create_sessions_table.php (1)

18-18: No issues found — the change is correct.

The users table correctly uses UUID primary keys ($table->uuid('id')->primary()), confirming that the foreignUuid('user_id') foreign key in the sessions table is properly typed and will not cause constraint failures.

app-modules/character/database/migrations/2025_11_18_100010_create_character_wallet_table.php (1)

16-16: No issues found—characters table uses UUID primary keys.

The characters table migration confirms UUID primary key usage at line 18 ($table->uuid('id')->primary()), making the foreignUuid('character_id') constraint in the new migration correct and consistent.

app-modules/events/src/Models/Pivot/EventAttend.php (1)

12-12: The review comment is based on incorrect assumptions.

No evidence exists of a table rename from event_attend to events_attendees. The codebase contains no references to event_attend anywhere, and the migration 2025_11_05_192756_create_events_attendees_table.php creates the events_attendees table from scratch. The model's $table property correctly matches the table name created by the migration. There is no mismatch and no missing migration.

Likely an incorrect or invalid review comment.

Makefile (1)

8-9: Excellent: route-list command now filters vendor routes.

Adding --except-vendor keeps the route listing focused on application routes, reducing noise from third-party packages. This aligns with the Taskfile.yml update and improves the developer experience.

Taskfile.yml (1)

17-20: Excellent: route-list task now filters vendor routes.

Adding --except-vendor keeps the route listing focused on application routes. This change mirrors the Makefile update, ensuring consistent behavior whether developers use make route-list or task route-list.

Comment thread app-modules/sponsors/src/Models/Pivot/SponsorAttend.php
@gvieira18 gvieira18 changed the title fix: resolving models with database fix: align database schema with model definitions Nov 18, 2025
@danielhe4rt
danielhe4rt merged commit fbac984 into 3.x Nov 18, 2025
10 of 11 checks passed
@danielhe4rt
danielhe4rt deleted the fix/resolver-files branch November 18, 2025 17:45
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.

3 participants