Skip to content

Conversation

@xHeaven
Copy link
Contributor

@xHeaven xHeaven commented Jan 27, 2026

This PR makes the filename prefix configurable for raw migrations.
Keeps the original Y-m-d prefix and adds a new Uuidv7 prefix. (time-sortable)
The usecase: no collision/confusion/rename need when creating multiple migrations the same day.

@innocenzi
Copy link
Member

I love this. What if the interface accepted the filename so the user could have further control over the final name?

@xHeaven
Copy link
Contributor Author

xHeaven commented Jan 27, 2026

I love this. What if the interface accepted the filename so the user could have further control over the final name?

Only the filename, or a separate property?

@innocenzi
Copy link
Member

I meant this:

interface MigrationNamingStrategy
{
    public function getName(string $filename): string;
}

Not sure if the extension should be given too?

@xHeaven
Copy link
Contributor Author

xHeaven commented Jan 27, 2026

I meant this:

interface MigrationNamingStrategy
{
    public function getName(string $filename): string;
}

Makes sense, I can definitely adapt to this. However, object and up name gets generated entirely differently that raw, do you want to streamline them or we want to handle them separately?

Not sure if the extension should be given too?

I don't think so, raw migrations are .sql, object and up migrations are .php since they are class-based, not sure what benefit would it give us to change this.

What are your thoughts?

@innocenzi
Copy link
Member

innocenzi commented Jan 27, 2026

Makes sense, I can definitely adapt to this. However, object and up name gets generated entirely differently that raw, do you want to streamline them or we want to handle them separately?

Ah, good point! I'd say we only use the naming strategy for raw migrations because class ones should follow PSR-4. That would also solve the extension question.

@innocenzi innocenzi merged commit e957640 into tempestphp:3.x Jan 29, 2026
74 checks passed
@xHeaven xHeaven deleted the migrations-tweak branch January 29, 2026 12:28
@aidan-casey
Copy link
Member

Nice, @xHeaven! I really like this PR also. Given this is merged to 3.x, any reason we cannot a) default to UUIDv7 and b) add a timestamp to the date?

CC: @innocenzi

@xHeaven
Copy link
Contributor Author

xHeaven commented Jan 29, 2026

Nice, @xHeaven! I really like this PR also. Given this is merged to 3.x, any reason we cannot a) default to UUIDv7 and b) add a timestamp to the date?

CC: @innocenzi

There is no reason. I was unsure whether I wanted to change Tempest's default behavior, as people tend to have some weird UX fetish towards date'd migrations, for "scannability" reasons. We can definitely default to UUIDv7, in fact, it's a safer default in terms of collisions.

Regarding the timestamp to date, we could either rename the DatePrefixStrategy to DatetimePrefixStrategy and include this, or create a new strategy that includes the H:i:s format. We could also add a TimestampPrefixStrategy that is just a Unix timestamp.

@innocenzi
Copy link
Member

Personally I wouldn't want UUIDs by default, it's not exactly nice to "scan" when looking at the file tree. It's quite long and I'm more interested in seeing the rest of the name :)

@innocenzi
Copy link
Member

A Unix timestamp strategy would be good though!

@xHeaven
Copy link
Contributor Author

xHeaven commented Jan 29, 2026

Personally I wouldn't want UUIDs by default, it's not exactly nice to "scan" when looking at the file tree. It's quite long and I'm more interested in seeing the rest of the name :)

See @aidan-casey, there goes the scanning fetish I was talking about! :D

@aidan-casey
Copy link
Member

Sadness. I like the lack of collision while maintaining sorting by time. It'd be nice if you could generate multiple migrations at a time and have them all sorted by order.

Either way, I think we should include a sensible default, which should at least not collide when created on the same day by default.

@innocenzi
Copy link
Member

That's still possible without cluttering file names with UUIDs! We could do a file_exists check before writing the file, and increment an id. I'd be fine with shorter IDs instead of UUIDs by default too, but come on, UUIDs are very long.

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