diff --git a/internal/memdb/memdb.go b/internal/memdb/memdb.go index 479596baae..e34cff3b68 100644 --- a/internal/memdb/memdb.go +++ b/internal/memdb/memdb.go @@ -72,6 +72,22 @@ func GetNewClient(options ...Option) plugin.NewClientFunc { Unique: false, }, }, + Relations: schema.Tables{ + { + Name: "table3", + Columns: []schema.Column{ + { + Name: "col1", + Type: types.UUID, + Description: "col1 description", + PrimaryKey: false, + NotNull: false, + IncrementalKey: true, + Unique: false, + }, + }, + }, + }, }, }, }, @@ -165,12 +181,12 @@ func (c *client) Sync(_ context.Context, options plugin.SyncOptions, res chan<- return nil } -func (c *client) Tables(context.Context, plugin.TableOptions) (schema.Tables, error) { +func (c *client) Tables(_ context.Context, opts plugin.TableOptions) (schema.Tables, error) { tables := make(schema.Tables, 0, len(c.tables)) for _, table := range c.tables { tables = append(tables, table) } - return tables, nil + return tables.FilterDfs(opts.Tables, opts.SkipTables, opts.SkipDependentTables) } func (c *client) migrate(_ context.Context, table *schema.Table) { diff --git a/serve/package.go b/serve/package.go index a95cd9ee3d..7697de6251 100644 --- a/serve/package.go +++ b/serve/package.go @@ -64,10 +64,11 @@ func (s *PluginServe) writeTablesJSON(ctx context.Context, dir string) error { if table.Parent != nil { parent = &table.Parent.Name } - var relations *[]string + relations := make([]string, 0, len(table.Relations)) if table.Relations != nil { - names := table.Relations.TableNames() - relations = &names + for _, relation := range table.Relations { + relations = append(relations, relation.Name) + } } columns := make([]cloudquery_api.PluginTableColumn, 0, len(table.Columns)) for _, column := range table.Columns { @@ -86,7 +87,7 @@ func (s *PluginServe) writeTablesJSON(ctx context.Context, dir string) error { IsIncremental: &table.IsIncremental, Name: table.Name, Parent: parent, - Relations: relations, + Relations: &relations, Title: &table.Title, Columns: &columns, }) diff --git a/serve/plugin_test.go b/serve/plugin_test.go index e1546cbc11..5cd43500b1 100644 --- a/serve/plugin_test.go +++ b/serve/plugin_test.go @@ -67,7 +67,7 @@ func TestPluginServe(t *testing.T) { t.Fatal(err) } - getTablesRes, err := c.GetTables(ctx, &pb.GetTables_Request{}) + getTablesRes, err := c.GetTables(ctx, &pb.GetTables_Request{Tables: []string{"*"}}) if err != nil { t.Fatal(err) } @@ -80,7 +80,7 @@ func TestPluginServe(t *testing.T) { t.Fatal(err) } - if len(tables) != 2 { + if len(tables) != 3 { t.Fatalf("Expected 2 tables but got %d", len(tables)) } testTable := schema.Table{ diff --git a/serve/testdata/memdbtables.json b/serve/testdata/memdbtables.json index a9e5335ebd..87c46344d4 100644 --- a/serve/testdata/memdbtables.json +++ b/serve/testdata/memdbtables.json @@ -30,8 +30,29 @@ } ], "description": "", + "parent": "table1", + "relations": ["table3"], "is_incremental": false, "name": "table2", "title": "" + }, + { + "columns": [ + { + "description": "col1 description", + "incremental_key": true, + "name": "col1", + "not_null": false, + "primary_key": false, + "type": "uuid", + "unique": false + } + ], + "description": "", + "parent": "table2", + "relations": [], + "is_incremental": false, + "name": "table3", + "title": "" } ]