Skip to content

Commit cb78111

Browse files
committed
Remove 'steampipe_command' schema and move settings and scan_metadata foreign tables to 'steampipe_internal' schema. Closes #310
1 parent d04be88 commit cb78111

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

fdw.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func goFdwGetPathKeys(state *C.FdwPlanState) *C.List {
125125
// get the connection name - this is the namespace (i.e. the local schema)
126126
opts["connection"] = getNamespace(rel)
127127

128-
if opts["connection"] == constants.CommandSchema {
128+
if opts["connection"] == constants.InternalSchema {
129129
return result
130130
}
131131

@@ -389,7 +389,7 @@ func goFdwImportForeignSchema(stmt *C.ImportForeignSchemaStmt, serverOid C.Oid)
389389
}
390390
}()
391391

392-
log.Printf("[WARN] goFdwImportForeignSchema remote '%s' local '%s'\n", C.GoString(stmt.remote_schema), C.GoString(stmt.local_schema))
392+
log.Printf("[INFO] goFdwImportForeignSchema remote '%s' local '%s'\n", C.GoString(stmt.remote_schema), C.GoString(stmt.local_schema))
393393
// get the plugin hub,
394394
pluginHub, err := hub.GetHub()
395395
if err != nil {
@@ -402,9 +402,10 @@ func goFdwImportForeignSchema(stmt *C.ImportForeignSchemaStmt, serverOid C.Oid)
402402
localSchema := C.GoString(stmt.local_schema)
403403

404404
// special handling for the command schema
405-
if remoteSchema == constants.CommandSchema {
406-
commandSchema := pluginHub.GetCommandSchema()
407-
sql := SchemaToSql(commandSchema, stmt, serverOid)
405+
if remoteSchema == constants.InternalSchema {
406+
log.Printf("[INFO] importing setting tables into steampipe_internal schema")
407+
settingsSchema := pluginHub.GetSettingsSchema()
408+
sql := SchemaToSql(settingsSchema, stmt, serverOid)
408409
return sql
409410
}
410411

@@ -435,7 +436,7 @@ func goFdwExecForeignInsert(estate *C.EState, rinfo *C.ResultRelInfo, slot *C.Tu
435436
defer C.RelationClose(rel)
436437
connection := getNamespace(rel)
437438
// if this is a command insert, handle it
438-
if connection == constants.CommandSchema {
439+
if connection == constants.InternalSchema {
439440
return handleCommandInsert(rinfo, slot, rel)
440441
}
441442

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require (
88
github.com/hashicorp/go-hclog v1.5.0
99
github.com/hashicorp/go-version v1.6.0 // indirect
1010
github.com/turbot/go-kit v0.6.0-alpha.1
11-
// schema_import
12-
github.com/turbot/steampipe v1.7.0-rc.0.0.20230515091940-efbd4045e27e
11+
// remove_steampipe_command
12+
github.com/turbot/steampipe v1.7.0-rc.0.0.20230516153230-a938a696d29e
1313
github.com/turbot/steampipe-plugin-sdk/v5 v5.4.1
1414
go.opentelemetry.io/otel v1.10.0
1515
google.golang.org/protobuf v1.30.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1
904904
github.com/tombuildsstuff/giovanni v0.15.1/go.mod h1:0TZugJPEtqzPlMpuJHYfXY6Dq2uLPrXf98D2XQSxNbA=
905905
github.com/turbot/go-kit v0.6.0-alpha.1 h1:mm1QpkwknuJQfA7oKzyzMiDRx5GsKlzxwsNa7n+Ttj4=
906906
github.com/turbot/go-kit v0.6.0-alpha.1/go.mod h1:oP9gLk6bETL4nkEuujZZbOlcv9jnHQlf7DYcI/+Ke8Q=
907-
github.com/turbot/steampipe v1.7.0-rc.0.0.20230515091940-efbd4045e27e h1:A5F7NT23yBROgPkJXE+pxRQomFTS8S+kZblREJ1CALQ=
908-
github.com/turbot/steampipe v1.7.0-rc.0.0.20230515091940-efbd4045e27e/go.mod h1:sDC02Vc5RYn/FqZ3vpuWlMqmawR7J2jwIC9Q33qWgnE=
907+
github.com/turbot/steampipe v1.7.0-rc.0.0.20230516153230-a938a696d29e h1:xHKqH1CueFpviC1SAeQhmfxS5e4Mfn/jp/b7QRRLZm4=
908+
github.com/turbot/steampipe v1.7.0-rc.0.0.20230516153230-a938a696d29e/go.mod h1:sDC02Vc5RYn/FqZ3vpuWlMqmawR7J2jwIC9Q33qWgnE=
909909
github.com/turbot/steampipe-plugin-sdk/v5 v5.4.1 h1:1d2Rt4SH9D/lnLhi7e7Zhv6d7OX8PzwKzCBbyvSeD+o=
910910
github.com/turbot/steampipe-plugin-sdk/v5 v5.4.1/go.mod h1:bfvdKaLwemr13EPOMbnr7/hOQOO7m4oM7HnVMdNotgY=
911911
github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=

hub/hub.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (h *Hub) GetIterator(columns []string, quals *proto.Quals, unhandledRestric
287287
table := opts["table"]
288288
log.Printf("[TRACE] Hub GetIterator() table '%s'", table)
289289

290-
if connectionName == constants.CommandSchema {
290+
if connectionName == constants.InternalSchema {
291291
return h.executeCommandScan(table)
292292
}
293293

@@ -848,7 +848,7 @@ func (h *Hub) ApplySetting(key string, value string) error {
848848
return h.cacheSettings.Apply(key, value)
849849
}
850850

851-
func (h *Hub) GetCommandSchema() map[string]*proto.TableSchema {
851+
func (h *Hub) GetSettingsSchema() map[string]*proto.TableSchema {
852852
return map[string]*proto.TableSchema{
853853
constants.CommandTableSettings: {
854854
Columns: []*proto.ColumnDefinition{
@@ -896,7 +896,7 @@ func (h *Hub) executeCommandScan(table string) (Iterator, error) {
896896
for i, m := range h.scanMetadata {
897897
res.Rows[i] = m.AsResultRow()
898898
}
899-
return newInMemoryIterator(constants.CommandSchema, res), nil
899+
return newInMemoryIterator(constants.InternalSchema, res), nil
900900
default:
901901
return nil, fmt.Errorf("cannot select from command table '%s'", table)
902902
}

sql/sql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func GetSQLForTable(table string, tableSchema *proto.TableSchema, localSchema st
3131
columnsString = append(columnsString, fmt.Sprintf("%s %s%s", column, t, trailing))
3232
}
3333

34-
sql := fmt.Sprintf(`create foreign table %s.%s
34+
sql := fmt.Sprintf(`CREATE FOREIGN TABLE IF NOT EXISTS %s.%s
3535
(
3636
%s
3737
)
38-
server %s OPTIONS (table %s)`,
38+
SERVER %s OPTIONS (table %s)`,
3939
localSchema,
4040
escapedTableName,
4141
strings.Join(columnsString, "\n "),

0 commit comments

Comments
 (0)