Skip to content

migration new can overwrite an existing file on a same-second name collision #7883

Backlog

Description

@jonxsong

I’d like to implement the fix. If this is suitable for external contribution, could you assign it to @jonxsong and add the open-for-contribution label after triage?

Affected area

Migrations

Supabase CLI version

3.5.0-beta.17

Operating system

Windows 11 x64, build 26200

Installation method

Official GitHub release binary (windows_amd64)

Command

'create table second_example (id bigint);' | supabase.exe migration new add_example

Actual output

The command exits 0 and reports Migration created for a file that already existed. In my run the file was 20261130222349_add_example.sql. Its contents changed from create table first_example (id bigint); to create table second_example (id bigint);.

I also reproduced the collision by running two same-name invocations with different SQL over stdin in the same UTC second. Both returned success and reported the same file, which contained only the second invocation’s SQL.

Expected behavior

migration new should preserve the existing file when a generated path collides. It can report the collision or create a migration under a fresh version.

Steps to reproduce

Run this in PowerShell with the CLI on PATH. It creates a disposable project and pre-creates files for a short window around the current UTC second so the collision is reproducible without racing two processes.

$scratch = Join-Path ([System.IO.Path]::GetTempPath()) ('migration-collision-' + [Guid]::NewGuid())
$migrations = Join-Path $scratch 'supabase/migrations'
New-Item -ItemType Directory -Path $migrations -Force | Out-Null
'project_id = "migration-collision-probe"' | Set-Content -LiteralPath (Join-Path $scratch 'supabase/config.toml')

$now = [DateTime]::UtcNow
foreach ($offset in -2..12) {
  $timestamp = $now.AddSeconds($offset).ToString('yyyyMMddHHmmss')
  $file = Join-Path $migrations ($timestamp + '_add_example.sql')
  Set-Content -LiteralPath $file -Value 'create table first_example (id bigint);'
}

Push-Location -LiteralPath $scratch
try {
  'create table second_example (id bigint);' | supabase.exe migration new add_example
  "Exit code: $LASTEXITCODE"
  Get-ChildItem -LiteralPath $migrations -File |
    Select-String -SimpleMatch 'create table second_example (id bigint);'
} finally {
  Pop-Location
}

Additional context

Reproduced during AI-assisted triage in temporary directories. The command generates a seconds-resolution UTC version and writes an empty byte array to the destination before opening it in append mode for stdin. The initial write truncates an existing destination. The same handler is present on current develop. Version and path derivation · File creation and stdin copy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions