/
alt3rmann
/
graphql-engine
Обзор
Документация
Войти
/
alt3rmann
/
graphql-engine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
cli/pkg/migrate/delete.go
63 строки
2 KB
Mohd Bilal
cli: expose `hasura migrate delete` command as an API
07 дек 2022, 06:02
07 дек 2022, 06:02
00f5df3
Код
Авторство
О чём код?
package migrate import ( "github.com/hasura/graphql-engine/cli/v2" "github.com/hasura/graphql-engine/cli/v2/commands" "github.com/hasura/graphql-engine/cli/v2/internal/errors" "github.com/hasura/graphql-engine/cli/v2/internal/hasura" ) type projectMigrationsDeleter struct { ec *cli.ExecutionContext opts commands.MigrateDeleteOptions } func newProjectMigrationsDeleter(ec *cli.ExecutionContext) *projectMigrationsDeleter { p := &projectMigrationsDeleter{ec: ec, opts: commands.MigrateDeleteOptions{EC: ec}} return p } type ProjectMigrationDeleterOption func(deleter *projectMigrationsDeleter) func DeleteOnDatabase(databaseName string, databaseKind hasura.SourceKind) ProjectMigrationDeleterOption { return func(p *projectMigrationsDeleter) { p.opts.EC.Source.Name = databaseName p.opts.EC.Source.Kind = databaseKind } } func DeleteVersion(version uint64) ProjectMigrationDeleterOption { return func(p *projectMigrationsDeleter) { p.opts.Version = version } } func DeleteAllMigrations() ProjectMigrationDeleterOption { return func(p *projectMigrationsDeleter) { p.opts.All = true } } func DeleteOnlyOnServer() ProjectMigrationDeleterOption { return func(p *projectMigrationsDeleter) { p.opts.OnlyServer = true } } func DeleteOnAllDatabases() ProjectMigrationDeleterOption { return func(p *projectMigrationsDeleter) { p.opts.EC.AllDatabases = true } } func (p *projectMigrationsDeleter) delete(opts ...ProjectMigrationDeleterOption) error { var op errors.Op = "migrate.projectMigrationsDeleter.delete" p.opts.EC.AllDatabases = false // this becomes `true` if not explicitly set to `false` for some unkown reason for _, opt := range opts { opt(p) } if err := p.opts.Run(); err != nil { return errors.E(op, err) } return nil }