add name to migrate status response (close #2376) (#3109)

This commit is contained in:
Euler 2019-11-28 08:36:16 -03:00 committed by Shahidh K Muhammed
parent c9b9ed5055
commit 56a217bbaa
8 changed files with 34 additions and 2 deletions

View File

@ -74,10 +74,11 @@ func printStatus(status *migrate.Status) *bytes.Buffer {
buf := &bytes.Buffer{}
out.Init(buf, 0, 8, 2, ' ', 0)
w := util.NewPrefixWriter(out)
w.Write(util.LEVEL_0, "VERSION\tSOURCE STATUS\tDATABASE STATUS\n")
w.Write(util.LEVEL_0, "VERSION\tNAME\tSOURCE STATUS\tDATABASE STATUS\n")
for _, version := range status.Index {
w.Write(util.LEVEL_0, "%d\t%s\t%s\n",
w.Write(util.LEVEL_0, "%d\t%s\t%s\t%s\n",
version,
status.Migrations[version].Name,
convertBool(status.Migrations[version].IsPresent),
convertBool(status.Migrations[version].IsApplied),
)

View File

@ -202,11 +202,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
expectedStatus := migrate.NewStatus()
expectedStatus.Append(&migrate.MigrationStatus{
Version: 1,
Name: "create_table_test",
IsApplied: true,
IsPresent: true,
})
expectedStatus.Append(&migrate.MigrationStatus{
Version: 2,
Name: "add_table_test",
IsApplied: false,
IsPresent: true,
})
@ -219,11 +221,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
expectedStatus = migrate.NewStatus()
expectedStatus.Append(&migrate.MigrationStatus{
Version: 1,
Name: "create_table_test",
IsApplied: true,
IsPresent: true,
})
expectedStatus.Append(&migrate.MigrationStatus{
Version: 2,
Name: "add_table_test",
IsApplied: true,
IsPresent: true,
})
@ -236,11 +240,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
expectedStatus = migrate.NewStatus()
expectedStatus.Append(&migrate.MigrationStatus{
Version: 1,
Name: "create_table_test",
IsApplied: true,
IsPresent: true,
})
expectedStatus.Append(&migrate.MigrationStatus{
Version: 2,
Name: "add_table_test",
IsApplied: false,
IsPresent: true,
})
@ -253,11 +259,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
expectedStatus = migrate.NewStatus()
expectedStatus.Append(&migrate.MigrationStatus{
Version: 1,
Name: "create_table_test",
IsApplied: false,
IsPresent: true,
})
expectedStatus.Append(&migrate.MigrationStatus{
Version: 2,
Name: "add_table_test",
IsApplied: false,
IsPresent: true,
})

View File

@ -255,6 +255,7 @@ func (m *Migrate) newMigrationStatus(version uint64, driverType string) *Migrati
if !ok {
migrStatus = &MigrationStatus{
Version: version,
Name: m.sourceDrv.ReadName(version),
}
}

View File

@ -92,6 +92,10 @@ type Driver interface {
// it must return os.ErrNotExist.
// Do not start reading, just return the ReadCloser!
ReadMetaDown(version uint64) (r io.ReadCloser, identifier string, fileName string, err error)
// ReadName returns an name that helps
// finding this migration in the source for a given version
ReadName(version uint64) (name string)
}
// Open returns a new driver instance.

View File

@ -219,3 +219,7 @@ func (f *File) ReadMetaDown(version uint64) (r io.ReadCloser, identifier string,
}
return nil, "", "", &os.PathError{Op: fmt.Sprintf("read version %v", version), Path: f.path, Err: os.ErrNotExist}
}
func (f *File) ReadName(version uint64) (name string) {
return f.migrations.ReadName(version)
}

View File

@ -166,6 +166,13 @@ func (i *Migrations) MetaDown(version uint64) (m *Migration, ok bool) {
return nil, false
}
func (i *Migrations) ReadName(version uint64) (name string) {
for k := range i.migrations[version] {
return i.migrations[version][k].Identifier
}
return "-"
}
func (i *Migrations) findPos(version uint64) int {
if len(i.index) > 0 {
ix := i.index.Search(version)

View File

@ -108,3 +108,7 @@ func (s *Stub) ReadMetaDown(version uint64) (r io.ReadCloser, identifier string,
}
return nil, "", "", &os.PathError{Op: fmt.Sprintf("read down yaml version %v", version), Path: s.Url, Err: os.ErrNotExist}
}
func (f *Stub) ReadName(version uint64) (name string) {
return f.Migrations.ReadName(version)
}

View File

@ -8,6 +8,9 @@ type MigrationStatus struct {
// Version is the version of this migration.
Version uint64 `json:"-"`
// Name helps finding this migration in the source folder
Name string `json:"-"`
// Check if the migration is applied on the cluster
IsApplied bool `json:"database_status"`