graphql-engine/cli/pkg/migrate/apply.go
Aravind K P c7ac1ede3f cli: add migrate and metadata packages
>

### Description
>
This PR adds two new packages which implement the CLI requirements specified in RFC:https://github.com/hasura/lux/blob/cloud/docs/rfcs/20210614_github_integration.md

1. `pkg/metadata`

![image](https://user-images.githubusercontent.com/8335904/122384828-b4757d80-cf89-11eb-9e21-ef116fb928e9.png)

2. `pkg/migrate`

![image](https://user-images.githubusercontent.com/8335904/122510554-68771700-d023-11eb-9f5d-046d2c0cf18a.png)

### Changelog

- [x] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label.

### Affected components

- [x] CLI

https://github.com/hasura/graphql-engine-mono/pull/1598

GitOrigin-RevId: 0e2bce498386c5aae68dbca0fe383a6afff9d1a9
2021-06-18 06:25:14 +00:00

50 lines
1.3 KiB
Go

package migrate
import (
"github.com/hasura/graphql-engine/cli/v2"
"github.com/hasura/graphql-engine/cli/v2/commands"
)
type projectMigrationsApplier struct {
ec *cli.ExecutionContext
opts commands.MigrateApplyOptions
}
func newProjectMigrationsApplier(ec *cli.ExecutionContext) *projectMigrationsApplier {
p := &projectMigrationsApplier{ec: ec, opts: commands.MigrateApplyOptions{EC: ec}}
return p
}
type ProjectMigrationApplierOption func(applier *projectMigrationsApplier)
func ApplyOnAllDatabases() ProjectMigrationApplierOption {
return func(p *projectMigrationsApplier) {
p.opts.AllDatabases = true
}
}
func ApplyOnDatabaseName(databaseName string) ProjectMigrationApplierOption {
return func(p *projectMigrationsApplier) {
p.opts.Source.Name = databaseName
}
}
type MigrationDirection string
const MigrationDirectionUp MigrationDirection = "up"
const MigrationDirectionDown MigrationDirection = "down"
func ApplyVersion(version string, direction MigrationDirection) ProjectMigrationApplierOption {
return func(p *projectMigrationsApplier) {
p.opts.VersionMigration = version
p.opts.MigrationType = string(direction)
}
}
func (p *projectMigrationsApplier) Apply(opts ...ProjectMigrationApplierOption) error {
for _, opt := range opts {
opt(p)
}
return p.opts.Run()
}