Welcome to mirror list, hosted at ThFree Co, Russian Federation.

new-migration « _support - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f08eec2a53f474ca50612e1523ea2e445d43417c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
require 'erb'

PROGNAME = File.basename(__FILE__)
MIGRATIONS_DIR = 'internal/praefect/datastore/migrations'

def main(migration_name)
  unless /\A[a-z0-9_]+\z/ =~ migration_name
    abort "invalid migration name #{migration_name.inspect} (only a-z0-9_ are allowed)"
  end

  sequence_number = Time.now.utc.strftime('%Y%m%d%H%M%S')
 
  migration_file =  File.join(MIGRATIONS_DIR, "#{sequence_number}_#{migration_name}.go")
  warn "#{PROGNAME}: creating #{migration_file}"
  IO.write(migration_file, ERB.new(DATA.read).result(binding))
end

unless ARGV.count == 1
  abort "usage: #{PROGNAME} MIGRATION_NAME"
end

main(*ARGV)

__END__
package migrations

import migrate "github.com/rubenv/sql-migrate"

func init() {
	m := &migrate.Migration{
		Id:   "<%= sequence_number %>_<%= migration_name %>",
		Up:   []string{},
		Down: []string{},
	}

	allMigrations = append(allMigrations, m)
}