diff --git a/cli/cli.go b/cli/cli.go index 6b99416f30d29e..e2acef069c4c1e 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -315,7 +315,7 @@ func (s *ServerConfig) SetHTTPClient() error { return nil } -type DatasourceConfig struct { +type DatabaseConfig struct { Name string `yaml:"name,omitempty"` Type string `yaml:"type,omitempty"` MigrationsDirectory string `yaml:"migrations_directory,omitempty"` @@ -337,8 +337,8 @@ type Config struct { // SeedsDirectory defines the directory where seed files will be stored SeedsDirectory string `yaml:"seeds_directory,omitempty"` // ActionConfig defines the config required to create or generate codegen for an action. - ActionConfig *types.ActionExecutionConfig `yaml:"actions,omitempty"` - DatasourcesConfig []DatasourceConfig `yaml:"datasources,omitempty"` + ActionConfig *types.ActionExecutionConfig `yaml:"actions,omitempty"` + DatabasesConfig []DatabaseConfig `yaml:"datasources,omitempty"` } // ExecutionContext contains various contextual information required by the cli @@ -428,8 +428,8 @@ type ExecutionContext struct { // instance of API client which communicates with Hasura API APIClient *hasura.Client - // current datasource on which operation is being done - Datasource string + // current database on which operation is being done + Database string HasMetadataV3 bool } @@ -936,7 +936,7 @@ func GetAdminSecretHeaderName(v *version.Version) string { } return XHasuraAdminSecret } -func GetDatasourceOps(ec *ExecutionContext) hasura.DatasourceOperations { +func GetDatabaseOps(ec *ExecutionContext) hasura.DatabaseOperations { if !ec.HasMetadataV3 { return ec.APIClient.V1Query } diff --git a/cli/commands/migrate.go b/cli/commands/migrate.go index 7a29a9957facda..4b1aafe695a934 100644 --- a/cli/commands/migrate.go +++ b/cli/commands/migrate.go @@ -37,8 +37,8 @@ func NewMigrateCmd(ec *cli.ExecutionContext) *cobra.Command { return err } if ec.Config.Version >= cli.V3 { - if !cmd.Flags().Changed("datasource") { - return errors.New("datasource flag is required") + if !cmd.Flags().Changed("database") { + return errors.New("database flag is required") } } else { if err := scripts.CheckIfUpdateToConfigV3IsRequired(ec); err != nil { @@ -51,7 +51,7 @@ func NewMigrateCmd(ec *cli.ExecutionContext) *cobra.Command { } f := migrateCmd.PersistentFlags() - f.StringVar(&ec.Datasource, "datasource", "", "datasource name which operation should be applied") + f.StringVar(&ec.Database, "database", "", "database on which operation should be applied") f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine") f.String("admin-secret", "", "admin secret for Hasura GraphQL Engine") diff --git a/cli/commands/migrate_apply.go b/cli/commands/migrate_apply.go index 271e1d6dc328eb..590807e086a21f 100644 --- a/cli/commands/migrate_apply.go +++ b/cli/commands/migrate_apply.go @@ -61,7 +61,7 @@ func newMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command { return ec.Validate() }, RunE: func(cmd *cobra.Command, args []string) error { - opts.Datasource = ec.Datasource + opts.Database = ec.Database if opts.dryRun && opts.SkipExecution { return errors.New("both --skip-execution and --dry-run flags cannot be used together") } @@ -116,7 +116,7 @@ type MigrateApplyOptions struct { GotoVersion string SkipExecution bool dryRun bool - Datasource string + Database string } func (o *MigrateApplyOptions) Run() error { @@ -125,7 +125,7 @@ func (o *MigrateApplyOptions) Run() error { return errors.Wrap(err, "error validating flags") } - migrateDrv, err := migrate.NewMigrate(o.EC, true, o.Datasource) + migrateDrv, err := migrate.NewMigrate(o.EC, true, o.Database) if err != nil { return err } diff --git a/cli/commands/migrate_create.go b/cli/commands/migrate_create.go index 3e5a0edc4eb2c2..cc44c21a64b107 100644 --- a/cli/commands/migrate_create.go +++ b/cli/commands/migrate_create.go @@ -52,7 +52,7 @@ func newMigrateCreateCmd(ec *cli.ExecutionContext) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { opts.name = args[0] opts.EC.Spin("Creating migration files...") - opts.Datasource = ec.Datasource + opts.Database = ec.Database version, err := opts.run() opts.EC.Spinner.Stop() if err != nil { @@ -97,12 +97,12 @@ type migrateCreateOptions struct { schemaNames []string upSQL string downSQL string - Datasource string + Database string } func (o *migrateCreateOptions) run() (version int64, err error) { timestamp := getTime() - createOptions := mig.New(timestamp, o.name, filepath.Join(o.EC.MigrationDir, o.Datasource)) + createOptions := mig.New(timestamp, o.name, filepath.Join(o.EC.MigrationDir, o.Database)) if o.fromServer { o.sqlServer = true @@ -137,7 +137,7 @@ func (o *migrateCreateOptions) run() (version int64, err error) { var migrateDrv *migrate.Migrate if o.sqlServer || o.metaDataServer || o.flags.Changed("up-sql") || o.flags.Changed("down-sql") { - migrateDrv, err = migrate.NewMigrate(o.EC, true, o.Datasource) + migrateDrv, err = migrate.NewMigrate(o.EC, true, o.Database) if err != nil { return 0, errors.Wrap(err, "cannot create migrate instance") } @@ -151,7 +151,7 @@ func (o *migrateCreateOptions) run() (version int64, err error) { } } if o.sqlServer { - data, err := migrateDrv.ExportSchemaDump(o.schemaNames, o.Datasource) + data, err := migrateDrv.ExportSchemaDump(o.schemaNames, o.Database) if err != nil { return 0, errors.Wrap(err, "cannot fetch schema dump") } diff --git a/cli/commands/migrate_squash.go b/cli/commands/migrate_squash.go index d417bcf1287c1e..e3bdd0f5ab2fa2 100644 --- a/cli/commands/migrate_squash.go +++ b/cli/commands/migrate_squash.go @@ -38,7 +38,7 @@ func newMigrateSquashCmd(ec *cli.ExecutionContext) *cobra.Command { SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { opts.newVersion = getTime() - opts.Datasource = ec.Datasource + opts.Database = ec.Database if opts.EC.HasMetadataV3 && opts.EC.Config.Version < cli.V2 { return fmt.Errorf("squashing when using metadata V3 is supported from Config V2 only") } @@ -65,19 +65,19 @@ type migrateSquashOptions struct { newVersion int64 deleteSource bool - Datasource string + Database string } func (o *migrateSquashOptions) run() error { o.EC.Logger.Warnln("This command is currently experimental and hence in preview, correctness of squashed migration is not guaranteed!") o.EC.Spin(fmt.Sprintf("Squashing migrations from %d to latest...", o.from)) defer o.EC.Spinner.Stop() - migrateDrv, err := migrate.NewMigrate(o.EC, true, o.Datasource) + migrateDrv, err := migrate.NewMigrate(o.EC, true, o.Database) if err != nil { return errors.Wrap(err, "unable to initialize migrations driver") } - versions, err := mig.SquashCmd(migrateDrv, o.from, o.newVersion, o.name, filepath.Join(o.EC.MigrationDir, o.Datasource)) + versions, err := mig.SquashCmd(migrateDrv, o.from, o.newVersion, o.name, filepath.Join(o.EC.MigrationDir, o.Database)) o.EC.Spinner.Stop() if err != nil { return errors.Wrap(err, "unable to squash migrations") @@ -98,7 +98,7 @@ func (o *migrateSquashOptions) run() error { for _, v := range versions { delOptions := mig.CreateOptions{ Version: strconv.FormatInt(v, 10), - Directory: filepath.Join(o.EC.MigrationDir, o.Datasource), + Directory: filepath.Join(o.EC.MigrationDir, o.Database), } err = delOptions.Delete() if err != nil { diff --git a/cli/commands/migrate_status.go b/cli/commands/migrate_status.go index a2b0eed2203ebc..c31e2dc28d0fd7 100644 --- a/cli/commands/migrate_status.go +++ b/cli/commands/migrate_status.go @@ -29,7 +29,7 @@ func newMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command { SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { opts.EC.Spin("Fetching migration status...") - opts.Datasource = ec.Datasource + opts.Database = ec.Database status, err := opts.Run() opts.EC.Spinner.Stop() if err != nil { @@ -44,12 +44,12 @@ func newMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command { } type MigrateStatusOptions struct { - EC *cli.ExecutionContext - Datasource string + EC *cli.ExecutionContext + Database string } func (o *MigrateStatusOptions) Run() (*migrate.Status, error) { - migrateDrv, err := migrate.NewMigrate(o.EC, true, o.Datasource) + migrateDrv, err := migrate.NewMigrate(o.EC, true, o.Database) if err != nil { return nil, err } diff --git a/cli/commands/scripts_upgrade_multiple_sources.go b/cli/commands/scripts_upgrade_multiple_sources.go index 623b1638289973..81716242571f85 100644 --- a/cli/commands/scripts_upgrade_multiple_sources.go +++ b/cli/commands/scripts_upgrade_multiple_sources.go @@ -35,7 +35,7 @@ func newUpdateMultipleSources(ec *cli.ExecutionContext) *cobra.Command { Logger: ec.Logger, EC: ec, } - return scripts.UpgradeProjectToMultipleSources(opts) + return scripts.UpdateProjectV3(opts) }, } return cmd diff --git a/cli/commands/seed.go b/cli/commands/seed.go index 584d13bb820d36..f3c5bbdd178295 100644 --- a/cli/commands/seed.go +++ b/cli/commands/seed.go @@ -27,8 +27,8 @@ func NewSeedCmd(ec *cli.ExecutionContext) *cobra.Command { return err } if ec.Config.Version >= cli.V3 { - if !cmd.Flags().Changed("datasource") { - return errors.New("datasource flag is required") + if !cmd.Flags().Changed("database") { + return errors.New("database flag is required") } } else { if err := scripts.CheckIfUpdateToConfigV3IsRequired(ec); err != nil { @@ -45,7 +45,7 @@ func NewSeedCmd(ec *cli.ExecutionContext) *cobra.Command { ) f := seedCmd.PersistentFlags() - f.StringVar(&ec.Datasource, "datasource", "", "datasource name which operation should be applied") + f.StringVar(&ec.Database, "database", "", "database on which operation should be applied") f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine") f.String("admin-secret", "", "admin secret for Hasura GraphQL Engine") diff --git a/cli/commands/seed_apply.go b/cli/commands/seed_apply.go index e9591a910901f2..89804ae71da284 100644 --- a/cli/commands/seed_apply.go +++ b/cli/commands/seed_apply.go @@ -13,8 +13,8 @@ type SeedApplyOptions struct { EC *cli.ExecutionContext // seed file to apply - FileNames []string - Datasource string + FileNames []string + Database string } func newSeedApplyCmd(ec *cli.ExecutionContext) *cobra.Command { @@ -35,7 +35,7 @@ func newSeedApplyCmd(ec *cli.ExecutionContext) *cobra.Command { }, RunE: func(cmd *cobra.Command, args []string) error { opts.EC.Spin("Applying seeds...") - opts.Datasource = ec.Datasource + opts.Database = ec.Database err := opts.Run() opts.EC.Spinner.Stop() if err != nil { @@ -55,5 +55,5 @@ func (o *SeedApplyOptions) Run() error { return err } fs := afero.NewOsFs() - return seed.ApplySeedsToDatabase(o.EC, fs, migrateDriver, o.FileNames, o.Datasource) + return seed.ApplySeedsToDatabase(o.EC, fs, migrateDriver, o.FileNames, o.Database) } diff --git a/cli/commands/seed_create.go b/cli/commands/seed_create.go index 7e13ec548fb5ed..7df7f9515ff05e 100644 --- a/cli/commands/seed_create.go +++ b/cli/commands/seed_create.go @@ -24,8 +24,8 @@ type SeedNewOptions struct { FromTableNames []string // seed file that was created - FilePath string - Datasource string + FilePath string + Database string } func newSeedCreateCmd(ec *cli.ExecutionContext) *cobra.Command { @@ -50,7 +50,7 @@ func newSeedCreateCmd(ec *cli.ExecutionContext) *cobra.Command { }, RunE: func(cmd *cobra.Command, args []string) error { opts.SeedName = args[0] - opts.Datasource = ec.Datasource + opts.Database = ec.Database err := opts.Run() if err != nil { return err @@ -66,15 +66,15 @@ func newSeedCreateCmd(ec *cli.ExecutionContext) *cobra.Command { } func (o *SeedNewOptions) Run() error { - datasourceDirectory := filepath.Join(o.EC.SeedsDirectory, o.Datasource) - if f, _ := os.Stat(datasourceDirectory); f == nil { - if err := os.MkdirAll(datasourceDirectory, 0755); err != nil { + databaseDirectory := filepath.Join(o.EC.SeedsDirectory, o.Database) + if f, _ := os.Stat(databaseDirectory); f == nil { + if err := os.MkdirAll(databaseDirectory, 0755); err != nil { return err } } createSeedOpts := seed.CreateSeedOpts{ UserProvidedSeedName: o.SeedName, - DirectoryPath: filepath.Join(o.EC.SeedsDirectory, o.Datasource), + DirectoryPath: filepath.Join(o.EC.SeedsDirectory, o.Database), } // If we are initializing from a database table @@ -87,7 +87,7 @@ func (o *SeedNewOptions) Run() error { return errors.Wrap(err, "cannot initialize migrate driver") } // Send the query - body, err = migrateDriver.ExportDataDump(o.FromTableNames, o.Datasource) + body, err = migrateDriver.ExportDataDump(o.FromTableNames, o.Database) if err != nil { return errors.Wrap(err, "exporting seed data") } diff --git a/cli/integration_test/v3/metadata.go b/cli/integration_test/v3/metadata.go index 0dcde1972e7485..dfeffa45c62e7c 100644 --- a/cli/integration_test/v3/metadata.go +++ b/cli/integration_test/v3/metadata.go @@ -96,7 +96,7 @@ func TestMetadataCmd(t *testing.T, ec *cli.ExecutionContext) { &commands.MigrateApplyOptions{ EC: ec, DownMigration: "all", - Datasource: "default", + Database: "default", }, nil, "", diff --git a/cli/integration_test/v3/metadata/latest/1_metadata/sources/sources.yaml b/cli/integration_test/v3/metadata/latest/1_metadata/databases/databases.yaml similarity index 100% rename from cli/integration_test/v3/metadata/latest/1_metadata/sources/sources.yaml rename to cli/integration_test/v3/metadata/latest/1_metadata/databases/databases.yaml diff --git a/cli/integration_test/v3/metadata/latest/2_metadata/sources/sources.yaml b/cli/integration_test/v3/metadata/latest/2_metadata/databases/databases.yaml similarity index 100% rename from cli/integration_test/v3/metadata/latest/2_metadata/sources/sources.yaml rename to cli/integration_test/v3/metadata/latest/2_metadata/databases/databases.yaml diff --git a/cli/integration_test/v3/metadata/latest/2_metadata/sources/default/tables/public_test.yaml b/cli/integration_test/v3/metadata/latest/2_metadata/databases/default/tables/public_test.yaml similarity index 100% rename from cli/integration_test/v3/metadata/latest/2_metadata/sources/default/tables/public_test.yaml rename to cli/integration_test/v3/metadata/latest/2_metadata/databases/default/tables/public_test.yaml diff --git a/cli/integration_test/v3/migrate.go b/cli/integration_test/v3/migrate.go index 0f5009cd78f550..3b60262987f950 100644 --- a/cli/integration_test/v3/migrate.go +++ b/cli/integration_test/v3/migrate.go @@ -33,8 +33,8 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { status migrate.Status }{ {"apply-up-all-migrations", &commands.MigrateApplyOptions{ - EC: ec, - Datasource: "default", + EC: ec, + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -51,7 +51,7 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { {"apply-down-1-migration", &commands.MigrateApplyOptions{ EC: ec, DownMigration: "1", - Datasource: "default", + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -68,7 +68,7 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { {"apply-down-all-migration", &commands.MigrateApplyOptions{ EC: ec, DownMigration: "all", - Datasource: "default", + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -85,7 +85,7 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { {"apply-goto-2-migration", &commands.MigrateApplyOptions{ EC: ec, GotoVersion: "2", - Datasource: "default", + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -102,7 +102,7 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { {"apply-goto-nil-migration", &commands.MigrateApplyOptions{ EC: ec, GotoVersion: "-1", - Datasource: "default", + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -119,7 +119,7 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { {"apply-up-1-migration", &commands.MigrateApplyOptions{ EC: ec, UpMigration: "1", - Datasource: "default", + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -136,7 +136,7 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { {"apply-version-2-up-migration", &commands.MigrateApplyOptions{ EC: ec, VersionMigration: "2", - Datasource: "default", + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -154,7 +154,7 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { EC: ec, VersionMigration: "2", MigrationType: "down", - Datasource: "default", + Database: "default", }, nil, migrate.Status{ Index: []uint64{1, 2}, Migrations: map[uint64]*migrate.MigrationStatus{ @@ -182,8 +182,8 @@ func TestMigrateCmd(t *testing.T, ec *cli.ExecutionContext) { t.Fatal(err) } statusOpts := &commands.MigrateStatusOptions{ - EC: ec, - Datasource: "default", + EC: ec, + Database: "default", } actualStatus, err := statusOpts.Run() if err != nil { diff --git a/cli/integration_test/v3/seeds.go b/cli/integration_test/v3/seeds.go index 02aeb731a33d8f..329fdcdfe7799d 100644 --- a/cli/integration_test/v3/seeds.go +++ b/cli/integration_test/v3/seeds.go @@ -51,7 +51,7 @@ func TestSeedsCreateCmd(t *testing.T, ec *cli.ExecutionContext) { DirectoryPath: "seeds/", Data: strings.NewReader("INSERT INTO account1 (username, password, email) values ('scriptonist', 'no you cant guess it', 'hello@drogon.com');"), UserProvidedSeedName: "can_we_create_seed_files", - Datasource: "default", + Database: "default", }, }, false, @@ -89,13 +89,13 @@ func TestSeedsCreateCmd(t *testing.T, ec *cli.ExecutionContext) { t.Fatalf("CreateSeedFile() = %v, but want filepath of form"+` [a-z]+\/[0-9]+\_[a-zA-Z]+\.sql`, *gotFilename) } gotDirectoryPath := regexGroups[1] - gotDatasourceDirectory := regexGroups[2] + gotDatabaseDirectory := regexGroups[2] gotUserProvidedFilename := regexGroups[4] gotFileExtension := regexGroups[5] fmt.Println(regexGroups) assert.Equal(t, gotDirectoryPath, tc.args.opts.DirectoryPath) assert.Equal(t, gotUserProvidedFilename, tc.args.opts.UserProvidedSeedName) - assert.Equal(t, gotDatasourceDirectory, tc.args.opts.Datasource+"/") + assert.Equal(t, gotDatabaseDirectory, tc.args.opts.Database+"/") assert.Equal(t, gotFileExtension, ".sql") // test if a filewith the filename was created @@ -128,8 +128,8 @@ func TestSeedsApplyCmd(t *testing.T, ec *cli.ExecutionContext) { { "can apply all seeds", &commands.SeedApplyOptions{ - EC: ec, - Datasource: "default", + EC: ec, + Database: "default", }, false, }, diff --git a/cli/internal/hasura/client.go b/cli/internal/hasura/client.go index e3175380834eab..fd33f11a3671b0 100644 --- a/cli/internal/hasura/client.go +++ b/cli/internal/hasura/client.go @@ -14,7 +14,7 @@ type Client struct { type V1Query interface { CommonMetadataOperations - DatasourceOperations + DatabaseOperations Send(requestBody interface{}) (httpcResponse *httpc.Response, body io.Reader, error error) } @@ -30,7 +30,7 @@ type CatalogStateOperations interface { } type V2Query interface { - DatasourceOperations + DatabaseOperations Send(requestBody interface{}) (httpcResponse *httpc.Response, body io.Reader, error error) } diff --git a/cli/internal/hasura/commonmetadata/commonmetadata.go b/cli/internal/hasura/commonmetadata/commonmetadata.go index 6af62073492048..514f5888c55670 100644 --- a/cli/internal/hasura/commonmetadata/commonmetadata.go +++ b/cli/internal/hasura/commonmetadata/commonmetadata.go @@ -13,7 +13,7 @@ import ( "github.com/hasura/graphql-engine/cli/internal/httpc" ) -// implements all metadata operations which does not depend on the datasource +// implements all metadata operations which does not depend on the database type ClientCommonMetadataOps struct { *httpc.Client path string diff --git a/cli/internal/hasura/datasourceops/datasource.go b/cli/internal/hasura/databaseops/datasource.go similarity index 60% rename from cli/internal/hasura/datasourceops/datasource.go rename to cli/internal/hasura/databaseops/datasource.go index 8e97cfc0337861..62fb21d6b4aaf9 100644 --- a/cli/internal/hasura/datasourceops/datasource.go +++ b/cli/internal/hasura/databaseops/datasource.go @@ -1,4 +1,4 @@ -package datasourceops +package databaseops import ( "bytes" @@ -9,18 +9,18 @@ import ( "github.com/hasura/graphql-engine/cli/internal/httpc" ) -// allow to interact with all hasura opertions on datasources -type ClientDatasourceOps struct { +// allow to interact with all hasura opertions on database +type ClientDatabaseOps struct { *httpc.Client // api subpath eg: "v1/query" path string } -func New(client *httpc.Client, path string) *ClientDatasourceOps { - return &ClientDatasourceOps{client, path} +func New(client *httpc.Client, path string) *ClientDatabaseOps { + return &ClientDatabaseOps{client, path} } -func (h *ClientDatasourceOps) send(body interface{}, responseBodyWriter io.Writer) (*httpc.Response, error) { +func (h *ClientDatabaseOps) send(body interface{}, responseBodyWriter io.Writer) (*httpc.Response, error) { req, err := h.NewRequest(http.MethodPost, h.path, body) if err != nil { return nil, err @@ -32,7 +32,7 @@ func (h *ClientDatasourceOps) send(body interface{}, responseBodyWriter io.Write return resp, nil } -func (c *ClientDatasourceOps) SendDatasourceOperation(body interface{}) (*httpc.Response, io.Reader, error) { +func (c *ClientDatabaseOps) SendDatabaseOperation(body interface{}) (*httpc.Response, io.Reader, error) { req, err := c.NewRequest(http.MethodPost, c.path, body) if err != nil { return nil, nil, err diff --git a/cli/internal/hasura/datasourceops/run_sql.go b/cli/internal/hasura/databaseops/run_sql.go similarity index 83% rename from cli/internal/hasura/datasourceops/run_sql.go rename to cli/internal/hasura/databaseops/run_sql.go index 84f56db3a729c7..35d80a7787a533 100644 --- a/cli/internal/hasura/datasourceops/run_sql.go +++ b/cli/internal/hasura/databaseops/run_sql.go @@ -1,4 +1,4 @@ -package datasourceops +package databaseops import ( "bytes" @@ -9,7 +9,7 @@ import ( "github.com/hasura/graphql-engine/cli/internal/hasura" ) -func (h *ClientDatasourceOps) RunSQL(input hasura.RunSQLInput) (*hasura.RunSQLOutput, error) { +func (h *ClientDatabaseOps) RunSQL(input hasura.RunSQLInput) (*hasura.RunSQLOutput, error) { body := hasura.RequestBody{ Type: "run_sql", Args: input, diff --git a/cli/internal/hasura/datasourceops/run_sql_test.go b/cli/internal/hasura/databaseops/run_sql_test.go similarity index 88% rename from cli/internal/hasura/datasourceops/run_sql_test.go rename to cli/internal/hasura/databaseops/run_sql_test.go index d6cb7613a0e23a..a4ee9c71bf2a28 100644 --- a/cli/internal/hasura/datasourceops/run_sql_test.go +++ b/cli/internal/hasura/databaseops/run_sql_test.go @@ -1,4 +1,4 @@ -package datasourceops +package databaseops import ( "testing" @@ -11,7 +11,7 @@ import ( "github.com/hasura/graphql-engine/cli/internal/httpc" ) -func TestHasuraDatasourceOperations_RunSQL(t *testing.T) { +func TestHasuraDatabaseOperations_RunSQL(t *testing.T) { port, teardown := testutil.StartHasura(t, testutil.HasuraVersion) defer teardown() type fields struct { @@ -19,8 +19,8 @@ func TestHasuraDatasourceOperations_RunSQL(t *testing.T) { path string } type args struct { - input hasura.RunSQLInput - datasource string + input hasura.RunSQLInput + database string } tests := []struct { name string @@ -50,7 +50,7 @@ func TestHasuraDatasourceOperations_RunSQL(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { test := func() { - h := &ClientDatasourceOps{ + h := &ClientDatabaseOps{ Client: tt.fields.httpClient, path: tt.fields.path, } diff --git a/cli/internal/hasura/datasourceops.go b/cli/internal/hasura/datasourceops.go index fd8898c13b9afa..7593d8950b80e8 100644 --- a/cli/internal/hasura/datasourceops.go +++ b/cli/internal/hasura/datasourceops.go @@ -11,10 +11,10 @@ const ( TuplesOK RunSQLResultType = "TuplesOk" ) -// hasura API requests used to interact with connected datasource(s) -type DatasourceOperations interface { +// hasura API requests used to interact with connected database(s) +type DatabaseOperations interface { RunSQL(input RunSQLInput) (response *RunSQLOutput, err error) - SendDatasourceOperation(requestBody interface{}) (httpcResponse *httpc.Response, body io.Reader, error error) + SendDatabaseOperation(requestBody interface{}) (httpcResponse *httpc.Response, body io.Reader, error error) } type RunSQLInput struct { diff --git a/cli/internal/hasura/v1query/v1_query.go b/cli/internal/hasura/v1query/v1_query.go index 3fc90b6566f4d7..bcb17c6e2d6cca 100644 --- a/cli/internal/hasura/v1query/v1_query.go +++ b/cli/internal/hasura/v1query/v1_query.go @@ -7,7 +7,7 @@ import ( "net/http" "github.com/hasura/graphql-engine/cli/internal/hasura/commonmetadata" - "github.com/hasura/graphql-engine/cli/internal/hasura/datasourceops" + "github.com/hasura/graphql-engine/cli/internal/hasura/databaseops" "github.com/hasura/graphql-engine/cli/internal/httpc" ) @@ -16,7 +16,7 @@ type Client struct { // api path, normaly this would be v1/query path string - *datasourceops.ClientDatasourceOps + *databaseops.ClientDatabaseOps *commonmetadata.ClientCommonMetadataOps } @@ -24,7 +24,7 @@ func New(c *httpc.Client, path string) *Client { client := &Client{ Client: c, path: path, - ClientDatasourceOps: datasourceops.New(c, path), + ClientDatabaseOps: databaseops.New(c, path), ClientCommonMetadataOps: commonmetadata.New(c, path), } return client diff --git a/cli/internal/hasura/v1query/v1_query_test.go b/cli/internal/hasura/v1query/v1_query_test.go index 7d035de94f8cd7..720a3c55ffc056 100644 --- a/cli/internal/hasura/v1query/v1_query_test.go +++ b/cli/internal/hasura/v1query/v1_query_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/hasura/graphql-engine/cli/internal/hasura/commonmetadata" - "github.com/hasura/graphql-engine/cli/internal/hasura/datasourceops" + "github.com/hasura/graphql-engine/cli/internal/hasura/databaseops" "github.com/hasura/graphql-engine/cli/internal/httpc" "github.com/hasura/graphql-engine/cli/internal/testutil" "github.com/stretchr/testify/assert" @@ -19,7 +19,7 @@ func TestClient_Send(t *testing.T) { type fields struct { Client *httpc.Client path string - HasuraDatasourceRequests *datasourceops.ClientDatasourceOps + HasuraDatabaseRequests *databaseops.ClientDatabaseOps HasuraCommonMetadataRequests *commonmetadata.ClientCommonMetadataOps } type args struct { @@ -43,7 +43,7 @@ func TestClient_Send(t *testing.T) { return c }(), path: "v1/query", - HasuraDatasourceRequests: nil, + HasuraDatabaseRequests: nil, HasuraCommonMetadataRequests: nil, }, args{ @@ -61,7 +61,7 @@ func TestClient_Send(t *testing.T) { c := &Client{ Client: tt.fields.Client, path: tt.fields.path, - ClientDatasourceOps: tt.fields.HasuraDatasourceRequests, + ClientDatabaseOps: tt.fields.HasuraDatabaseRequests, ClientCommonMetadataOps: tt.fields.HasuraCommonMetadataRequests, } resp, gotResponseBody, err := c.Send(tt.args.body) diff --git a/cli/internal/hasura/v2query/v2_query_test.go b/cli/internal/hasura/v2query/v2_query_test.go index d608ca421de285..172c65b5a29063 100644 --- a/cli/internal/hasura/v2query/v2_query_test.go +++ b/cli/internal/hasura/v2query/v2_query_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/hasura/graphql-engine/cli/internal/hasura/commonmetadata" - "github.com/hasura/graphql-engine/cli/internal/hasura/datasourceops" + "github.com/hasura/graphql-engine/cli/internal/hasura/databaseops" "github.com/hasura/graphql-engine/cli/internal/httpc" "github.com/hasura/graphql-engine/cli/internal/testutil" "github.com/stretchr/testify/assert" @@ -19,7 +19,7 @@ func TestClient_Send(t *testing.T) { type fields struct { Client *httpc.Client path string - HasuraDatasourceRequests *datasourceops.ClientDatasourceOps + HasuraDatabaseRequests *databaseops.ClientDatabaseOps HasuraCommonMetadataRequests *commonmetadata.ClientCommonMetadataOps } type args struct { @@ -43,7 +43,7 @@ func TestClient_Send(t *testing.T) { return c }(), path: "v2/query", - HasuraDatasourceRequests: nil, + HasuraDatabaseRequests: nil, HasuraCommonMetadataRequests: nil, }, args{ @@ -61,9 +61,9 @@ func TestClient_Send(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &Client{ - Client: tt.fields.Client, - path: tt.fields.path, - ClientDatasourceOps: tt.fields.HasuraDatasourceRequests, + Client: tt.fields.Client, + path: tt.fields.path, + ClientDatabaseOps: tt.fields.HasuraDatabaseRequests, } resp, gotResponseBody, err := c.Send(tt.args.body) if (err != nil) != tt.wantErr { diff --git a/cli/internal/hasura/v2query/v2query.go b/cli/internal/hasura/v2query/v2query.go index f1c51e0cef851f..bfac0e88136ce3 100644 --- a/cli/internal/hasura/v2query/v2query.go +++ b/cli/internal/hasura/v2query/v2query.go @@ -6,7 +6,7 @@ import ( "io" "net/http" - "github.com/hasura/graphql-engine/cli/internal/hasura/datasourceops" + "github.com/hasura/graphql-engine/cli/internal/hasura/databaseops" "github.com/hasura/graphql-engine/cli/internal/httpc" ) @@ -14,14 +14,14 @@ type Client struct { *httpc.Client path string - *datasourceops.ClientDatasourceOps + *databaseops.ClientDatabaseOps } func New(c *httpc.Client, path string) *Client { client := &Client{ - Client: c, - ClientDatasourceOps: datasourceops.New(c, path), - path: path, + Client: c, + ClientDatabaseOps: databaseops.New(c, path), + path: path, } return client } diff --git a/cli/internal/scripts/update-project-v3.go b/cli/internal/scripts/update-project-v3.go index 3d95f9e9aadff3..026604f1c95b70 100644 --- a/cli/internal/scripts/update-project-v3.go +++ b/cli/internal/scripts/update-project-v3.go @@ -37,14 +37,13 @@ type UpgradeToMuUpgradeProjectToMultipleSourcesOpts struct { Logger *logrus.Logger } -// UpgradeProjectToMultipleSources will help a project directory move from a single -// datasource structure to multiple datasource +// UpdateProjectV3 will help a project directory move from a single // The project is expected to be in Config V2 -func UpgradeProjectToMultipleSources(opts UpgradeToMuUpgradeProjectToMultipleSourcesOpts) error { +func UpdateProjectV3(opts UpgradeToMuUpgradeProjectToMultipleSourcesOpts) error { /* New flow Config V2 -> Config V3 - Warn user about creating a backup - - Ask user for the name of datasource to migrate to + - Ask user for the name of database to migrate to - copy state from hdb_tables to catalog state - Move current migration directories to a new source directory - Move seeds belonging to the source to a new directory @@ -66,20 +65,20 @@ func UpgradeProjectToMultipleSources(opts UpgradeToMuUpgradeProjectToMultipleSou } // move migration child directories // get directory names to move - targetDatasource, err := util.GetInputPrompt("what datasource does the current migrations / seeds belong to?") + targetDatabase, err := util.GetInputPrompt("what database does the current migrations / seeds belong to?") if err != nil { return err } opts.EC.Spinner.Start() opts.EC.Spin("updating project... ") // copy state - // if a default datasource is setup copy state from it - sources, err := ListDatasources(opts.EC.APIClient.V1Metadata) + // if a default database is setup copy state from it + sources, err := ListDatabases(opts.EC.APIClient.V1Metadata) if err != nil { return err } if len(sources) >= 1 { - if err := copyState(opts.EC, targetDatasource); err != nil { + if err := copyState(opts.EC, targetDatabase); err != nil { return err } } @@ -97,35 +96,35 @@ func UpgradeProjectToMultipleSources(opts UpgradeToMuUpgradeProjectToMultipleSou return errors.Wrap(err, "getting list of seed files to move") } - // create a new directory for TargetDatasource - targetMigrationsDirectoryName := filepath.Join(opts.MigrationsAbsDirectoryPath, targetDatasource) + // create a new directory for TargetDatabase + targetMigrationsDirectoryName := filepath.Join(opts.MigrationsAbsDirectoryPath, targetDatabase) if err = opts.Fs.Mkdir(targetMigrationsDirectoryName, 0755); err != nil { - errors.Wrap(err, "creating target datasource name") + errors.Wrap(err, "creating target migrations directory") } - // create a new directory for TargetDatasource - targetSeedsDirectoryName := filepath.Join(opts.SeedsAbsDirectoryPath, targetDatasource) + // create a new directory for TargetDatabase + targetSeedsDirectoryName := filepath.Join(opts.SeedsAbsDirectoryPath, targetDatabase) if err = opts.Fs.Mkdir(targetSeedsDirectoryName, 0755); err != nil { - errors.Wrap(err, "creating target datasource name") + errors.Wrap(err, "creating target seeds directory") } - // move migration directories to target datasource directory + // move migration directories to target database directory if err := copyMigrations(opts.Fs, migrationDirectoriesToMove, opts.MigrationsAbsDirectoryPath, targetMigrationsDirectoryName); err != nil { - return errors.Wrap(err, "moving migrations to target datasource directory") + return errors.Wrap(err, "moving migrations to target database directory") } - // move seed directories to target datasource directory + // move seed directories to target database directory if err := copyFiles(opts.Fs, seedFilesToMove, opts.SeedsAbsDirectoryPath, targetSeedsDirectoryName); err != nil { - return errors.Wrap(err, "moving seeds to target datasource directory") + return errors.Wrap(err, "moving seeds to target database directory") } // write new config file newConfig := *opts.EC.Config newConfig.Version = cli.V3 - newConfig.DatasourcesConfig = []cli.DatasourceConfig{ + newConfig.DatabasesConfig = []cli.DatabaseConfig{ { - Name: targetDatasource, - MigrationsDirectory: targetDatasource, - SeedsDirectory: targetDatasource, + Name: targetDatabase, + MigrationsDirectory: targetDatabase, + SeedsDirectory: targetDatabase, }, } if err := opts.EC.WriteConfig(&newConfig); err != nil { @@ -247,7 +246,7 @@ func isHasuraCLIGeneratedMigration(dirPath string) (bool, error) { return regexp.MatchString(regex, filepath.Base(dirPath)) } -func copyState(ec *cli.ExecutionContext, destdatasource string) error { +func copyState(ec *cli.ExecutionContext, destdatabase string) error { // copy migrations state src := cli.GetMigrationsStateStore(ec) if err := src.PrepareMigrationsStateStore(); err != nil { @@ -257,7 +256,7 @@ func copyState(ec *cli.ExecutionContext, destdatasource string) error { if err := dst.PrepareMigrationsStateStore(); err != nil { return err } - err := statestore.CopyMigrationState(src, dst, "", destdatasource) + err := statestore.CopyMigrationState(src, dst, "", destdatabase) if err != nil { return err } @@ -284,14 +283,12 @@ func CheckIfUpdateToConfigV3IsRequired(ec *cli.ExecutionContext) error { return errors.New("please upgrade your project to a newer version.\ntip: use " + color.New(color.FgCyan).SprintFunc()("hasura scripts update-project-v2") + " to upgrade your project to config v2") } if ec.Config.Version < cli.V3 && ec.HasMetadataV3 { - sources, err := ListDatasources(ec.APIClient.V1Metadata) + sources, err := ListDatabases(ec.APIClient.V1Metadata) if err != nil { return err } upgrade := func() error { - // server is configured with a default datasource - // and other datasources - ec.Logger.Info("Looks like you are trying to use hasura with multiple datasources, which requires some changes on your project directory\n") + ec.Logger.Info("Looks like you are trying to use hasura with multiple databases, which requires some changes on your project directory\n") ec.Logger.Info("please use " + color.New(color.FgCyan).SprintFunc()("hasura scripts update-project-v3") + " to make this change") return errors.New("update to config V3") } @@ -299,7 +296,7 @@ func CheckIfUpdateToConfigV3IsRequired(ec *cli.ExecutionContext) error { if len(sources) != 1 { return upgrade() } - // if 1 source is configured and it is not "default" then it's a custom datasource + // if 1 source is configured and it is not "default" then it's a custom database // then also prompt an upgrade if len(sources) == 1 { if sources[0] != "default" { @@ -310,7 +307,7 @@ func CheckIfUpdateToConfigV3IsRequired(ec *cli.ExecutionContext) error { return nil } -func ListDatasources(client hasura.CommonMetadataOperations) ([]string, error) { +func ListDatabases(client hasura.CommonMetadataOperations) ([]string, error) { metadata, err := client.ExportMetadata() if err != nil { return nil, err diff --git a/cli/internal/scripts/update-project-v3_test.go b/cli/internal/scripts/update-project-v3_test.go index ccca3816f00816..692bbc04a308d7 100644 --- a/cli/internal/scripts/update-project-v3_test.go +++ b/cli/internal/scripts/update-project-v3_test.go @@ -124,7 +124,7 @@ func Test_getMigrationDirectoryNames(t *testing.T) { } } -func Test_moveMigrationsToDatasourceDirectory(t *testing.T) { +func Test_moveMigrationsToDatabaseDirectory(t *testing.T) { type args struct { fs afero.Fs dirs []string @@ -228,8 +228,8 @@ func Test_copyState(t *testing.T) { port, teardown := testutil.StartHasura(t, testutil.HasuraVersion) defer teardown() type args struct { - ec *cli.ExecutionContext - destdatasource string + ec *cli.ExecutionContext + destdatabase string } tests := []struct { name string @@ -267,20 +267,20 @@ func Test_copyState(t *testing.T) { dstMigrations := migrations.NewCatalogStateStore(statestore.NewCLICatalogState(tt.args.ec.APIClient.V1Metadata)) assert.NoError(t, srcSettings.UpdateSetting("test", "test")) assert.NoError(t, srcMigrations.SetVersion("", 123, false)) - if err := copyState(tt.args.ec, tt.args.destdatasource); (err != nil) != tt.wantErr { + if err := copyState(tt.args.ec, tt.args.destdatabase); (err != nil) != tt.wantErr { t.Fatalf("copyState() error = %v, wantErr %v", err, tt.wantErr) } v, err := dstSettings.GetSetting("test") assert.NoError(t, err) assert.Equal(t, "test", v) - m, err := dstMigrations.GetVersions(tt.args.destdatasource) + m, err := dstMigrations.GetVersions(tt.args.destdatabase) assert.NoError(t, err) assert.Equal(t, map[uint64]bool{123: false}, m) }) } } -func Test_listDatasources(t *testing.T) { +func Test_listDatabases(t *testing.T) { type args struct { client hasura.CommonMetadataOperations } @@ -315,13 +315,13 @@ func Test_listDatasources(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := ListDatasources(tt.args.client) + got, err := ListDatabases(tt.args.client) if (err != nil) != tt.wantErr { - t.Errorf("ListDatasources() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("ListDatabases() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ListDatasources() got = %v, want %v", got, tt.want) + t.Errorf("ListDatabases() got = %v, want %v", got, tt.want) } }) } diff --git a/cli/internal/statestore/migrations/catalogstate.go b/cli/internal/statestore/migrations/catalogstate.go index 33243390678cd5..9cb6358917c72f 100644 --- a/cli/internal/statestore/migrations/catalogstate.go +++ b/cli/internal/statestore/migrations/catalogstate.go @@ -36,35 +36,35 @@ func NewCatalogStateStore(c *statestore.CLICatalogState) *CatalogStateStore { return &CatalogStateStore{c} } -func (m *CatalogStateStore) InsertVersion(datasource string, version int64) error { +func (m *CatalogStateStore) InsertVersion(database string, version int64) error { // get setting state, err := m.getCLIState() if err != nil { return err } versionString := fmt.Sprintf("%d", version) - state.SetMigration(datasource, versionString, false) + state.SetMigration(database, versionString, false) return m.setCLIState(*state) } -func (m *CatalogStateStore) SetVersion(datasource string, version int64, dirty bool) error { +func (m *CatalogStateStore) SetVersion(database string, version int64, dirty bool) error { // get setting state, err := m.getCLIState() if err != nil { return err } versionString := fmt.Sprintf("%d", version) - state.SetMigration(datasource, versionString, dirty) + state.SetMigration(database, versionString, dirty) return m.setCLIState(*state) } -func (m *CatalogStateStore) RemoveVersion(datasource string, version int64) error { +func (m *CatalogStateStore) RemoveVersion(database string, version int64) error { versionString := fmt.Sprintf("%d", version) state, err := m.getCLIState() if err != nil { return err } - state.UnsetMigration(datasource, versionString) + state.UnsetMigration(database, versionString) return m.setCLIState(*state) } @@ -72,13 +72,13 @@ func (m *CatalogStateStore) PrepareMigrationsStateStore() error { return nil } -func (m *CatalogStateStore) GetVersions(datasource string) (map[uint64]bool, error) { +func (m *CatalogStateStore) GetVersions(database string) (map[uint64]bool, error) { state, err := m.getCLIState() if err != nil { return nil, err } var versions = map[uint64]bool{} - for version, dirty := range state.GetMigrationsByDatasource(datasource) { + for version, dirty := range state.GetMigrationsByDatabase(database) { parsedVersion, err := strconv.ParseUint(version, 10, 64) if err != nil { return nil, errors.Wrap(err, "parsing migration version") diff --git a/cli/internal/statestore/migrations/catalogstate_test.go b/cli/internal/statestore/migrations/catalogstate_test.go index 4043de57feff34..e6f785fd306559 100644 --- a/cli/internal/statestore/migrations/catalogstate_test.go +++ b/cli/internal/statestore/migrations/catalogstate_test.go @@ -19,8 +19,8 @@ func TestCatalogStateStore_InsertVersion(t *testing.T) { c *statestore.CLICatalogState } type args struct { - datasource string - version int64 + database string + version int64 } tests := []struct { name string @@ -33,8 +33,8 @@ func TestCatalogStateStore_InsertVersion(t *testing.T) { fields{ statestore.NewCLICatalogState(catalogstate.New(testutil.NewHttpcClient(t, port, nil), "v1/metadata"))}, args{ - datasource: "test", - version: 321312321321321, + database: "test", + version: 321312321321321, }, false, }, @@ -44,14 +44,14 @@ func TestCatalogStateStore_InsertVersion(t *testing.T) { m := &CatalogStateStore{ c: tt.fields.c, } - err := m.InsertVersion(tt.args.datasource, tt.args.version) + err := m.InsertVersion(tt.args.database, tt.args.version) if tt.wantErr { assert.Error(t, err) } else { assert.NoError(t, err) state, err := m.getCLIState() assert.NoError(t, err) - assert.Equal(t, map[string]bool{strconv.Itoa(int(tt.args.version)): false}, state.GetMigrationsByDatasource(tt.args.datasource)) + assert.Equal(t, map[string]bool{strconv.Itoa(int(tt.args.version)): false}, state.GetMigrationsByDatabase(tt.args.database)) } }) } diff --git a/cli/internal/statestore/migrations/hdbtable.go b/cli/internal/statestore/migrations/hdbtable.go index dbebe71dc2ff28..535e5beff00507 100644 --- a/cli/internal/statestore/migrations/hdbtable.go +++ b/cli/internal/statestore/migrations/hdbtable.go @@ -12,11 +12,11 @@ import ( // until version 1.4 migration state was stored a special table // this struct will implement the methods required type MigrationStateStoreHdbTable struct { - client hasura.DatasourceOperations + client hasura.DatabaseOperations schema, table string } -func NewMigrationStateStoreHdbTable(client hasura.DatasourceOperations, schema, table string) *MigrationStateStoreHdbTable { +func NewMigrationStateStoreHdbTable(client hasura.DatabaseOperations, schema, table string) *MigrationStateStoreHdbTable { return &MigrationStateStoreHdbTable{client, schema, table} } diff --git a/cli/internal/statestore/settings/hdbtable.go b/cli/internal/statestore/settings/hdbtable.go index e109bea7b4c8fc..af5ba3d90e0294 100644 --- a/cli/internal/statestore/settings/hdbtable.go +++ b/cli/internal/statestore/settings/hdbtable.go @@ -7,11 +7,11 @@ import ( ) type StateStoreHdbTable struct { - client hasura.DatasourceOperations + client hasura.DatabaseOperations schema, table string } -func NewStateStoreHdbTable(client hasura.DatasourceOperations, schema, table string) *StateStoreHdbTable { +func NewStateStoreHdbTable(client hasura.DatabaseOperations, schema, table string) *StateStoreHdbTable { return &StateStoreHdbTable{client, schema, table} } diff --git a/cli/internal/statestore/statestore.go b/cli/internal/statestore/statestore.go index dd5bcc57af568d..dfe2aba6152d71 100644 --- a/cli/internal/statestore/statestore.go +++ b/cli/internal/statestore/statestore.go @@ -9,10 +9,10 @@ import ( // Abstraction for the storage layer for migration state type MigrationsStateStore interface { - InsertVersion(datasource string, version int64) error - RemoveVersion(datasource string, version int64) error - SetVersion(datasource string, version int64, dirty bool) error - GetVersions(datasource string) (map[uint64]bool, error) + InsertVersion(database string, version int64) error + RemoveVersion(database string, version int64) error + SetVersion(database string, version int64, dirty bool) error + GetVersions(database string) (map[uint64]bool, error) PrepareMigrationsStateStore() error } @@ -71,19 +71,19 @@ func (c *CLIState) Init() { c.Settings = map[string]string{} } } -func (c *CLIState) SetMigration(datasource, key string, value bool) { - if c.Migrations[datasource] == nil { - c.Migrations[datasource] = map[string]bool{} +func (c *CLIState) SetMigration(database, key string, value bool) { + if c.Migrations[database] == nil { + c.Migrations[database] = map[string]bool{} } - c.Migrations[datasource][key] = value + c.Migrations[database][key] = value } -func (c *CLIState) UnsetMigration(datasource, key string) { - delete(c.Migrations[datasource], key) +func (c *CLIState) UnsetMigration(database, key string) { + delete(c.Migrations[database], key) } -func (c *CLIState) GetMigrationsByDatasource(datasource string) map[string]bool { - return c.Migrations[datasource] +func (c *CLIState) GetMigrationsByDatabase(database string) map[string]bool { + return c.Migrations[database] } func (c *CLIState) GetMigrations() *MigrationsState { @@ -109,13 +109,13 @@ func (c *CLIState) GetSettings() map[string]string { return c.Settings } -func CopyMigrationState(src, dest MigrationsStateStore, srcdatasource, destdatasource string) error { - versions, err := src.GetVersions(srcdatasource) +func CopyMigrationState(src, dest MigrationsStateStore, srcdatabase, destdatabase string) error { + versions, err := src.GetVersions(srcdatabase) if err != nil { return err } for k, v := range versions { - dest.SetVersion(destdatasource, int64(k), v) + dest.SetVersion(destdatabase, int64(k), v) } return nil } diff --git a/cli/metadata/sources/sources.go b/cli/metadata/sources/sources.go index cd4c18a9fffcbf..57947fd0c95717 100644 --- a/cli/metadata/sources/sources.go +++ b/cli/metadata/sources/sources.go @@ -18,8 +18,8 @@ import ( ) const ( - fileName string = "sources.yaml" - sourcesDirectory string = "sources" + fileName string = "databases.yaml" + sourcesDirectory string = "databases" functionsDirectory string = "functions" tablesDirectory string = "tables" ) diff --git a/cli/metadata/sources/sources_test.go b/cli/metadata/sources/sources_test.go index da4f84ee6ac3c0..843c5fee965bab 100644 --- a/cli/metadata/sources/sources_test.go +++ b/cli/metadata/sources/sources_test.go @@ -41,7 +41,7 @@ func TestSourceConfig_Export(t *testing.T) { }(), }, map[string][]byte{ - "metadata/sources/sources.yaml": []byte(`- name: default + "metadata/databases/databases.yaml": []byte(`- name: default configuration: connection_info: database_url: @@ -57,19 +57,19 @@ func TestSourceConfig_Export(t *testing.T) { - "!include public_get_t1.yaml" - "!include public_get_t2.yaml" `), - "metadata/sources/default/tables/public_t1.yaml": []byte(`table: + "metadata/databases/default/tables/public_t1.yaml": []byte(`table: name: t1 schema: public `), - "metadata/sources/default/tables/public_t2.yaml": []byte(`table: + "metadata/databases/default/tables/public_t2.yaml": []byte(`table: name: t2 schema: public `), - "metadata/sources/default/functions/public_get_t1.yaml": []byte(`function: + "metadata/databases/default/functions/public_get_t1.yaml": []byte(`function: name: get_t1 schema: public `), - "metadata/sources/default/functions/public_get_t2.yaml": []byte(`function: + "metadata/databases/default/functions/public_get_t2.yaml": []byte(`function: name: get_t2 schema: public `), diff --git a/cli/metadata/sources/testdata/metadata/sources/sources.yaml b/cli/metadata/sources/testdata/metadata/databases/databases.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/sources.yaml rename to cli/metadata/sources/testdata/metadata/databases/databases.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s1/functions/public_get_t1.yaml b/cli/metadata/sources/testdata/metadata/databases/s1/functions/public_get_t1.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s1/functions/public_get_t1.yaml rename to cli/metadata/sources/testdata/metadata/databases/s1/functions/public_get_t1.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s1/functions/public_get_t2.yaml b/cli/metadata/sources/testdata/metadata/databases/s1/functions/public_get_t2.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s1/functions/public_get_t2.yaml rename to cli/metadata/sources/testdata/metadata/databases/s1/functions/public_get_t2.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s1/tables/public_t1.yaml b/cli/metadata/sources/testdata/metadata/databases/s1/tables/public_t1.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s1/tables/public_t1.yaml rename to cli/metadata/sources/testdata/metadata/databases/s1/tables/public_t1.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s1/tables/public_t2.yaml b/cli/metadata/sources/testdata/metadata/databases/s1/tables/public_t2.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s1/tables/public_t2.yaml rename to cli/metadata/sources/testdata/metadata/databases/s1/tables/public_t2.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s2/functions/public_get_t1.yaml b/cli/metadata/sources/testdata/metadata/databases/s2/functions/public_get_t1.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s2/functions/public_get_t1.yaml rename to cli/metadata/sources/testdata/metadata/databases/s2/functions/public_get_t1.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s2/functions/public_get_t2.yaml b/cli/metadata/sources/testdata/metadata/databases/s2/functions/public_get_t2.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s2/functions/public_get_t2.yaml rename to cli/metadata/sources/testdata/metadata/databases/s2/functions/public_get_t2.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s2/tables/public_t1.yaml b/cli/metadata/sources/testdata/metadata/databases/s2/tables/public_t1.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s2/tables/public_t1.yaml rename to cli/metadata/sources/testdata/metadata/databases/s2/tables/public_t1.yaml diff --git a/cli/metadata/sources/testdata/metadata/sources/s2/tables/public_t2.yaml b/cli/metadata/sources/testdata/metadata/databases/s2/tables/public_t2.yaml similarity index 100% rename from cli/metadata/sources/testdata/metadata/sources/s2/tables/public_t2.yaml rename to cli/metadata/sources/testdata/metadata/databases/s2/tables/public_t2.yaml diff --git a/cli/migrate/api/migrate.go b/cli/migrate/api/migrate.go index 48898c20d13467..dd99c4fa908916 100644 --- a/cli/migrate/api/migrate.go +++ b/cli/migrate/api/migrate.go @@ -35,14 +35,14 @@ type Request struct { Up []requestType `json:"up"` Down []requestType `json:"down"` SkipExecution bool `json:"skip_execution"` - Datasource string `json:"datasource,omitempty"` + Database string `json:"datasource,omitempty"` } type requestType struct { - Version int `json:"version,omitempty"` - Type string `json:"type"` - Datasource string `json:"datasource,omitempty"` - Args interface{} `json:"args"` + Version int `json:"version,omitempty"` + Type string `json:"type"` + Database string `json:"datasource,omitempty"` + Args interface{} `json:"args"` } func MigrateAPI(c *gin.Context) { @@ -77,12 +77,12 @@ func MigrateAPI(c *gin.Context) { // Switch on request method switch c.Request.Method { case "GET": - datasource := c.Query("datasource") - if ec.Config.Version >= cli.V3 && datasource == "" { + database := c.Query("datasource") + if ec.Config.Version >= cli.V3 && database == "" { c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: "datasource query parameter is required"}) return } - t, err := migrate.NewMigrate(ec, false, datasource) + t, err := migrate.NewMigrate(ec, false, database) if err != nil { c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) return @@ -109,23 +109,23 @@ func MigrateAPI(c *gin.Context) { return } - if ec.Config.Version >= cli.V3 && request.Datasource == "" { + if ec.Config.Version >= cli.V3 && request.Database == "" { c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: "datasource key not found in body"}) return } startTime := time.Now() timestamp := startTime.UnixNano() / int64(time.Millisecond) - datasource := request.Datasource + database := request.Database if ec.Config.Version < cli.V3 { - datasource = "" + database = "" } - t, err := migrate.NewMigrate(ec, false, datasource) + t, err := migrate.NewMigrate(ec, false, database) if err != nil { c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) return } - createOptions := cmd.New(timestamp, request.Name, filepath.Join(ec.MigrationDir, datasource)) + createOptions := cmd.New(timestamp, request.Name, filepath.Join(ec.MigrationDir, database)) if version != int(cli.V1) { sqlUp := &bytes.Buffer{} sqlDown := &bytes.Buffer{} diff --git a/cli/migrate/database/driver_test.go b/cli/migrate/database/driver_test.go index 4b129c8f0c4aef..5c3b92683e5311 100644 --- a/cli/migrate/database/driver_test.go +++ b/cli/migrate/database/driver_test.go @@ -153,14 +153,6 @@ func (m *mockDriver) ExportDataDump([]string, string) ([]byte, error) { return nil, nil } -func (m *mockDriver) GetDatasources() ([]string, error) { - return nil, nil -} - -func (m *mockDriver) PrepareMigrationsStateStore() error { - return nil -} - func TestRegisterTwice(t *testing.T) { Register("mock", &mockDriver{}) diff --git a/cli/migrate/database/hasuradb/hasuradb.go b/cli/migrate/database/hasuradb/hasuradb.go index 05b92310dc8974..890068a60189db 100644 --- a/cli/migrate/database/hasuradb/hasuradb.go +++ b/cli/migrate/database/hasuradb/hasuradb.go @@ -33,7 +33,7 @@ func init() { } const ( - DefaultDatasourceName = "default" + DefaultDatabaseName = "default" ) var ( @@ -77,7 +77,7 @@ type HasuraDB struct { hasuraOpts *database.HasuraOpts metadataops hasura.CommonMetadataOperations - datasourceops hasura.DatasourceOperations + databaseops hasura.DatabaseOperations hasuraClient *hasura.Client migrationsStateStore statestore.MigrationsStateStore settingsStateStore statestore.SettingsStateStore @@ -96,7 +96,7 @@ func WithInstance(config *Config, logger *log.Logger, hasuraOpts *database.Hasur logger: logger, hasuraOpts: hasuraOpts, metadataops: hasuraOpts.MetadataOps, - datasourceops: hasuraOpts.DatasourceOps, + databaseops: hasuraOpts.DatabaseOps, hasuraClient: hasuraOpts.Client, migrationsStateStore: hasuraOpts.MigrationsStateStore, settingsStateStore: hasuraOpts.SettingsStateStore, @@ -230,12 +230,12 @@ func (h *HasuraDB) Run(migration io.Reader, fileType, fileName string) error { } sqlInput := hasura.RunSQLInput{ SQL: string(body), - Source: h.hasuraOpts.Datasource, + Source: h.hasuraOpts.Database, } if h.config.enableCheckMetadataConsistency { sqlInput.CheckMetadataConsistency = func() *bool { b := false; return &b }() } - _, err := h.datasourceops.RunSQL(sqlInput) + _, err := h.databaseops.RunSQL(sqlInput) if err != nil { return nil } @@ -307,7 +307,7 @@ func sendMetadataMigrations(hasuradb *HasuraDB, requests []interface{}) error { Type: "bulk", Args: queryRequests, } - resp, body, err := hasuradb.datasourceops.SendDatasourceOperation(queryBulk) + resp, body, err := hasuradb.databaseops.SendDatabaseOperation(queryBulk) if err != nil { return err } @@ -345,20 +345,20 @@ func (h *HasuraDB) ResetQuery() { } func (h *HasuraDB) InsertVersion(version int64) error { - return h.migrationsStateStore.InsertVersion(h.hasuraOpts.Datasource, version) + return h.migrationsStateStore.InsertVersion(h.hasuraOpts.Database, version) } func (h *HasuraDB) SetVersion(version int64, dirty bool) error { - return h.migrationsStateStore.SetVersion(h.hasuraOpts.Datasource, version, dirty) + return h.migrationsStateStore.SetVersion(h.hasuraOpts.Database, version, dirty) } func (h *HasuraDB) RemoveVersion(version int64) error { - return h.migrationsStateStore.RemoveVersion(h.hasuraOpts.Datasource, version) + return h.migrationsStateStore.RemoveVersion(h.hasuraOpts.Database, version) } func (h *HasuraDB) getVersions() (err error) { - v, err := h.migrationsStateStore.GetVersions(h.hasuraOpts.Datasource) + v, err := h.migrationsStateStore.GetVersions(h.hasuraOpts.Database) if err != nil { return err } diff --git a/cli/migrate/database/hasuradb/seed.go b/cli/migrate/database/hasuradb/seed.go index 7183e409380c8d..1a3f2f6c622ab2 100644 --- a/cli/migrate/database/hasuradb/seed.go +++ b/cli/migrate/database/hasuradb/seed.go @@ -9,7 +9,7 @@ import ( ) func (h *HasuraDB) ApplySeed(m interface{}) error { - resp, body, err := h.datasourceops.SendDatasourceOperation(m) + resp, body, err := h.databaseops.SendDatabaseOperation(m) if err != nil { return err } diff --git a/cli/migrate/database/migration.go b/cli/migrate/database/migration.go index 2c9d68d7d1435f..3a2ae4dc020433 100644 --- a/cli/migrate/database/migration.go +++ b/cli/migrate/database/migration.go @@ -106,10 +106,10 @@ func (s migrationVersions) Search(x uint64) int { type HasuraOpts struct { HasMetadataV3 bool - Datasource string + Database string Client *hasura.Client - DatasourceOps hasura.DatasourceOperations + DatabaseOps hasura.DatabaseOperations MetadataOps hasura.CommonMetadataOperations MigrationsStateStore statestore.MigrationsStateStore SettingsStateStore statestore.SettingsStateStore diff --git a/cli/migrate/database/types.go b/cli/migrate/database/types.go index 83e6072199944d..0759834b123807 100644 --- a/cli/migrate/database/types.go +++ b/cli/migrate/database/types.go @@ -32,7 +32,7 @@ func (c *CustomList) Iterate() linq.Iterator { } } -type Datasource struct { +type Database struct { Name string Type string } diff --git a/cli/migrate/util.go b/cli/migrate/util.go index ba70de9ba40449..9143ffe9b6284b 100644 --- a/cli/migrate/util.go +++ b/cli/migrate/util.go @@ -8,7 +8,7 @@ import ( "runtime" "strings" - "github.com/hasura/graphql-engine/cli/migrate/database" + migratedb "github.com/hasura/graphql-engine/cli/migrate/database" crontriggers "github.com/hasura/graphql-engine/cli/metadata/cron_triggers" @@ -123,27 +123,27 @@ func FilterCustomQuery(u *nurl.URL) *nurl.URL { return &ux } -func NewMigrate(ec *cli.ExecutionContext, isCmd bool, datasource string) (*Migrate, error) { - // create a new directory for the datasource if it does'nt exists - if f, _ := os.Stat(filepath.Join(ec.MigrationDir, datasource)); f == nil { - err := os.MkdirAll(filepath.Join(ec.MigrationDir, datasource), 0755) +func NewMigrate(ec *cli.ExecutionContext, isCmd bool, database string) (*Migrate, error) { + // create a new directory for the database if it does'nt exists + if f, _ := os.Stat(filepath.Join(ec.MigrationDir, database)); f == nil { + err := os.MkdirAll(filepath.Join(ec.MigrationDir, database), 0755) if err != nil { return nil, err } } dbURL := GetDataPath(ec) - fileURL := GetFilePath(filepath.Join(ec.MigrationDir, datasource)) + fileURL := GetFilePath(filepath.Join(ec.MigrationDir, database)) opts := NewMigrateOpts{ fileURL.String(), dbURL.String(), isCmd, int(ec.Config.Version), ec.Config.ServerConfig.TLSConfig, ec.Logger, - &database.HasuraOpts{ + &migratedb.HasuraOpts{ HasMetadataV3: ec.HasMetadataV3, - Datasource: datasource, + Database: database, Client: ec.APIClient, - DatasourceOps: cli.GetDatasourceOps(ec), + DatabaseOps: cli.GetDatabaseOps(ec), MetadataOps: cli.GetCommonMetadataOps(ec), MigrationsStateStore: cli.GetMigrationsStateStore(ec), SettingsStateStore: cli.GetSettingsStateStore(ec), diff --git a/cli/pkg/console/apiserver.go b/cli/pkg/console/apiserver.go index 84274c18abc263..ec8c484b643d1a 100644 --- a/cli/pkg/console/apiserver.go +++ b/cli/pkg/console/apiserver.go @@ -51,7 +51,7 @@ func cliProjectUpdateCheck(ec *cli.ExecutionContext) gin.HandlerFunc { } // if a user is on config v2 and they have multiple databases prompt them to upgrade if ec.Config.Version <= cli.V2 && ec.HasMetadataV3 { - sources, err := scripts.ListDatasources(ec.APIClient.V1Metadata) + sources, err := scripts.ListDatabases(ec.APIClient.V1Metadata) if err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, &response{Code: "internal_error", Message: errMessage{"cannot list sources"}.Error()}) return diff --git a/cli/seed/apply.go b/cli/seed/apply.go index 8bd09c8348efe3..8835fe8ed482c5 100644 --- a/cli/seed/apply.go +++ b/cli/seed/apply.go @@ -16,7 +16,7 @@ import ( // ApplySeedsToDatabase will read all .sql files in the given // directory and apply it to hasura -func ApplySeedsToDatabase(ec *cli.ExecutionContext, fs afero.Fs, m *migrate.Migrate, filenames []string, datasource string) error { +func ApplySeedsToDatabase(ec *cli.ExecutionContext, fs afero.Fs, m *migrate.Migrate, filenames []string, database string) error { seedQuery := hasuradb.HasuraInterfaceBulk{ Type: "bulk", Args: make([]interface{}, 0), @@ -32,8 +32,8 @@ func ApplySeedsToDatabase(ec *cli.ExecutionContext, fs afero.Fs, m *migrate.Migr q := hasuradb.HasuraInterfaceQuery{ Type: "run_sql", Args: hasuradb.RunSQLInput{ - Source: datasource, - SQL: string(b), + Source: database, + SQL: string(b), }, } seedQuery.Args = append(seedQuery.Args, q) @@ -51,8 +51,8 @@ func ApplySeedsToDatabase(ec *cli.ExecutionContext, fs afero.Fs, m *migrate.Migr q := hasuradb.HasuraInterfaceQuery{ Type: "run_sql", Args: hasuradb.RunSQLInput{ - SQL: string(b), - Source: datasource, + SQL: string(b), + Source: database, }, } seedQuery.Args = append(seedQuery.Args, q) diff --git a/cli/seed/create.go b/cli/seed/create.go index a85ff9e8a97f82..e3cfb468010363 100644 --- a/cli/seed/create.go +++ b/cli/seed/create.go @@ -20,7 +20,7 @@ type CreateSeedOpts struct { // DirectoryPath in which seed file should be created DirectoryPath string Data io.Reader - Datasource string + Database string } // CreateSeedFile creates a .sql file according to the arguments @@ -34,7 +34,7 @@ func CreateSeedFile(fs afero.Fs, opts CreateSeedOpts) (*string, error) { timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10) // filename will be in format _.sql filenameWithTimeStamp := fmt.Sprintf("%s_%s.%s", timestamp, opts.UserProvidedSeedName, fileExtension) - fullFilePath := filepath.Join(filepath.Join(opts.DirectoryPath, opts.Datasource), filenameWithTimeStamp) + fullFilePath := filepath.Join(filepath.Join(opts.DirectoryPath, opts.Database), filenameWithTimeStamp) // Write contents to file file, err := fs.OpenFile(fullFilePath, os.O_WRONLY|os.O_CREATE, 0644)