Skip to content

dev/sg: do not load schemas immediately to prevent panics

Warren Gifford requested to merge fix-sg-migration-load into main

Created by: bobheadxi

Do not load database schemas immediately upon running sg, which causes sg to panic on all commands when run outside of the Sourcegraph repository directory.

I think this was introduced in https://github.com/sourcegraph/sourcegraph/pull/31086 , @caugustus-sourcegraph noticed this in https://github.com/sourcegraph/sourcegraph/pull/31141#issuecomment-1041896355

Test plan

Before

❯ go build -o .bin/sg ./dev/sg                                                                        
(cd .. && ./sourcegraph/.bin/sg version)                                                            
panic: sg migration command use the migrations defined on the local filesystem: not running inside sourcegraph/sourcegraph

goroutine 1 [running]:
main.mustResolveSchema({0x52e2def, 0x8})
        /Users/robertlin/Projects/sourcegraph/sourcegraph/dev/sg/sg_migration.go:124 +0x219
main.init()
        /Users/robertlin/Projects/sourcegraph/sourcegraph/dev/sg/sg_migration.go:115 +0x26b6

After

❯ go build -o .bin/sg ./dev/sg                       
(cd .. && ./sourcegraph/.bin/sg version)           
dev
(cd .. && ./sourcegraph/.bin/sg migration validate)
error: 3 errors occurred:
        * frontend: sg migration command uses the migrations defined on the local filesystem: not running inside sourcegraph/sourcegraph
        * codeintel: sg migration command uses the migrations defined on the local filesystem: not running inside sourcegraph/sourcegraph
        * codeinsights: sg migration command uses the migrations defined on the local filesystem: not running inside sourcegraph/sourcegraph

Merge request reports

Loading