Skip to content

Commit

Permalink
feat(migrations): add cloud integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
grandwizard28 committed Jan 14, 2025
1 parent 39e8223 commit 67034a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
31 changes: 0 additions & 31 deletions pkg/query-service/app/cloudintegrations/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,11 @@ type cloudProviderAccountsRepository interface {
func newCloudProviderAccountsRepository(db *sqlx.DB) (
*cloudProviderAccountsSQLRepository, error,
) {
if err := InitSqliteDBIfNeeded(db); err != nil {
return nil, fmt.Errorf("could not init sqlite DB for cloudintegrations: %w", err)
}

return &cloudProviderAccountsSQLRepository{
db: db,
}, nil
}

func InitSqliteDBIfNeeded(db *sqlx.DB) error {
if db == nil {
return fmt.Errorf("db is required")
}

createTablesStatements := `
CREATE TABLE IF NOT EXISTS cloud_integrations_accounts(
cloud_provider TEXT NOT NULL,
id TEXT NOT NULL,
config_json TEXT,
cloud_account_id TEXT,
last_agent_report_json TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
removed_at TIMESTAMP,
UNIQUE(cloud_provider, id)
)
`
_, err := db.Exec(createTablesStatements)
if err != nil {
return fmt.Errorf(
"could not ensure cloud provider integrations schema in sqlite DB: %w", err,
)
}

return nil
}

type cloudProviderAccountsSQLRepository struct {
db *sqlx.DB
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/sqlstore/migrations/007_add_integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ func (migration *addIntegrations) Up(ctx context.Context, db *bun.DB) error {
return err
}

if _, err := db.ExecContext(ctx, `CREATE TABLE IF NOT EXISTS cloud_integrations_accounts(
cloud_provider TEXT NOT NULL,
id TEXT NOT NULL,
config_json TEXT,
cloud_account_id TEXT,
last_agent_report_json TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
removed_at TIMESTAMP,
UNIQUE(cloud_provider, id)
)`); err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 67034a5

Please sign in to comment.