Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions internal/memdb/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed so we set parents implicitly via Copy (see also cloudquery/cloudquery#14637)

}

func (c *client) migrate(_ context.Context, table *schema.Table) {
Expand Down
9 changes: 5 additions & 4 deletions serve/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
})
Expand Down
4 changes: 2 additions & 2 deletions serve/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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{
Expand Down
21 changes: 21 additions & 0 deletions serve/testdata/memdbtables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
]