Skip to content

Migration builder: table-level indexes, column modifiers, drop/rename/change, and fixes - #345

Merged
techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:techmahedy-4.x
Oct 2, 2026
Merged

techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:techmahedy-4.x

Conversation

@techmahedy

@techmahedy techmahedy commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Pull Request Checklist

Q A
Branch? 4.x
Bug fix? yes
New feature? Yes
Deprecations? no
Issues -
License MIT

Description

Summary

Brings the Doppar migration builder (Phaseolies\Database\Migration) to feature parity with the other major PHP frameworks, and fixes several bugs found along the way.

$table->string('title')->index() already worked; what was missing was table-level $table->index() (and everything around it).

Bug fixes

  • SQLite silently dropped indexes. Schema::create() sent all statements in one prepare() call and SQLite runs only the first, so column ->index() / ->unique() indexes were never created. Schema now executes statements one by one via the new Blueprint::toStatements() (toSql() still works and joins them).
  • Duplicate PRIMARY KEY on MySQL/PostgreSQL when ->primary() was used on a non-id column.
  • String defaults were escaped with addslashes(), which is invalid on PostgreSQL/SQLite. Now escaped per driver.
  • Foreign keys on SQLite are emitted inline in CREATE TABLE (SQLite cannot ALTER TABLE ADD CONSTRAINT).
  • A blueprint containing only drop/rename/index commands no longer throws "No columns defined".

New features

  • Indexes: index, unique, primary, fullText, spatialIndex at table level (composite, custom name, ->algorithm()); column-level ->index('name'), ->unique('name'), ->fullText(), ->spatialIndex().
  • Drops/renames: dropColumn, renameColumn, dropIndex, dropUnique, dropFullText, dropSpatialIndex, dropPrimary, dropForeign, renameIndex, dropTimestamps, dropSoftDeletes, dropRememberToken, dropMorphs, dropConstrainedForeignId.
  • ->change() to modify existing columns (MySQL MODIFY COLUMN, PostgreSQL ALTER COLUMN; SQLite throws a clear error).
  • Column modifiers: comment, unsigned, useCurrent, useCurrentOnUpdate, autoIncrement, charset, collation, storedAs/virtualAs, invisible, first, nullable(false).
  • Foreign keys: foreignId()->constrained() (table guessed from column name), foreignUuid, foreignUlid, composite keys, ->name(), noActionOnDelete/Update.
  • Types/helpers: increments family, ulid, rememberToken, morphs / nullableMorphs / uuidMorphs / ulidMorphs, softDeletesTz, nullableTimestamps, precision argument on temporal columns.
  • Table options: engine, charset, collation, comment, temporary.
  • Schema: drop, rename, dropColumns, renameColumn, hasColumn, hasColumns, getColumnListing, hasIndex (facade docblock updated).
  • Charset/collation/algorithm values are validated to prevent SQL injection through schema definitions.

Behaviour notes / compatibility

  • Default index names are unchanged for single columns (idx_{table}_{col}, {table}_{col}_unique), so existing down() migrations keep working. Names over 63 chars are shortened with a hash.
  • Blueprint::softDeletes() now returns the ColumnDefinition instead of void (accepts an optional column name).
  • Grammar::compileCreateIndex() / compileCreateUnique() gained an optional $name parameter. Custom grammar subclasses must add it.
  • PostgreSQL Database::execute() still splits on ;, so a comment containing ; would break there (pre-existing, untouched).

Docs

docs/content/docs/versions/4.x/migrations.md (docs repo) updated with all of the above. The outdated warning about needing after() when adding several columns was removed.

Checklist

  • Tests have been added or updated
  • Documentation has been updated if necessary
  • Code follows the project coding standards
  • All tests pass locally

@techmahedy
techmahedy merged commit 02281a1 into doppar:4.x Oct 2, 2026
16 checks passed
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