Skip to content

Commit 56a217b

Browse files
eulercbshahidhk
authored andcommitted
add name to migrate status response (close hasura#2376) (hasura#3109)
1 parent c9b9ed5 commit 56a217b

8 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎cli/commands/migrate_status.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ func printStatus(status *migrate.Status) *bytes.Buffer {
7474
buf := &bytes.Buffer{}
7575
out.Init(buf, 0, 8, 2, ' ', 0)
7676
w := util.NewPrefixWriter(out)
77-
w.Write(util.LEVEL_0, "VERSION\tSOURCE STATUS\tDATABASE STATUS\n")
77+
w.Write(util.LEVEL_0, "VERSION\tNAME\tSOURCE STATUS\tDATABASE STATUS\n")
7878
for _, version := range status.Index {
79-
w.Write(util.LEVEL_0, "%d\t%s\t%s\n",
79+
w.Write(util.LEVEL_0, "%d\t%s\t%s\t%s\n",
8080
version,
81+
status.Migrations[version].Name,
8182
convertBool(status.Migrations[version].IsPresent),
8283
convertBool(status.Migrations[version].IsApplied),
8384
)

‎cli/commands/migrate_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
202202
expectedStatus := migrate.NewStatus()
203203
expectedStatus.Append(&migrate.MigrationStatus{
204204
Version: 1,
205+
Name: "create_table_test",
205206
IsApplied: true,
206207
IsPresent: true,
207208
})
208209
expectedStatus.Append(&migrate.MigrationStatus{
209210
Version: 2,
211+
Name: "add_table_test",
210212
IsApplied: false,
211213
IsPresent: true,
212214
})
@@ -219,11 +221,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
219221
expectedStatus = migrate.NewStatus()
220222
expectedStatus.Append(&migrate.MigrationStatus{
221223
Version: 1,
224+
Name: "create_table_test",
222225
IsApplied: true,
223226
IsPresent: true,
224227
})
225228
expectedStatus.Append(&migrate.MigrationStatus{
226229
Version: 2,
230+
Name: "add_table_test",
227231
IsApplied: true,
228232
IsPresent: true,
229233
})
@@ -236,11 +240,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
236240
expectedStatus = migrate.NewStatus()
237241
expectedStatus.Append(&migrate.MigrationStatus{
238242
Version: 1,
243+
Name: "create_table_test",
239244
IsApplied: true,
240245
IsPresent: true,
241246
})
242247
expectedStatus.Append(&migrate.MigrationStatus{
243248
Version: 2,
249+
Name: "add_table_test",
244250
IsApplied: false,
245251
IsPresent: true,
246252
})
@@ -253,11 +259,13 @@ func testMigrate(t *testing.T, endpoint *url.URL, migrationsDir string) {
253259
expectedStatus = migrate.NewStatus()
254260
expectedStatus.Append(&migrate.MigrationStatus{
255261
Version: 1,
262+
Name: "create_table_test",
256263
IsApplied: false,
257264
IsPresent: true,
258265
})
259266
expectedStatus.Append(&migrate.MigrationStatus{
260267
Version: 2,
268+
Name: "add_table_test",
261269
IsApplied: false,
262270
IsPresent: true,
263271
})

‎cli/migrate/migrate.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ func (m *Migrate) newMigrationStatus(version uint64, driverType string) *Migrati
255255
if !ok {
256256
migrStatus = &MigrationStatus{
257257
Version: version,
258+
Name: m.sourceDrv.ReadName(version),
258259
}
259260
}
260261

‎cli/migrate/source/driver.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type Driver interface {
9292
// it must return os.ErrNotExist.
9393
// Do not start reading, just return the ReadCloser!
9494
ReadMetaDown(version uint64) (r io.ReadCloser, identifier string, fileName string, err error)
95+
96+
// ReadName returns an name that helps
97+
// finding this migration in the source for a given version
98+
ReadName(version uint64) (name string)
9599
}
96100

97101
// Open returns a new driver instance.

‎cli/migrate/source/file/file.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,7 @@ func (f *File) ReadMetaDown(version uint64) (r io.ReadCloser, identifier string,
219219
}
220220
return nil, "", "", &os.PathError{Op: fmt.Sprintf("read version %v", version), Path: f.path, Err: os.ErrNotExist}
221221
}
222+
223+
func (f *File) ReadName(version uint64) (name string) {
224+
return f.migrations.ReadName(version)
225+
}

‎cli/migrate/source/migration.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ func (i *Migrations) MetaDown(version uint64) (m *Migration, ok bool) {
166166
return nil, false
167167
}
168168

169+
func (i *Migrations) ReadName(version uint64) (name string) {
170+
for k := range i.migrations[version] {
171+
return i.migrations[version][k].Identifier
172+
}
173+
return "-"
174+
}
175+
169176
func (i *Migrations) findPos(version uint64) int {
170177
if len(i.index) > 0 {
171178
ix := i.index.Search(version)

‎cli/migrate/source/stub/stub.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ func (s *Stub) ReadMetaDown(version uint64) (r io.ReadCloser, identifier string,
108108
}
109109
return nil, "", "", &os.PathError{Op: fmt.Sprintf("read down yaml version %v", version), Path: s.Url, Err: os.ErrNotExist}
110110
}
111+
112+
func (f *Stub) ReadName(version uint64) (name string) {
113+
return f.Migrations.ReadName(version)
114+
}

‎cli/migrate/status.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ type MigrationStatus struct {
88
// Version is the version of this migration.
99
Version uint64 `json:"-"`
1010

11+
// Name helps finding this migration in the source folder
12+
Name string `json:"-"`
13+
1114
// Check if the migration is applied on the cluster
1215
IsApplied bool `json:"database_status"`
1316

0 commit comments

Comments
 (0)