Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: index out of range [0] with length 0 #3363

Closed
intel352 opened this issue Feb 3, 2025 · 6 comments
Closed

panic: runtime error: index out of range [0] with length 0 #3363

intel352 opened this issue Feb 3, 2025 · 6 comments

Comments

@intel352
Copy link

intel352 commented Feb 3, 2025

I'm moving from golang-migrate to Atlas. I missed that Atlas doesn't also use .down files, so working with an existing migrations directory resulted in the .down being processed first, and then a runtime panic.
Knowing about this, hopefully you can detect/mitigate the error so that it can at least be helpful regarding the cause.

Contents of the atlas_schema_revisions table:

20250124201454,create_affiliate_table.down,2,1,1,2025-02-03 14:23:17.650914 +00:00,812417,"","",eBwwb9odmRgSXp04uafjCfoCupCSaCE8QL+dwqil4NE=,null,Atlas CLI v0.30.1-c0d486a-canary

Cmd panic

atlas migrate apply --env=local
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
ariga.io/atlas/sql/migrate.(*Executor).Execute(0x1400123ed90, {0x105be06d8, 0x1400103b650}, {0x105beacf8, 0x140011128d0})
        /Users/runner/work/atlas-enterprise/atlas-enterprise/sql/migrate/migrate.go:852 +0xec0
ariga.io/atlas/cmd/atlas/internal/cmdapi.migrateApplyRun(0x14000af9b08, {0x1400106c0e0?, 0x1076abfe0?, 0x14000ef9200?}, {{0x14000f05380, 0x54}, {0x14000076bb8, 0x11}, {0x0, 0x0}, ...}, ...)
        /Users/runner/work/atlas-enterprise/atlas-enterprise/cmd/atlas/internal/cmdapi/migrate.go:278 +0xa8c
ariga.io/atlas/cmd/atlas/internal/cmdapi.migrateApplyCmd.func1.2(0x14000e96b48)
        /Users/runner/work/atlas-enterprise/atlas-enterprise/cmd/atlas/internal/cmdapi/migrate.go:138 +0x124
ariga.io/atlas/cmd/atlas/internal/cmdapi.cmdEnvsRun({0x14000125d78, 0x1, 0x14001013090?}, 0x105bab2a0, 0x14000af9b08, 0x14000e77ba8)
        /Users/runner/work/atlas-enterprise/atlas-enterprise/cmd/atlas/internal/cmdapi/migrate.go:1750 +0x354
ariga.io/atlas/cmd/atlas/internal/cmdapi.migrateApplyCmd.func1(0x14000af9b08, {0x1400106c0e0, 0x0, 0x1})
        /Users/runner/work/atlas-enterprise/atlas-enterprise/cmd/atlas/internal/cmdapi/migrate.go:133 +0x228
ariga.io/atlas/cmd/atlas/internal/cmdapi.migrateApplyCmd.RunE.func3(0x14000af9b08, {0x1400106c0e0?, 0x4?, 0x104b1a5da?})
        /Users/runner/work/atlas-enterprise/atlas-enterprise/cmd/atlas/internal/cmdapi/cmdapi.go:138 +0x2c
github.com/spf13/cobra.(*Command).execute(0x14000af9b08, {0x1400106c0c0, 0x1, 0x1})
        /Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:983 +0x834
github.com/spf13/cobra.(*Command).ExecuteC(0x10758f6a0)
        /Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        /Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1032
main.main()
        /Users/runner/work/atlas-enterprise/atlas-enterprise/cmd/atlas/main.go:57 +0x158
@a8m
Copy link
Member

a8m commented Feb 3, 2025

Hey @intel352 👋

Did you set the migration.format to golang-migrate?

env "local" {
  ...
  migration {
    dir    = "file://migrations"
    format = golang-migrate
  }
}

@intel352
Copy link
Author

intel352 commented Feb 3, 2025

I did actually.

@a8m
Copy link
Member

a8m commented Feb 3, 2025

Can you share your atlas.hcl file?

@intel352
Copy link
Author

intel352 commented Feb 5, 2025

At the time, it looked like this:

variable "url" {
  type = string
  default = ""
}

env "local" {
  // Define the URL of the database which is managed
  // in this environment.
  url = "postgres://scrubbed"

  // Define the URL of the Dev Database for this environment
  // See: https://atlasgo.io/concepts/dev-database
  dev = "docker://postgres/16/dev?search_path=public"

  migration {
    // URL where the migration directory resides.
    dir = "file://migrations"
    format = "golang-migrate"
  }
}

@a8m
Copy link
Member

a8m commented Feb 5, 2025

Config looks OK, can you please provide a simple directory example that reproduces this issue?

@a8m
Copy link
Member

a8m commented Feb 14, 2025

Config looks OK, can you please provide a simple directory example that reproduces this issue?

I wasn't able to reproduce this. Feel free to reopen if you have any example that reproduces this.

Thanks

@a8m a8m closed this as completed Feb 14, 2025
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

No branches or pull requests

2 participants