Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

feat: Testable Migrations (AWS) #401

Merged
merged 28 commits into from
Jan 20, 2022
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
40 changes: 11 additions & 29 deletions .github/workflows/test_migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
id: cache-migrations
uses: actions/cache@v2
with:
path: resources/migrations
key: ${{ runner.os }}-${{ hashFiles('resources/migrations') }}
path: resources/provider/migrations
key: ${{ runner.os }}-${{ hashFiles('resources/provider/migrations') }}

test_migration:
needs: should_run
Expand Down Expand Up @@ -58,39 +58,21 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Cache CQ
id: cache-cq-binary
uses: actions/cache@v2
with:
path: cloudquery
key: ${{ runner.os }}-${{ hashFiles('cloudquery') }}

- name: Download Cloudquery
if: steps.cache-cq-binary.cache-hit != 'true'
run: |
curl -L https://github.com/cloudquery/cloudquery/releases/latest/download/cloudquery_${OS}_x86_64 -o cloudquery
chmod a+x cloudquery
env:
OS: Linux

- name: Build initial schema
run: |
CQ_NO_TELEMETRY=1 ./cloudquery provider build-schema aws --config ./client/testdata/initial_migration.hcl --enable-console-log
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v .

- name: Run upgrade
- name: Test migrations for Postgres
run: |
go test -v ./resources/provider/provider_test.go
env:
CQ_MIGRATION_TEST_DSN: postgres://postgres:pass@localhost:5432/postgres?sslmode=disable

- name: Test migrations for Timescale
run: |
rm -rf .cq_reattach
go run main.go & while [ ! -f .cq_reattach ]; do sleep 1; done && \
./cloudquery provider upgrade aws --config ./client/testdata/default.hcl --enable-console-log
go test -v ./resources/provider/provider_test.go
env:
CQ_PROVIDER_DEBUG: 1
CQ_REATTACH_PROVIDERS: .cq_reattach
CQ_NO_TELEMETRY: 1
CQ_MIGRATION_TEST_DSN: tsdb://postgres:pass@localhost:5432/postgres?sslmode=disable

- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
Expand Down
7 changes: 4 additions & 3 deletions client/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/apigateway/types"
Expand All @@ -28,7 +29,7 @@ func TestResolveARN(t *testing.T) {
func(resource *schema.Resource) ([]string, error) {
return []string{"restapis", *resource.Item.(types.RestApi).Id}, nil
},
schema.NewResourceData(&schema.Table{Columns: []schema.Column{{Name: "myarn"}}}, nil, types.RestApi{Id: aws.String("myid")}, nil),
schema.NewResourceData(&schema.PostgresDialect{}, &schema.Table{Columns: []schema.Column{{Name: "myarn"}}}, nil, types.RestApi{Id: aws.String("myid")}, nil, time.Now()),
"arn:aws:apigateway:region::restapis/myid",
false,
},
Expand All @@ -39,7 +40,7 @@ func TestResolveARN(t *testing.T) {
func(resource *schema.Resource) ([]string, error) {
return []string{"", "restapis", *resource.Item.(types.RestApi).Id}, nil
},
schema.NewResourceData(&schema.Table{Columns: []schema.Column{{Name: "myarn"}}}, nil, types.RestApi{Id: aws.String("myid")}, nil),
schema.NewResourceData(&schema.PostgresDialect{}, &schema.Table{Columns: []schema.Column{{Name: "myarn"}}}, nil, types.RestApi{Id: aws.String("myid")}, nil, time.Now()),
"arn:aws:apigateway:region::/restapis/myid",
false,
},
Expand All @@ -50,7 +51,7 @@ func TestResolveARN(t *testing.T) {
func(resource *schema.Resource) ([]string, error) {
return nil, errors.New("test")
},
schema.NewResourceData(&schema.Table{Columns: []schema.Column{{Name: "myarn"}}}, nil, types.RestApi{Id: aws.String("myid")}, nil),
schema.NewResourceData(&schema.PostgresDialect{}, &schema.Table{Columns: []schema.Column{{Name: "myarn"}}}, nil, types.RestApi{Id: aws.String("myid")}, nil, time.Now()),
nil,
true,
},
Expand Down
19 changes: 0 additions & 19 deletions client/testdata/initial_migration.hcl

This file was deleted.

13 changes: 4 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.1.2
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.1.2
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.1.2
github.com/aws/aws-sdk-go-v2/service/codebuild v1.14.1
github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.3.1
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.3.3
github.com/aws/aws-sdk-go-v2/service/configservice v1.5.1
Expand Down Expand Up @@ -45,6 +46,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/rds v1.2.1
github.com/aws/aws-sdk-go-v2/service/redshift v1.3.0
github.com/aws/aws-sdk-go-v2/service/route53 v1.4.0
github.com/aws/aws-sdk-go-v2/service/route53domains v1.6.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.19.1
github.com/aws/aws-sdk-go-v2/service/s3control v1.14.1
github.com/aws/aws-sdk-go-v2/service/sagemaker v1.19.1
Expand All @@ -57,10 +59,11 @@ require (
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.5.1
github.com/aws/smithy-go v1.9.1
github.com/bxcodec/faker v2.0.1+incompatible
github.com/cloudquery/cq-provider-sdk v0.6.1
github.com/cloudquery/cq-provider-sdk v0.7.0-alpha2
github.com/cloudquery/faker/v3 v3.7.5
github.com/gocarina/gocsv v0.0.0-20210516172204-ca9e8a8ddea8
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.6
github.com/hashicorp/go-hclog v1.0.0
github.com/mitchellh/mapstructure v1.4.2
github.com/spf13/cast v1.4.1
Expand Down Expand Up @@ -96,8 +99,6 @@ require (
github.com/hashicorp/go-version v1.3.0 // indirect
github.com/hashicorp/hcl/v2 v2.10.1 // indirect
github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 // indirect
github.com/huandu/go-sqlbuilder v1.13.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.10.0 // indirect
Expand Down Expand Up @@ -145,9 +146,3 @@ require (
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

require (
github.com/aws/aws-sdk-go-v2/service/codebuild v1.14.1
github.com/aws/aws-sdk-go-v2/service/route53domains v1.6.0
github.com/google/go-cmp v0.5.6
)
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ github.com/cilium/ebpf v0.4.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJ
github.com/cilium/ebpf v0.6.2/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cloudquery/cq-provider-sdk v0.6.1 h1:pyHabGR81AdsnwtZF0oaJhF9VPK5tHiC8DukA5JEW/A=
github.com/cloudquery/cq-provider-sdk v0.6.1/go.mod h1:lLjzStk8uqMiunTDnAp26QXyQ3XAMexOqzuo8T2riMc=
github.com/cloudquery/cq-provider-sdk v0.7.0-alpha2 h1:GY0NJLEYf5JSHluVJsdAfFN00ygX5A+HZHw6/LDif5Q=
github.com/cloudquery/cq-provider-sdk v0.7.0-alpha2/go.mod h1:T+ngRXzcjJ6otKDGkWnPrHTsZuHUe3KZKtyhSLcvHCs=
github.com/cloudquery/faker/v3 v3.7.4/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
github.com/cloudquery/faker/v3 v3.7.5 h1:G7ANdEEcm8TvAAjIwNWSLrYK36CFCiSlrCqOTGCccL0=
github.com/cloudquery/faker/v3 v3.7.5/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
Expand Down Expand Up @@ -369,8 +369,8 @@ github.com/containerd/containerd v1.5.0-beta.1/go.mod h1:5HfvG1V2FsKesEGQ17k5/T7
github.com/containerd/containerd v1.5.0-beta.3/go.mod h1:/wr9AVtEM7x9c+n0+stptlo/uBBoBORwEx6ardVcmKU=
github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09ZvgqEq8EfBp/m3lcVZIvPHhI=
github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoTJseu1FGOKuoA4nNb2s=
github.com/containerd/containerd v1.5.8 h1:NmkCC1/QxyZFBny8JogwLpOy2f+VEbO/f6bV2Mqtwuw=
github.com/containerd/containerd v1.5.8/go.mod h1:YdFSv5bTFLpG2HIYmfqDpSYYTDX+mc5qtSuYx1YUb/s=
github.com/containerd/containerd v1.5.9 h1:rs6Xg1gtIxaeyG+Smsb/0xaSDu1VgFhOCKBXxMxbsF4=
github.com/containerd/containerd v1.5.9/go.mod h1:fvQqCfadDGga5HZyn3j4+dx56qj2I9YwBrlSdalvJYQ=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20191127005431-f65d91d395eb/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
Expand Down Expand Up @@ -720,12 +720,6 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKe
github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 h1:brI5vBRUlAlM34VFmnLPwjnCL/FxAJp9XvOdX6Zt+XE=
github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
github.com/huandu/go-sqlbuilder v1.13.0 h1:IN1VRzcyQ+Kx74L0g5ZAY5qDaRJjwMWVmb6GrFAF8Jc=
github.com/huandu/go-sqlbuilder v1.13.0/go.mod h1:LILlbQo0MOYjlIiGgOSR3UcWQpd5Y/oZ7HLNGyAUz0E=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
2 changes: 0 additions & 2 deletions resources/provider/migrations/10_v0.8.3.down.sql

This file was deleted.

2 changes: 0 additions & 2 deletions resources/provider/migrations/10_v0.8.3.up.sql

This file was deleted.

6 changes: 0 additions & 6 deletions resources/provider/migrations/11_v0.8.4.down.sql

This file was deleted.

2 changes: 0 additions & 2 deletions resources/provider/migrations/11_v0.8.4.up.sql

This file was deleted.

5 changes: 0 additions & 5 deletions resources/provider/migrations/12_v0.8.5.down.sql

This file was deleted.

6 changes: 0 additions & 6 deletions resources/provider/migrations/12_v0.8.5.up.sql

This file was deleted.

100 changes: 0 additions & 100 deletions resources/provider/migrations/13_v0.9.0.down.sql

This file was deleted.

18 changes: 0 additions & 18 deletions resources/provider/migrations/13_v0.9.0.up.sql

This file was deleted.

Loading