github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/serversettings/setup.go (about) 1 package serversettings 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/turbot/steampipe/pkg/constants" 8 "github.com/turbot/steampipe/pkg/db/db_common" 9 ) 10 11 func GetPopulateServerSettingsSql(ctx context.Context, settings db_common.ServerSettings) db_common.QueryWithArgs { 12 return db_common.QueryWithArgs{ 13 Query: fmt.Sprintf(`INSERT INTO %s.%s ( 14 start_time, 15 steampipe_version, 16 fdw_version, 17 cache_max_ttl, 18 cache_max_size_mb, 19 cache_enabled) 20 VALUES($1,$2,$3,$4,$5,$6)`, constants.InternalSchema, constants.ServerSettingsTable), 21 Args: []any{ 22 settings.StartTime, 23 settings.SteampipeVersion, 24 settings.FdwVersion, 25 settings.CacheMaxTtl, 26 settings.CacheMaxSizeMb, 27 settings.CacheEnabled, 28 }, 29 } 30 } 31 32 func CreateServerSettingsTable(ctx context.Context) db_common.QueryWithArgs { 33 return db_common.QueryWithArgs{ 34 Query: fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s.%s ( 35 start_time TIMESTAMPTZ NOT NULL, 36 steampipe_version TEXT NOT NULL, 37 fdw_version TEXT NOT NULL, 38 cache_max_ttl INTEGER NOT NULL, 39 cache_max_size_mb INTEGER NOT NULL, 40 cache_enabled BOOLEAN NOT NULL 41 );`, constants.InternalSchema, constants.ServerSettingsTable), 42 } 43 } 44 45 func GrantsOnServerSettingsTable(ctx context.Context) db_common.QueryWithArgs { 46 return db_common.QueryWithArgs{ 47 Query: fmt.Sprintf( 48 `GRANT SELECT ON TABLE %s.%s to %s;`, 49 constants.InternalSchema, 50 constants.ServerSettingsTable, 51 constants.DatabaseUsersRole, 52 ), 53 } 54 } 55 56 func DropServerSettingsTable(ctx context.Context) db_common.QueryWithArgs { 57 return db_common.QueryWithArgs{ 58 Query: fmt.Sprintf( 59 `DROP TABLE IF EXISTS %s.%s;`, 60 constants.InternalSchema, 61 constants.ServerSettingsTable, 62 ), 63 } 64 }