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
5 changes: 5 additions & 0 deletions .github/workflows/history_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
- name: Build
run: go build -v .

- name: Sanity Fetch with old version
run: go run ./main.go fetch --config=internal/test/test_history_config_oldversion.hcl --enable-console-log
env:
CQ_NO_TELEMETRY: 1

- name: Sanity Fetch
run: go run ./main.go fetch --config=internal/test/test_history_config.hcl --enable-console-log
env:
Expand Down
25 changes: 25 additions & 0 deletions internal/test/test_history_config_oldversion.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cloudquery {

connection {
dsn = "tsdb://postgres:pass@localhost:5432/postgres?sslmode=disable"
}
provider "test" {
version = "v0.0.10"
}
history {
// Save data retention for 7 days
retention = 7
// Truncate our fetch by 6 hours per fetch
truncation = 6
}

}

// All Provider Configurations
provider "test" {
configuration {}

resources = [
"slow_resource"
]
}
30 changes: 30 additions & 0 deletions pkg/client/database/timescale/ddlmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ func NewDDLManager(l hclog.Logger, conn *pgxpool.Conn, cfg *history.Config, dt s
}, nil
}

// PrepareHistory is run before any migrations
func (h DDLManager) PrepareHistory(ctx context.Context, conn *pgxpool.Conn) error {
if err := AddHistoryFunctions(ctx, conn); err != nil {
return fmt.Errorf("AddHistoryFunctions failed: %w", err)
}

// we need to drop the views before underlying tables can be modified
return h.dropViews(ctx, conn)
}

// SetupHistory is run after any migrations, finalizing history setup
func (h DDLManager) SetupHistory(ctx context.Context, conn *pgxpool.Conn) error {
var tables []string
if err := pgxscan.Select(ctx, conn, &tables, listHyperTables, history.SchemaName); err != nil {
Expand Down Expand Up @@ -82,6 +93,25 @@ func (h DDLManager) configureHyperTable(ctx context.Context, conn *pgxpool.Conn,
return nil
}

func (h DDLManager) dropViews(ctx context.Context, conn *pgxpool.Conn) error {
var tables []string
if err := pgxscan.Select(ctx, conn, &tables, listHyperTables, history.SchemaName); err != nil {
return fmt.Errorf("failed to list hypertables: %w", err)
}

if err := conn.BeginTxFunc(ctx, pgx.TxOptions{}, func(tx pgx.Tx) error {
for _, table := range tables {
if _, err := tx.Exec(ctx, fmt.Sprintf(dropTableView, table)); err != nil {
return fmt.Errorf("failed to drop view for table: %w", err)
}
}
return nil
}); err != nil {
return err
}
return nil
}

func (h DDLManager) recreateView(ctx context.Context, conn *pgxpool.Conn, table string) error {
if err := conn.BeginTxFunc(ctx, pgx.TxOptions{}, func(tx pgx.Tx) error {
// Must drop the view first -- CREATE OR REPLACE view won't cut it if columns are changed. PostgreSQL doc states:
Expand Down
8 changes: 6 additions & 2 deletions pkg/client/database/timescale/timescale.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ func (e Executor) Setup(ctx context.Context) (string, error) {
}
defer conn.Release()

if err := AddHistoryFunctions(ctx, conn); err != nil {
return e.dsn, fmt.Errorf("failed to create history functions: %w", err)
ddl, err := NewDDLManager(e.logger, conn, e.cfg, schema.TSDB)
if err != nil {
return e.dsn, err
}
if err := ddl.PrepareHistory(ctx, conn); err != nil {
return e.dsn, fmt.Errorf("failed to prepare history: %w", err)
}

return history.TransformDSN(e.dsn)
Expand Down
5 changes: 5 additions & 0 deletions pkg/module/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package module
import (
"context"
"fmt"
"sort"
"strings"

"github.com/cloudquery/cq-provider-sdk/cqproto"
Expand Down Expand Up @@ -168,6 +169,10 @@ func versionError(modName string, modVersions []uint32, provVersions map[string]
}
}

sort.Strings(unsupportingProviders)
sort.Strings(olderProviders)
sort.Strings(newerProviders)

if l := len(unsupportingProviders); l == 1 {
return fmt.Errorf("provider %s doesn't support %s yet", unsupportingProviders[0], modName)
} else if l > 1 {
Expand Down