github.com/gogriddy/goose@v0.0.0-20180817174216-2c751e0981c8/lib/goose/templates.go (about)

     1  // Code generated by go-bindata.
     2  // sources:
     3  // templates/migration-main.go.tmpl
     4  // templates/migration.go.tmpl
     5  // templates/migration.sql.tmpl
     6  // DO NOT EDIT!
     7  
     8  package goose
     9  
    10  import (
    11  	"fmt"
    12  	"io/ioutil"
    13  	"os"
    14  	"path/filepath"
    15  	"strings"
    16  	"time"
    17  )
    18  
    19  type asset struct {
    20  	bytes []byte
    21  	info  os.FileInfo
    22  }
    23  
    24  type bindataFileInfo struct {
    25  	name    string
    26  	size    int64
    27  	mode    os.FileMode
    28  	modTime time.Time
    29  }
    30  
    31  func (fi bindataFileInfo) Name() string {
    32  	return fi.name
    33  }
    34  func (fi bindataFileInfo) Size() int64 {
    35  	return fi.size
    36  }
    37  func (fi bindataFileInfo) Mode() os.FileMode {
    38  	return fi.mode
    39  }
    40  func (fi bindataFileInfo) ModTime() time.Time {
    41  	return fi.modTime
    42  }
    43  func (fi bindataFileInfo) IsDir() bool {
    44  	return false
    45  }
    46  func (fi bindataFileInfo) Sys() interface{} {
    47  	return nil
    48  }
    49  
    50  var _templatesMigrationMainGoTmpl = []byte(`package main
    51  
    52  import (
    53  	"log"
    54  	"bytes"
    55  	"encoding/gob"
    56  
    57  	_ "{{.Import}}"
    58  	"github.com/CloudCom/goose/lib/goose"
    59  )
    60  
    61  func main() {
    62  
    63  	var conf goose.DBConf
    64  	buf := bytes.NewBuffer({{ .Conf }})
    65  	if err := gob.NewDecoder(buf).Decode(&conf); err != nil {
    66  		log.Fatal("gob.Decode - ", err)
    67  	}
    68  
    69  	db, err := goose.OpenDBFromDBConf(&conf)
    70  	if err != nil {
    71  		log.Fatal("failed to open DB:", err)
    72  	}
    73  	defer db.Close()
    74  
    75  	txn, err := db.Begin()
    76  	if err != nil {
    77  		log.Fatal("db.Begin:", err)
    78  	}
    79  
    80  	{{ .Func }}(txn)
    81  
    82  	err = goose.FinalizeMigration(&conf, txn, {{ .Direction }}, {{ .Version }})
    83  	if err != nil {
    84  		log.Fatal("Commit() failed:", err)
    85  	}
    86  }
    87  {{/* vim: set ft=go.gotexttmpl: */}}
    88  `)
    89  
    90  func templatesMigrationMainGoTmplBytes() ([]byte, error) {
    91  	return _templatesMigrationMainGoTmpl, nil
    92  }
    93  
    94  func templatesMigrationMainGoTmpl() (*asset, error) {
    95  	bytes, err := templatesMigrationMainGoTmplBytes()
    96  	if err != nil {
    97  		return nil, err
    98  	}
    99  
   100  	info := bindataFileInfo{name: "templates/migration-main.go.tmpl", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
   101  	a := &asset{bytes: bytes, info: info}
   102  	return a, nil
   103  }
   104  
   105  var _templatesMigrationGoTmpl = []byte(`package main
   106  
   107  import (
   108  	"database/sql"
   109  )
   110  
   111  // Up is executed when this migration is applied
   112  func Up_{{ . }}(txn *sql.Tx) {
   113  
   114  }
   115  
   116  // Down is executed when this migration is rolled back
   117  func Down_{{ . }}(txn *sql.Tx) {
   118  
   119  }
   120  {{/* vim: set ft=go.gotexttmpl: */}}
   121  `)
   122  
   123  func templatesMigrationGoTmplBytes() ([]byte, error) {
   124  	return _templatesMigrationGoTmpl, nil
   125  }
   126  
   127  func templatesMigrationGoTmpl() (*asset, error) {
   128  	bytes, err := templatesMigrationGoTmplBytes()
   129  	if err != nil {
   130  		return nil, err
   131  	}
   132  
   133  	info := bindataFileInfo{name: "templates/migration.go.tmpl", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
   134  	a := &asset{bytes: bytes, info: info}
   135  	return a, nil
   136  }
   137  
   138  var _templatesMigrationSqlTmpl = []byte(`-- +goose Up
   139  -- SQL in section 'Up' is executed when this migration is applied
   140  
   141  
   142  -- +goose Down
   143  -- SQL section 'Down' is executed when this migration is rolled back
   144  
   145  
   146  `)
   147  
   148  func templatesMigrationSqlTmplBytes() ([]byte, error) {
   149  	return _templatesMigrationSqlTmpl, nil
   150  }
   151  
   152  func templatesMigrationSqlTmpl() (*asset, error) {
   153  	bytes, err := templatesMigrationSqlTmplBytes()
   154  	if err != nil {
   155  		return nil, err
   156  	}
   157  
   158  	info := bindataFileInfo{name: "templates/migration.sql.tmpl", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
   159  	a := &asset{bytes: bytes, info: info}
   160  	return a, nil
   161  }
   162  
   163  // Asset loads and returns the asset for the given name.
   164  // It returns an error if the asset could not be found or
   165  // could not be loaded.
   166  func Asset(name string) ([]byte, error) {
   167  	cannonicalName := strings.Replace(name, "\\", "/", -1)
   168  	if f, ok := _bindata[cannonicalName]; ok {
   169  		a, err := f()
   170  		if err != nil {
   171  			return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
   172  		}
   173  		return a.bytes, nil
   174  	}
   175  	return nil, fmt.Errorf("Asset %s not found", name)
   176  }
   177  
   178  // MustAsset is like Asset but panics when Asset would return an error.
   179  // It simplifies safe initialization of global variables.
   180  func MustAsset(name string) []byte {
   181  	a, err := Asset(name)
   182  	if err != nil {
   183  		panic("asset: Asset(" + name + "): " + err.Error())
   184  	}
   185  
   186  	return a
   187  }
   188  
   189  // AssetInfo loads and returns the asset info for the given name.
   190  // It returns an error if the asset could not be found or
   191  // could not be loaded.
   192  func AssetInfo(name string) (os.FileInfo, error) {
   193  	cannonicalName := strings.Replace(name, "\\", "/", -1)
   194  	if f, ok := _bindata[cannonicalName]; ok {
   195  		a, err := f()
   196  		if err != nil {
   197  			return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
   198  		}
   199  		return a.info, nil
   200  	}
   201  	return nil, fmt.Errorf("AssetInfo %s not found", name)
   202  }
   203  
   204  // AssetNames returns the names of the assets.
   205  func AssetNames() []string {
   206  	names := make([]string, 0, len(_bindata))
   207  	for name := range _bindata {
   208  		names = append(names, name)
   209  	}
   210  	return names
   211  }
   212  
   213  // _bindata is a table, holding each asset generator, mapped to its name.
   214  var _bindata = map[string]func() (*asset, error){
   215  	"templates/migration-main.go.tmpl": templatesMigrationMainGoTmpl,
   216  	"templates/migration.go.tmpl":      templatesMigrationGoTmpl,
   217  	"templates/migration.sql.tmpl":     templatesMigrationSqlTmpl,
   218  }
   219  
   220  // AssetDir returns the file names below a certain
   221  // directory embedded in the file by go-bindata.
   222  // For example if you run go-bindata on data/... and data contains the
   223  // following hierarchy:
   224  //     data/
   225  //       foo.txt
   226  //       img/
   227  //         a.png
   228  //         b.png
   229  // then AssetDir("data") would return []string{"foo.txt", "img"}
   230  // AssetDir("data/img") would return []string{"a.png", "b.png"}
   231  // AssetDir("foo.txt") and AssetDir("notexist") would return an error
   232  // AssetDir("") will return []string{"data"}.
   233  func AssetDir(name string) ([]string, error) {
   234  	node := _bintree
   235  	if len(name) != 0 {
   236  		cannonicalName := strings.Replace(name, "\\", "/", -1)
   237  		pathList := strings.Split(cannonicalName, "/")
   238  		for _, p := range pathList {
   239  			node = node.Children[p]
   240  			if node == nil {
   241  				return nil, fmt.Errorf("Asset %s not found", name)
   242  			}
   243  		}
   244  	}
   245  	if node.Func != nil {
   246  		return nil, fmt.Errorf("Asset %s not found", name)
   247  	}
   248  	rv := make([]string, 0, len(node.Children))
   249  	for childName := range node.Children {
   250  		rv = append(rv, childName)
   251  	}
   252  	return rv, nil
   253  }
   254  
   255  type bintree struct {
   256  	Func     func() (*asset, error)
   257  	Children map[string]*bintree
   258  }
   259  
   260  var _bintree = &bintree{nil, map[string]*bintree{
   261  	"templates": &bintree{nil, map[string]*bintree{
   262  		"migration-main.go.tmpl": &bintree{templatesMigrationMainGoTmpl, map[string]*bintree{}},
   263  		"migration.go.tmpl":      &bintree{templatesMigrationGoTmpl, map[string]*bintree{}},
   264  		"migration.sql.tmpl":     &bintree{templatesMigrationSqlTmpl, map[string]*bintree{}},
   265  	}},
   266  }}
   267  
   268  // RestoreAsset restores an asset under the given directory
   269  func RestoreAsset(dir, name string) error {
   270  	data, err := Asset(name)
   271  	if err != nil {
   272  		return err
   273  	}
   274  	info, err := AssetInfo(name)
   275  	if err != nil {
   276  		return err
   277  	}
   278  	err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
   279  	if err != nil {
   280  		return err
   281  	}
   282  	err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
   283  	if err != nil {
   284  		return err
   285  	}
   286  	err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
   287  	if err != nil {
   288  		return err
   289  	}
   290  	return nil
   291  }
   292  
   293  // RestoreAssets restores an asset under the given directory recursively
   294  func RestoreAssets(dir, name string) error {
   295  	children, err := AssetDir(name)
   296  	// File
   297  	if err != nil {
   298  		return RestoreAsset(dir, name)
   299  	}
   300  	// Dir
   301  	for _, child := range children {
   302  		err = RestoreAssets(dir, filepath.Join(name, child))
   303  		if err != nil {
   304  			return err
   305  		}
   306  	}
   307  	return nil
   308  }
   309  
   310  func _filePath(dir, name string) string {
   311  	cannonicalName := strings.Replace(name, "\\", "/", -1)
   312  	return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
   313  }