Skip to content

dev/sg: generate named migrations and revert named migrations

Created by: bobheadxi

Implements the 2nd and 3rd steps of https://github.com/sourcegraph/sourcegraph/issues/37244:

  • modify makeMigrationFilenames in makeMigrationFilenames to take a name as well as an index. Sanitize (s/ /_/g et al) the name and add it to the end of the created filenames
  • (a little less trivial) ensure the call to makeMigrationFilenames in the sg migration revert command receives the correct name so it can actually revert the correct filenames to modify

Test plan

➜ go run ./dev/sg migration add --db codeintel 'do the thing!'
Migration files created
 Up query file: migrations/codeintel/1655353366_do_the_thing/up.sql
 Down query file: migrations/codeintel/1655353366_do_the_thing/down.sql
 Metadata file: migrations/codeintel/1655353366_do_the_thing/metadata.yaml
 
Checkout the development docs for migrations:  https://docs.sourcegraph.com/dev/background-information/sql/migrations
➜  git add .
➜  git ci "fake migration"
[06-14-dev/sg_generate_named_mgirations_and_revert_named_migrations 36ce124d9e] fake migration
 3 files changed, 14 insertions(+)
 create mode 100644 migrations/codeintel/1655353366_do_the_thing/down.sql
 create mode 100644 migrations/codeintel/1655353366_do_the_thing/metadata.yaml
 create mode 100644 migrations/codeintel/1655353366_do_the_thing/up.sql
➜  git hash                         
36ce124d9ee1b53e15fd5f6f50202a2c66807d60
➜  go run ./dev/sg migration revert 36ce124d9ee1b53e15fd5f6f50202a2c66807d60
Migration files redacted
 Up query file: /Users/[email protected]/Projects/sourcegraph/sourcegraph/migrations/codeintel/1655353366_do_the_thing/up.sql
 
Migration files created
 Up query file: migrations/codeintel/1655353400_revert_36ce124d9ee1b53e15fd5f6f50202a2c66807d60/up.sql
 Down query file: migrations/codeintel/1655353400_revert_36ce124d9ee1b53e15fd5f6f50202a2c66807d60/down.sql
 Metadata file: migrations/codeintel/1655353400_revert_36ce124d9ee1b53e15fd5f6f50202a2c66807d60/metadata.yaml
 
Checkout the development docs for migrations:  https://docs.sourcegraph.com/dev/background-information/sql/migrations

Merge request reports

Loading