feat: use go embed for sqlite migrations (#21653)
parent
5251c85412
commit
40c7d69415
|
@ -344,7 +344,7 @@ func (m *Launcher) run(ctx context.Context, opts *InfluxdOpts) (err error) {
|
|||
sqliteMigrator := sqlite.NewMigrator(m.sqlStore, m.log.With(zap.String("service", "sqlite migrations")))
|
||||
|
||||
// apply migrations to the sqlite metadata store
|
||||
if err := sqliteMigrator.Up(ctx, &sqliteMigrations.All{}); err != nil {
|
||||
if err := sqliteMigrator.Up(ctx, sqliteMigrations.All); err != nil {
|
||||
m.log.Error("Failed to apply sqlite migrations", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ func newTestService(t *testing.T) (*Service, func(t *testing.T)) {
|
|||
ctx := context.Background()
|
||||
|
||||
sqliteMigrator := sqlite.NewMigrator(store, zap.NewNop())
|
||||
err := sqliteMigrator.Up(ctx, &migrations.All{})
|
||||
err := sqliteMigrator.Up(ctx, migrations.All)
|
||||
require.NoError(t, err)
|
||||
|
||||
svc := NewService(zap.NewNop(), store)
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
//go:generate env GO111MODULE=on go run github.com/kevinburke/go-bindata/go-bindata -prefix "migrations/" -o ./migrations_gen.go -ignore README|go|conf -pkg migrations .
|
||||
|
||||
package migrations
|
||||
|
||||
type All struct{}
|
||||
import "embed"
|
||||
|
||||
func (s *All) ListNames() []string {
|
||||
return AssetNames()
|
||||
}
|
||||
|
||||
func (s *All) MustAssetString(n string) string {
|
||||
return MustAssetString(n)
|
||||
}
|
||||
//go:embed *.sql
|
||||
var All embed.FS
|
||||
|
|
|
@ -1,271 +0,0 @@
|
|||
// Code generated by go-bindata. DO NOT EDIT.
|
||||
// sources:
|
||||
// 0001_create_notebooks_table.sql (377B)
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
clErr := gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
if clErr != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
type asset struct {
|
||||
bytes []byte
|
||||
info os.FileInfo
|
||||
digest [sha256.Size]byte
|
||||
}
|
||||
|
||||
type bindataFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
func (fi bindataFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
func (fi bindataFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
func (fi bindataFileInfo) ModTime() time.Time {
|
||||
return fi.modTime
|
||||
}
|
||||
func (fi bindataFileInfo) IsDir() bool {
|
||||
return false
|
||||
}
|
||||
func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var __0001_create_notebooks_tableSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x8f\xc1\x6a\xeb\x30\x10\x45\xf7\xfa\x8a\x8b\x57\xef\x41\x0d\xca\xb6\xa1\x0b\x35\x88\x12\x6a\xbb\xc6\x55\x21\x59\x09\xc5\x1e\xd7\xa2\xb6\x15\x24\x39\xf4\xf3\x8b\x1d\xea\x12\xb2\x9c\xc3\xcc\xb9\x73\xd3\x14\xaa\x23\x4c\x81\xbc\xbe\x90\x0f\xd6\x8d\x08\x9d\x9b\xfa\x06\x83\x89\x75\x87\xd8\x11\x12\xce\xf9\x21\x41\xeb\xdd\xb0\xcc\xad\xed\x09\xa3\x19\x88\xa5\x29\xe4\xf7\x23\x38\xe7\x1b\x5d\x7b\x32\x91\xf4\xe8\x22\x9d\x9c\xfb\x0a\x3a\x9a\x53\x4f\xbf\xb6\xce\x5c\x08\x66\x0d\xb2\xc1\x8d\x70\x2d\x36\xac\xac\xc4\x4b\x2e\x6e\x3e\x78\xda\x6c\xd9\xac\xde\x2d\xc6\x25\xd2\x8e\x36\x5a\xd3\xe3\xea\x8c\x0e\x21\x3a\x4f\x58\xc3\xd8\xae\x92\x42\x49\x28\xf1\x9c\x49\x24\x2b\x4f\xf0\x8f\x01\xb6\x81\x92\x07\x85\xe2\x4d\xa1\xf8\xc8\x32\x94\xd5\x3e\x17\xd5\x11\xaf\xf2\xf8\xc0\x00\xe7\x3f\xb5\x6d\xb0\x2f\xfe\x56\x66\x3c\x57\xbc\x3d\x9c\x69\x38\x53\x7d\x4f\xaf\xed\x1b\x6d\x22\xd4\x3e\x97\xef\x4a\xe4\xe5\xcc\xa7\x73\x73\xc7\xd9\xff\x2d\xfb\x09\x00\x00\xff\xff\xfa\x0d\x5b\xbc\x79\x01\x00\x00")
|
||||
|
||||
func _0001_create_notebooks_tableSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__0001_create_notebooks_tableSql,
|
||||
"0001_create_notebooks_table.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _0001_create_notebooks_tableSql() (*asset, error) {
|
||||
bytes, err := _0001_create_notebooks_tableSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0001_create_notebooks_table.sql", size: 377, mode: os.FileMode(420), modTime: time.Unix(1621864389, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4d, 0x3e, 0x28, 0x95, 0x61, 0xa2, 0x25, 0x32, 0xb3, 0x33, 0x8, 0x21, 0xe6, 0xf5, 0xcd, 0xb7, 0x26, 0x1d, 0xec, 0x29, 0x6b, 0x53, 0x87, 0x69, 0x1, 0x39, 0x16, 0x3b, 0xf, 0x2c, 0xed, 0xb7}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[canonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.bytes, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// AssetString returns the asset contents as a string (instead of a []byte).
|
||||
func AssetString(name string) (string, error) {
|
||||
data, err := Asset(name)
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
// MustAsset is like Asset but panics when Asset would return an error.
|
||||
// It simplifies safe initialization of global variables.
|
||||
func MustAsset(name string) []byte {
|
||||
a, err := Asset(name)
|
||||
if err != nil {
|
||||
panic("asset: Asset(" + name + "): " + err.Error())
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// MustAssetString is like AssetString but panics when Asset would return an
|
||||
// error. It simplifies safe initialization of global variables.
|
||||
func MustAssetString(name string) string {
|
||||
return string(MustAsset(name))
|
||||
}
|
||||
|
||||
// AssetInfo loads and returns the asset info for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func AssetInfo(name string) (os.FileInfo, error) {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[canonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.info, nil
|
||||
}
|
||||
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||
}
|
||||
|
||||
// AssetDigest returns the digest of the file with the given name. It returns an
|
||||
// error if the asset could not be found or the digest could not be loaded.
|
||||
func AssetDigest(name string) ([sha256.Size]byte, error) {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[canonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.digest, nil
|
||||
}
|
||||
return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name)
|
||||
}
|
||||
|
||||
// Digests returns a map of all known files and their checksums.
|
||||
func Digests() (map[string][sha256.Size]byte, error) {
|
||||
mp := make(map[string][sha256.Size]byte, len(_bindata))
|
||||
for name := range _bindata {
|
||||
a, err := _bindata[name]()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mp[name] = a.digest
|
||||
}
|
||||
return mp, nil
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"0001_create_notebooks_table.sql": _0001_create_notebooks_tableSql,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
// directory embedded in the file by go-bindata.
|
||||
// For example if you run go-bindata on data/... and data contains the
|
||||
// following hierarchy:
|
||||
// data/
|
||||
// foo.txt
|
||||
// img/
|
||||
// a.png
|
||||
// b.png
|
||||
// then AssetDir("data") would return []string{"foo.txt", "img"},
|
||||
// AssetDir("data/img") would return []string{"a.png", "b.png"},
|
||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and
|
||||
// AssetDir("") will return []string{"data"}.
|
||||
func AssetDir(name string) ([]string, error) {
|
||||
node := _bintree
|
||||
if len(name) != 0 {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
pathList := strings.Split(canonicalName, "/")
|
||||
for _, p := range pathList {
|
||||
node = node.Children[p]
|
||||
if node == nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Func != nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
rv := make([]string, 0, len(node.Children))
|
||||
for childName := range node.Children {
|
||||
rv = append(rv, childName)
|
||||
}
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"0001_create_notebooks_table.sql": &bintree{_0001_create_notebooks_tableSql, map[string]*bintree{}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory.
|
||||
func RestoreAsset(dir, name string) error {
|
||||
data, err := Asset(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := AssetInfo(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||
}
|
||||
|
||||
// RestoreAssets restores an asset under the given directory recursively.
|
||||
func RestoreAssets(dir, name string) error {
|
||||
children, err := AssetDir(name)
|
||||
// File
|
||||
if err != nil {
|
||||
return RestoreAsset(dir, name)
|
||||
}
|
||||
// Dir
|
||||
for _, child := range children {
|
||||
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _filePath(dir, name string) string {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...)
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
# disable to the ST1005 "error strings should not be capitalized" rule for this directory
|
||||
# to prevent errors from the code-gen'd bindata file.
|
||||
checks = ["inherit", "-ST1005"]
|
|
@ -2,6 +2,7 @@ package sqlite
|
|||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -9,11 +10,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MigrationSource interface {
|
||||
ListNames() []string
|
||||
MustAssetString(string) string
|
||||
}
|
||||
|
||||
type Migrator struct {
|
||||
store *SqlStore
|
||||
log *zap.Logger
|
||||
|
@ -26,35 +22,60 @@ func NewMigrator(store *SqlStore, log *zap.Logger) *Migrator {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *Migrator) Up(ctx context.Context, source MigrationSource) error {
|
||||
func (m *Migrator) Up(ctx context.Context, source embed.FS) error {
|
||||
list, err := source.ReadDir(".")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// sort the list according to the version number to ensure the migrations are applied in the correct order
|
||||
sort.Slice(list, func(i, j int) bool {
|
||||
return list[i].Name() < list[j].Name()
|
||||
})
|
||||
|
||||
// get the current value for user_version from the database
|
||||
c, err := m.store.userVersion()
|
||||
current, err := m.store.userVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
list := source.ListNames()
|
||||
// sort the list according to the version number to ensure the migrations are applied in the correct order
|
||||
sort.Strings(list)
|
||||
// get the migration number of the latest migration for logging purposes
|
||||
final, err := scriptVersion(list[len(list)-1].Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.log.Info("Bringing up metadata migrations", zap.Int("migration_count", len(list)))
|
||||
// log this message only if there are migrations to run
|
||||
if final > current {
|
||||
m.log.Info("Bringing up metadata migrations", zap.Int("migration_count", final-current))
|
||||
}
|
||||
|
||||
for _, n := range list {
|
||||
for _, f := range list {
|
||||
n := f.Name()
|
||||
// get the version of this migration script
|
||||
v, err := scriptVersion(n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// get the current value for user_version from the database. this is done in the loop as well to ensure
|
||||
// that if for some reason the migrations are out of order, newer migrations are not applied after older ones.
|
||||
c, err := m.store.userVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if the version of the script is greater than the current user_version,
|
||||
// execute the script to apply the migration
|
||||
if v > c {
|
||||
m.log.Debug("Executing metadata migration", zap.String("migration_name", n))
|
||||
stmt := source.MustAssetString(n)
|
||||
err := m.store.execTrans(ctx, stmt)
|
||||
mBytes, err := source.ReadFile(n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := m.store.execTrans(ctx, string(mBytes)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,15 @@ import (
|
|||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
type tableInfo struct {
|
||||
Cid int `db:"cid"`
|
||||
Name string `db:"name"`
|
||||
Db_type string `db:"type"`
|
||||
Notnull int `db:"notnull"`
|
||||
Dflt_value interface{} `db:"dflt_value"`
|
||||
Pk int `db:"pk"`
|
||||
}
|
||||
|
||||
func TestUp(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@ -23,12 +32,26 @@ func TestUp(t *testing.T) {
|
|||
require.Equal(t, 0, v)
|
||||
|
||||
migrator := NewMigrator(store, zaptest.NewLogger(t))
|
||||
migrator.Up(ctx, &test_migrations.All{})
|
||||
migrator.Up(ctx, test_migrations.All)
|
||||
|
||||
// user_version should now be 3 after applying the migrations
|
||||
v, err = store.userVersion()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, v)
|
||||
|
||||
// make sure that test_table_1 had the "id" column renamed to "org_id"
|
||||
table1Info := []*tableInfo{}
|
||||
err = store.DB.Select(&table1Info, "PRAGMA table_info(test_table_1)")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, table1Info, 3)
|
||||
require.Equal(t, "org_id", table1Info[0].Name)
|
||||
|
||||
// make sure that test_table_2 was created correctly
|
||||
table2Info := []*tableInfo{}
|
||||
err = store.DB.Select(&table2Info, "PRAGMA table_info(test_table_2)")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, table2Info, 3)
|
||||
require.Equal(t, "user_id", table2Info[0].Name)
|
||||
}
|
||||
|
||||
func TestScriptVersion(t *testing.T) {
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
//go:generate env GO111MODULE=on go run github.com/kevinburke/go-bindata/go-bindata -prefix "migrations/" -o ./migrations_gen.go -ignore README|go|conf -pkg test_migrations .
|
||||
|
||||
package test_migrations
|
||||
|
||||
type All struct{}
|
||||
import "embed"
|
||||
|
||||
func (s *All) ListNames() []string {
|
||||
return AssetNames()
|
||||
}
|
||||
|
||||
func (s *All) MustAssetString(n string) string {
|
||||
return MustAssetString(n)
|
||||
}
|
||||
//go:embed *.sql
|
||||
var All embed.FS
|
||||
|
|
|
@ -1,319 +0,0 @@
|
|||
// Code generated by go-bindata. DO NOT EDIT.
|
||||
// sources:
|
||||
// 0001_create_test_table_1.sql (294B)
|
||||
// 0002_rename_test_table_id_1.sql (471B)
|
||||
// 0003_create_test_table_2.sql (268B)
|
||||
|
||||
package test_migrations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
clErr := gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
if clErr != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
type asset struct {
|
||||
bytes []byte
|
||||
info os.FileInfo
|
||||
digest [sha256.Size]byte
|
||||
}
|
||||
|
||||
type bindataFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
func (fi bindataFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
func (fi bindataFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
func (fi bindataFileInfo) ModTime() time.Time {
|
||||
return fi.modTime
|
||||
}
|
||||
func (fi bindataFileInfo) IsDir() bool {
|
||||
return false
|
||||
}
|
||||
func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var __0001_create_test_table_1Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x8e\x41\x4b\xc3\x30\x18\x86\xef\xf9\x15\x2f\x3d\x29\x58\x48\xaf\x0e\x0f\x71\x04\x19\xb6\xb3\xd4\x08\xdb\x29\x64\xeb\x57\x13\x6c\x13\x69\xd2\xe1\xcf\x97\x66\x28\x88\xc7\xef\xfd\xe0\x79\x9e\xb2\x84\xb2\x84\x25\xd2\xac\x2f\x34\x47\x17\x3c\xa2\x0d\xcb\xd8\x63\x32\xe9\x6c\x91\x2c\xa1\xe0\x9c\x1f\x0a\x0c\x73\x98\xf2\x3d\xb8\x91\xe0\xcd\x44\xac\x2c\x21\xbf\xee\xc1\x39\xaf\xf4\x79\x26\x93\x48\xfb\x90\xe8\x14\xc2\x47\xd4\xc9\x9c\x46\xfa\xa1\x59\x73\x21\x98\x5f\x91\x8b\xc1\x23\x0c\xa8\x58\xdb\x89\xa7\x46\xfc\x29\x78\xa8\x36\x6c\x45\x6f\x33\x31\x2b\x13\xc5\xe4\xfc\x3b\x32\x93\x6d\x3b\x29\x94\x84\x12\x8f\xb5\x44\xb1\xfe\xae\x32\x5d\x15\xb8\x61\x80\xeb\xa1\xe4\x41\x61\xff\xa2\xb0\x7f\xab\x6b\xb4\xdd\xae\x11\xdd\x11\xcf\xf2\x78\xc7\x80\x6b\x6a\xaf\x4d\x82\xda\x35\xf2\x55\x89\xa6\x5d\xf7\xe5\xb3\xff\xb7\xb3\xdb\x0d\xfb\x0e\x00\x00\xff\xff\xb4\xf0\xc9\x16\x26\x01\x00\x00")
|
||||
|
||||
func _0001_create_test_table_1SqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__0001_create_test_table_1Sql,
|
||||
"0001_create_test_table_1.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _0001_create_test_table_1Sql() (*asset, error) {
|
||||
bytes, err := _0001_create_test_table_1SqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0001_create_test_table_1.sql", size: 294, mode: os.FileMode(420), modTime: time.Unix(1621877121, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe5, 0x9f, 0x5, 0xa8, 0x6a, 0x85, 0xcb, 0x8a, 0x60, 0x65, 0x54, 0xd4, 0x62, 0x45, 0xa5, 0x53, 0xe2, 0x7a, 0xba, 0xaa, 0x76, 0x5e, 0x71, 0xf4, 0x44, 0x5b, 0xd1, 0xf3, 0x24, 0x73, 0x59, 0xe6}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __0002_rename_test_table_id_1Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\x8f\xcd\x4e\xc2\x40\x14\x85\xd7\xdc\xa7\x38\x61\x05\x09\x4d\x8a\x4b\x89\x8b\x11\xaf\xa6\xb1\x7f\x19\xae\x09\xac\x26\x85\x0e\xb6\xb1\x74\x4c\x3b\x10\x1f\xdf\x28\x6a\x20\xe0\x72\xce\xdc\xf3\xf3\x05\x01\xa4\xb2\xd8\xf7\xb6\x33\x07\xdb\xf5\xb5\x6b\xd1\x57\x6e\xdf\x94\xd8\x15\x7e\x53\xc1\x57\x16\xc3\x30\x0c\x97\x43\x6c\x3b\xb7\xfb\x7e\x6f\xeb\xc6\xa2\x2d\x76\x96\x82\x00\xfc\x71\x8b\x30\x0c\xa7\x66\xd3\xd9\xc2\x5b\xd3\x3a\x6f\xd7\xce\xbd\xf5\xc6\x17\xeb\xc6\xfe\xa6\x55\xc5\xc1\xa2\xf8\x2b\xaa\x7b\xd7\xc2\x6d\x31\xa5\x5c\xab\xa7\x44\x9d\x2d\xb8\xbb\x99\x11\xa9\x58\x58\x43\xd4\x7d\xcc\xf0\xb6\xf7\xc7\x38\x33\x85\xe6\x54\x25\x0c\xc9\x60\x4e\x75\xe3\x9a\x72\x46\x34\xd7\xac\x84\xaf\xf8\x68\x44\x80\xeb\x5e\x4d\x5d\x42\x78\x29\x48\x33\x41\xfa\x12\xc7\xc8\x75\x94\x28\xbd\xc2\x33\xaf\x26\x04\x1c\x39\x4a\x53\x78\x48\x94\xf0\x42\x54\x92\x7f\xe9\xfb\xf7\xf2\x42\xa7\xf1\x8c\x28\x4a\x17\xac\x05\x51\x2a\xd9\xf9\xd2\xd1\xb1\x6e\x72\x62\x9d\x9c\xc4\x8f\x69\xb0\xe0\x98\xe7\x82\xff\x6f\x68\xf0\xa8\xb3\xe4\x2a\xe9\x83\xce\xf2\x1f\xce\x8b\xef\xcf\x00\x00\x00\xff\xff\x21\xe0\xcc\x10\xd7\x01\x00\x00")
|
||||
|
||||
func _0002_rename_test_table_id_1SqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__0002_rename_test_table_id_1Sql,
|
||||
"0002_rename_test_table_id_1.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _0002_rename_test_table_id_1Sql() (*asset, error) {
|
||||
bytes, err := _0002_rename_test_table_id_1SqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0002_rename_test_table_id_1.sql", size: 471, mode: os.FileMode(420), modTime: time.Unix(1621877249, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa0, 0x4, 0x11, 0x10, 0x22, 0x46, 0xf, 0xc1, 0xf9, 0x9e, 0xbf, 0x22, 0x40, 0x20, 0x7a, 0xc0, 0x51, 0xae, 0x55, 0xc5, 0x1e, 0x84, 0xf4, 0x18, 0x37, 0x38, 0xa0, 0x2b, 0xc2, 0xd0, 0x1d, 0x9a}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __0003_create_test_table_2Sql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\x8e\x41\x4b\xc3\x40\x10\x46\xef\xfb\x2b\x3e\x7a\x52\x30\xb0\xd5\x9b\xc5\xc3\x2a\x8b\x14\x93\x1a\xe2\x0a\xed\x69\xd9\x36\x13\x36\x98\x64\x64\x77\x52\xfc\xf9\xa2\x41\x41\x3c\xce\x63\x78\xdf\x2b\x0a\xb8\x48\x98\x33\x25\x7f\xa6\x94\x7b\x9e\x90\x23\xcf\x43\x8b\x31\xc8\x29\x42\x22\x61\xa5\xb5\xde\xaf\xd0\x25\x1e\xbf\xef\xae\x1f\x08\x53\x18\x49\x15\x05\xec\xc7\x2d\xb4\xd6\x6b\x7f\x4a\x14\x84\xfc\xc4\x42\x47\xe6\xb7\xec\x25\x1c\x07\xfa\xb1\xc5\x70\x26\x84\xdf\xa1\x3e\xf3\x04\xee\xb0\x56\x75\x63\x1e\x2b\xf3\xa7\xe0\xee\x66\xa3\xd4\x43\x63\x8d\xb3\x70\xe6\xbe\xb4\x10\xca\xb2\xf8\xfc\xb5\xba\x50\x58\xde\xfb\x16\xce\xee\x1d\x76\xcf\x0e\xbb\xd7\xb2\x44\xdd\x6c\x2b\xd3\x1c\xf0\x64\x0f\x57\x0a\x58\x8a\x5a\x1f\x04\x6e\x5b\xd9\x17\x67\xaa\xfa\x8b\xcf\xef\xed\x3f\xae\x2e\x37\x9f\x01\x00\x00\xff\xff\x83\x4b\x56\xf1\x0c\x01\x00\x00")
|
||||
|
||||
func _0003_create_test_table_2SqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__0003_create_test_table_2Sql,
|
||||
"0003_create_test_table_2.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _0003_create_test_table_2Sql() (*asset, error) {
|
||||
bytes, err := _0003_create_test_table_2SqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0003_create_test_table_2.sql", size: 268, mode: os.FileMode(420), modTime: time.Unix(1621877264, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9f, 0x5f, 0xd1, 0x19, 0x6c, 0x93, 0x71, 0xda, 0xa2, 0x1f, 0x18, 0xe2, 0xec, 0x1f, 0x6b, 0x9b, 0x40, 0x6a, 0x4d, 0x22, 0x3, 0x49, 0xb4, 0x50, 0x9b, 0x91, 0xff, 0x75, 0xdd, 0x8f, 0x9, 0xf5}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[canonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.bytes, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// AssetString returns the asset contents as a string (instead of a []byte).
|
||||
func AssetString(name string) (string, error) {
|
||||
data, err := Asset(name)
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
// MustAsset is like Asset but panics when Asset would return an error.
|
||||
// It simplifies safe initialization of global variables.
|
||||
func MustAsset(name string) []byte {
|
||||
a, err := Asset(name)
|
||||
if err != nil {
|
||||
panic("asset: Asset(" + name + "): " + err.Error())
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// MustAssetString is like AssetString but panics when Asset would return an
|
||||
// error. It simplifies safe initialization of global variables.
|
||||
func MustAssetString(name string) string {
|
||||
return string(MustAsset(name))
|
||||
}
|
||||
|
||||
// AssetInfo loads and returns the asset info for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func AssetInfo(name string) (os.FileInfo, error) {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[canonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.info, nil
|
||||
}
|
||||
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||
}
|
||||
|
||||
// AssetDigest returns the digest of the file with the given name. It returns an
|
||||
// error if the asset could not be found or the digest could not be loaded.
|
||||
func AssetDigest(name string) ([sha256.Size]byte, error) {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[canonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.digest, nil
|
||||
}
|
||||
return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name)
|
||||
}
|
||||
|
||||
// Digests returns a map of all known files and their checksums.
|
||||
func Digests() (map[string][sha256.Size]byte, error) {
|
||||
mp := make(map[string][sha256.Size]byte, len(_bindata))
|
||||
for name := range _bindata {
|
||||
a, err := _bindata[name]()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mp[name] = a.digest
|
||||
}
|
||||
return mp, nil
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"0001_create_test_table_1.sql": _0001_create_test_table_1Sql,
|
||||
|
||||
"0002_rename_test_table_id_1.sql": _0002_rename_test_table_id_1Sql,
|
||||
|
||||
"0003_create_test_table_2.sql": _0003_create_test_table_2Sql,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
// directory embedded in the file by go-bindata.
|
||||
// For example if you run go-bindata on data/... and data contains the
|
||||
// following hierarchy:
|
||||
// data/
|
||||
// foo.txt
|
||||
// img/
|
||||
// a.png
|
||||
// b.png
|
||||
// then AssetDir("data") would return []string{"foo.txt", "img"},
|
||||
// AssetDir("data/img") would return []string{"a.png", "b.png"},
|
||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and
|
||||
// AssetDir("") will return []string{"data"}.
|
||||
func AssetDir(name string) ([]string, error) {
|
||||
node := _bintree
|
||||
if len(name) != 0 {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
pathList := strings.Split(canonicalName, "/")
|
||||
for _, p := range pathList {
|
||||
node = node.Children[p]
|
||||
if node == nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Func != nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
rv := make([]string, 0, len(node.Children))
|
||||
for childName := range node.Children {
|
||||
rv = append(rv, childName)
|
||||
}
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"0001_create_test_table_1.sql": &bintree{_0001_create_test_table_1Sql, map[string]*bintree{}},
|
||||
"0002_rename_test_table_id_1.sql": &bintree{_0002_rename_test_table_id_1Sql, map[string]*bintree{}},
|
||||
"0003_create_test_table_2.sql": &bintree{_0003_create_test_table_2Sql, map[string]*bintree{}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory.
|
||||
func RestoreAsset(dir, name string) error {
|
||||
data, err := Asset(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := AssetInfo(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||
}
|
||||
|
||||
// RestoreAssets restores an asset under the given directory recursively.
|
||||
func RestoreAssets(dir, name string) error {
|
||||
children, err := AssetDir(name)
|
||||
// File
|
||||
if err != nil {
|
||||
return RestoreAsset(dir, name)
|
||||
}
|
||||
// Dir
|
||||
for _, child := range children {
|
||||
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _filePath(dir, name string) string {
|
||||
canonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(canonicalName, "/")...)...)
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
# disable to the ST1005 "error strings should not be capitalized" rule for this directory
|
||||
# to prevent errors from the code-gen'd bindata file.
|
||||
checks = ["inherit", "-ST1005"]
|
Loading…
Reference in New Issue