diff --git a/.github/workflows/ci-go.yaml b/.github/workflows/ci-go.yaml index 1dc27015..5ecd5085 100644 --- a/.github/workflows/ci-go.yaml +++ b/.github/workflows/ci-go.yaml @@ -65,6 +65,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: ariga/setup-atlas@v0 + with: + cloud-token: ${{ secrets.ATLAS_TOKEN }} - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: diff --git a/atlasaction/action.go b/atlasaction/action.go index 4974250b..c59a9684 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -604,7 +604,11 @@ func (a *Actions) SchemaPlan(ctx context.Context) error { a.SetOutput("plan", plan.File.URL) a.SetOutput("status", plan.File.Status) // Report the schema plan to the user and add a comment to the PR. - summary, err := schemaPlanComment(plan, params.Env, tc.RerunCmd) + summary, err := RenderTemplate("schema-plan.tmpl", map[string]any{ + "Plan": plan, + "EnvName": params.Env, + "RerunCommand": tc.RerunCmd, + }) if err != nil { return fmt.Errorf("failed to generate schema plan comment: %w", err) } @@ -925,19 +929,6 @@ func (a *Actions) addSuggestions(lint *atlasexec.SummaryReport, fn func(*Suggest return nil } -func schemaPlanComment(payload *atlasexec.SchemaPlan, envName, rerun string) (string, error) { - data := map[string]any{ - "Plan": payload, - "EnvName": envName, - "RerunCommand": rerun, - } - var buf bytes.Buffer - if err := commentsTmpl.ExecuteTemplate(&buf, "schema-plan.tmpl", data); err != nil { - return "", err - } - return buf.String(), nil -} - func execTime(start, end time.Time) string { return end.Sub(start).String() } diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go index 8389f7ac..4b58ad81 100644 --- a/atlasaction/action_test.go +++ b/atlasaction/action_test.go @@ -1272,7 +1272,7 @@ func TestLintTemplateGeneration(t *testing.T) { Files: []*atlasexec.FileReport{{Name: "20230925192914.sql"}}, }, // language=html - expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
1 new migration file detected20230925192914.sql
ERD and visual diff generatedView Visualization
No issues foundView Report
Read the full linting report on Atlas Cloud
", + expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
1 new migration file detected20230925192914.sql
ERD and visual diff generatedView Visualization
No issues foundView Report
Read the full linting report on Atlas Cloud
", }, { name: "file with 2 issues", @@ -1333,7 +1333,7 @@ func TestLintTemplateGeneration(t *testing.T) { }}, }, // language=html - expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
1 new migration file detected20230925192914.sql
ERD and visual diff generatedView Visualization
Analyze 20230925192914.sql
2 reports were found in analysis
Data dependent changes detected
Adding a unique index \"idx_unique_fullname\" on table \"Persons\" might fail in case columns \"FirstName\", \"LastName\" contain duplicate entries (MF101)
Adding a non-nullable \"varchar\" column \"City\" on table \"Persons\" without a default value implicitly sets existing rows with \"\" (MY101)
Read the full linting report on Atlas Cloud
", + expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
1 new migration file detected20230925192914.sql
ERD and visual diff generatedView Visualization
Analyze 20230925192914.sql
2 reports were found in analysis
Data dependent changes detected
Adding a unique index \"idx_unique_fullname\" on table \"Persons\" might fail in case columns \"FirstName\", \"LastName\" contain duplicate entries (MF101)
Adding a non-nullable \"varchar\" column \"City\" on table \"Persons\" without a default value implicitly sets existing rows with \"\" (MY101)
Read the full linting report on Atlas Cloud
", }, { name: "2 files, 1 with error, 1 with issue", @@ -1411,7 +1411,7 @@ func TestLintTemplateGeneration(t *testing.T) { }, }, // language=html - expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
2 new migration files detected20230925192914.sql
20230925192915.sql
ERD and visual diff generatedView Visualization
Analyze 20230925192914.sql
1 reports were found in analysis
Data dependent changes detected
Adding a unique index \"idx_unique_fullname\" on table \"Persons\" might fail in case columns \"FirstName\", \"LastName\" contain duplicate entries (MF101)
Analyze 20240625104520_destructive.sql
1 reports were found in analysis
Destructive changes detected
Dropping table \"Persons\" (DS102)
Read the full linting report on Atlas Cloud
", + expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
2 new migration files detected20230925192914.sql
20230925192915.sql
ERD and visual diff generatedView Visualization
Analyze 20230925192914.sql
1 reports were found in analysis
Data dependent changes detected
Adding a unique index \"idx_unique_fullname\" on table \"Persons\" might fail in case columns \"FirstName\", \"LastName\" contain duplicate entries (MF101)
Analyze 20240625104520_destructive.sql
1 reports were found in analysis
Destructive changes detected
Dropping table \"Persons\" (DS102)
Read the full linting report on Atlas Cloud
", }, { name: "1 checksum error", @@ -1433,7 +1433,7 @@ func TestLintTemplateGeneration(t *testing.T) { }}, }, // language=html - expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
1 new migration file detected20230925192914.sql
ERD and visual diff generatedView Visualization
Migration Integrity Check
File atlas.sum is invalid
checksum mismatch
Read the full linting report on Atlas Cloud
", + expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
1 new migration file detected20230925192914.sql
ERD and visual diff generatedView Visualization
Migration Integrity Check
File atlas.sum is invalid
checksum mismatch
Read the full linting report on Atlas Cloud
", }, { name: "non linear history error", @@ -1466,7 +1466,7 @@ func TestLintTemplateGeneration(t *testing.T) { }, }, // language=html - expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
No migration files detected 
ERD and visual diff generatedView Visualization
Detected 1 non-additive change
Pulling the the latest git changes might fix this warning
File 20240613102407.sql is missing or has been removed. Changes that have already been applied will not be reverted
Read the full linting report on Atlas Cloud
", + expected: "atlas migrate lint on testdata/migrations\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
StatusStepResult
No migration files detected 
ERD and visual diff generatedView Visualization
Detected 1 non-additive change
Pulling the the latest git changes might fix this warning
File 20240613102407.sql is missing or has been removed. Changes that have already been applied will not be reverted
Read the full linting report on Atlas Cloud
", }, } { t.Run(tt.name, func(t *testing.T) { diff --git a/atlasaction/comments/lint-report.tmpl b/atlasaction/comments/lint-report.tmpl index d0b2442c..5a1cff69 100644 --- a/atlasaction/comments/lint-report.tmpl +++ b/atlasaction/comments/lint-report.tmpl @@ -1,37 +1,4 @@ {{- define "lint-report" -}} - - - - - - - - - - - {{- block "lint-first-step" . -}} - {{- template "lint-check" "success.svg" -}} - - - {{- end -}} - {{- with .URL -}} {{- template "lint-check" "success.svg" -}} @@ -74,8 +41,6 @@ {{- with .URL -}} {{- end -}} - -
StatusStepResult
- {{- $fileCount := len .Files -}} - {{- if eq $fileCount 1 -}} - 1 new migration file detected - {{- else if $fileCount -}} - {{- $fileCount }} new migration files detected - {{- else -}} - No migration files detected - {{- end -}} - - {{- with .Files -}} - {{- range $i, $f := . -}} - {{- if $i -}}
{{- end -}}{{- $f.Name -}} - {{- end -}} - {{- else -}} -   - {{- end -}} -
Read the full linting report on {{ . | link "Atlas Cloud" -}}
{{- end -}} {{- define "lint-check" -}}
{{- assetsImage . | image "20px" -}}
diff --git a/atlasaction/comments/migrate-lint.tmpl b/atlasaction/comments/migrate-lint.tmpl index 20ae6c53..a97bcd22 100644 --- a/atlasaction/comments/migrate-lint.tmpl +++ b/atlasaction/comments/migrate-lint.tmpl @@ -1,2 +1,33 @@ -atlas migrate lint on {{- .Env.Dir }} +atlas migrate lint on {{- .Env.Dir }} + + + + + + + + + +{{- template "lint-check" "success.svg" -}} + + + {{- template "lint-report" . -}} +
StatusStepResult
+ {{- $fileCount := len .Files -}} + {{- if eq $fileCount 1 -}} + 1 new migration file detected + {{- else if $fileCount -}} + {{- $fileCount }} new migration files detected + {{- else -}} + No migration files detected + {{- end -}} + + {{- with .Files -}} + {{- range $i, $f := . -}} + {{- if $i -}}
{{- end -}}{{- $f.Name -}} + {{- end -}} + {{- else -}} +   + {{- end -}} +
\ No newline at end of file diff --git a/atlasaction/comments/schema-apply.tmpl b/atlasaction/comments/schema-apply.tmpl index d5fe6e1c..f829923a 100644 --- a/atlasaction/comments/schema-apply.tmpl +++ b/atlasaction/comments/schema-apply.tmpl @@ -52,7 +52,7 @@ {{- .File.Migration | codeblock "sql" | details (printf "📄 View %s Statements" $kind) -}} {{- with .Lint -}}

Atlas lint results

- {{- template "lint-report" . -}} + {{- template "schema-lint" $ -}} {{- end -}} {{/* Fallback to the old output */}} {{- else with .Changes -}} diff --git a/atlasaction/comments/schema-plan.tmpl b/atlasaction/comments/schema-plan.tmpl index d90b326d..8069ac98 100644 --- a/atlasaction/comments/schema-plan.tmpl +++ b/atlasaction/comments/schema-plan.tmpl @@ -2,7 +2,7 @@

SQL Plan

{{- .Plan.File.Migration | codeblock "sql" -}}

Atlas lint results

-{{- template "lint-report" .Plan.Lint -}} +{{- template "schema-lint" . -}}
📝 To edit this plan, follow these steps @@ -14,4 +14,32 @@
  • Re-trigger this action using {{ .RerunCommand }}
  • {{- end -}} -
    \ No newline at end of file + +{{- define "schema-lint" -}} + + + + + + + + + + + {{- template "lint-check" "success.svg" -}} + {{- with .Plan.File -}} + + + {{- end -}} + {{- template "lint-report" .Plan.Lint -}} +
    StatusStepResult
    Detect schema changes + {{- $stmtCount := len .Stmts -}} + {{- if eq $stmtCount 1 -}} + 1 new statement detected + {{- else if $stmtCount -}} + {{- $stmtCount }} new statements detected + {{- else -}} + No statements detected + {{- end -}} +
    +{{- end -}} diff --git a/atlasaction/testdata/github/schema-apply-envs.txtar b/atlasaction/testdata/github/schema-apply-envs.txtar index c270b92f..476f921c 100644 --- a/atlasaction/testdata/github/schema-apply-envs.txtar +++ b/atlasaction/testdata/github/schema-apply-envs.txtar @@ -21,9 +21,9 @@ Abort: The plan "From" hash does not match the current state hash (passed with - + R1cGcSfo1oWYK4dz+7WvgCtE/QppFo9lKFEqEDzoS4o= (current hash) -- schema-apply/1/stdout -- -{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-bu.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-12T21:31:20.339663+07:00","End":"2024-09-12T21:31:20.351603+07:00","Applied":{"Name":"20240910173744.sql","Version":"20240910173744","Start":"2024-09-12T21:31:20.350607+07:00","End":"2024-09-12T21:31:20.351228+07:00","Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]},"Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-bu.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"File":{"Name":"20240910173744","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=","Migration":"-- Add column \"c2\" to table: \"t4\"\nALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;\n","URL":"file://20240910173744.plan.hcl"}},"Changes":{"Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]}} -{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-pi.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-12T21:31:20.354074+07:00","End":"2024-09-12T21:31:20.35764+07:00","Applied":{"Name":"20240910173744.sql","Version":"20240910173744","Start":"2024-09-12T21:31:20.356221+07:00","End":"2024-09-12T21:31:20.356755+07:00","Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]},"Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-pi.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"File":{"Name":"20240910173744","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=","Migration":"-- Add column \"c2\" to table: \"t4\"\nALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;\n","URL":"file://20240910173744.plan.hcl"}},"Changes":{"Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]}} -{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-su.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-12T21:31:20.360863+07:00","End":"2024-09-12T21:31:20.368395+07:00","Applied":{"Name":"20240910173744.sql","Version":"20240910173744","Start":"2024-09-12T21:31:20.364331+07:00","End":"2024-09-12T21:31:20.365086+07:00","Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]},"Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-su.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"File":{"Name":"20240910173744","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=","Migration":"-- Add column \"c2\" to table: \"t4\"\nALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;\n","URL":"file://20240910173744.plan.hcl"}},"Changes":{"Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]}} +{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-bu.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-18T11:19:23.232253+07:00","End":"2024-09-18T11:19:23.238022+07:00","Applied":{"Name":"20240910173744.sql","Version":"20240910173744","Start":"2024-09-18T11:19:23.237559+07:00","End":"2024-09-18T11:19:23.237793+07:00","Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]},"Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-bu.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"File":{"Name":"20240910173744","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=","Migration":"-- Add column \"c2\" to table: \"t4\"\nALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;\n","Stmts":[{"Pos":34,"Text":"ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;","Comments":["-- Add column \"c2\" to table: \"t4\"\n"]}],"URL":"file://20240910173744.plan.hcl"}},"Changes":{"Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]}} +{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-pi.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-18T11:19:23.239729+07:00","End":"2024-09-18T11:19:23.242458+07:00","Applied":{"Name":"20240910173744.sql","Version":"20240910173744","Start":"2024-09-18T11:19:23.241765+07:00","End":"2024-09-18T11:19:23.24208+07:00","Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]},"Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-pi.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"File":{"Name":"20240910173744","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=","Migration":"-- Add column \"c2\" to table: \"t4\"\nALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;\n","Stmts":[{"Pos":34,"Text":"ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;","Comments":["-- Add column \"c2\" to table: \"t4\"\n"]}],"URL":"file://20240910173744.plan.hcl"}},"Changes":{"Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]}} +{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-su.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-18T11:19:23.244225+07:00","End":"2024-09-18T11:19:23.247165+07:00","Applied":{"Name":"20240910173744.sql","Version":"20240910173744","Start":"2024-09-18T11:19:23.246708+07:00","End":"2024-09-18T11:19:23.246929+07:00","Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]},"Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local-su.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"File":{"Name":"20240910173744","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=","Migration":"-- Add column \"c2\" to table: \"t4\"\nALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;\n","Stmts":[{"Pos":34,"Text":"ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;","Comments":["-- Add column \"c2\" to table: \"t4\"\n"]}],"URL":"file://20240910173744.plan.hcl"}},"Changes":{"Applied":["ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;"]}} -- output.txt -- error<<_GitHubActionsFileCommandDelimeter_ Abort: The plan "From" hash does not match the current state hash (passed with --from): - iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE= (plan value) + R1cGcSfo1oWYK4dz+7WvgCtE/QppFo9lKFEqEDzoS4o= (current hash) @@ -49,7 +49,7 @@ _GitHubActionsFileCommandDelimeter_ file://20240910173744.plan.hcl Total Time - 11.94ms + 5.769ms

    Version 20240910173744.sql:

    @@ -60,7 +60,7 @@ _GitHubActionsFileCommandDelimeter_ - +
    Error Statement
    1621µs--
    234µs--
    📄 View Pre-planned SQL Statements
    -- Add column "c2" to table: "t4"
     ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;
     
    @@ -84,7 +84,7 @@ ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL; file://20240910173744.plan.hcl Total Time - 3.566ms + 2.729ms

    Version 20240910173744.sql:

    @@ -95,7 +95,7 @@ ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL; - +
    Error Statement
    1534µs--
    315µs--
    📄 View Pre-planned SQL Statements
    -- Add column "c2" to table: "t4"
     ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;
     
    @@ -119,7 +119,7 @@ ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL; file://20240910173744.plan.hcl Total Time - 7.532ms + 2.94ms

    Version 20240910173744.sql:

    @@ -130,7 +130,7 @@ ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL; - +
    Error Statement
    1755µs--
    221µs--
    📄 View Pre-planned SQL Statements
    -- Add column "c2" to table: "t4"
     ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;
     
    diff --git a/atlasaction/testdata/github/schema-apply-lint.txtar b/atlasaction/testdata/github/schema-apply-lint.txtar index dd55fcdd..e61290a7 100644 --- a/atlasaction/testdata/github/schema-apply-lint.txtar +++ b/atlasaction/testdata/github/schema-apply-lint.txtar @@ -2,7 +2,6 @@ mock-atlas $WORK/schema-apply # Setup the action input variables env INPUT_ENV=test -env INPUT_AUTO-APPROVE=true # Run the action ! atlas-action schema/apply @@ -10,11 +9,9 @@ summary summary.html output output.txt -- schema-apply/1/args -- -schema apply --format {{ json . }} --env test --auto-approve --- schema-apply/1/stderr -- -Rejected by review policy: errors or warnings were found +schema apply --format {{ json . }} --env test -- schema-apply/1/stdout -- -{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-12T17:47:58.815235+07:00","End":"0001-01-01T00:00:00Z","Error":"Rejected by review policy: errors or warnings were found","Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"Lint":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"file","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"mode=memory","Fragment":"","RawFragment":"","Schema":"main"}},"Schema":{},"Steps":[{"Name":"Analyze 20240912104758.sql","Text":"1 reports were found in analysis","Result":{"Name":"20240912104758.sql","Text":"-- Disable the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = off;\n-- Drop \"t4\" table\nDROP TABLE `t4`;\n-- Enable back the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = on;\n","Reports":[{"Text":"destructive changes detected","Diagnostics":[{"Pos":101,"Text":"Dropping table \"t4\"","Code":"DS102","SuggestedFixes":[{"Message":"Add a pre-migration check to ensure table \"t4\" is empty before dropping it"}]}]}],"Error":"destructive changes detected"}}],"Files":[{"Name":"20240912104758.sql","Text":"-- Disable the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = off;\n-- Drop \"t4\" table\nDROP TABLE `t4`;\n-- Enable back the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = on;\n","Reports":[{"Text":"destructive changes detected","Diagnostics":[{"Pos":101,"Text":"Dropping table \"t4\"","Code":"DS102","SuggestedFixes":[{"Message":"Add a pre-migration check to ensure table \"t4\" is empty before dropping it"}]}]}],"Error":"destructive changes detected"}]},"File":{"Name":"20240912104758","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Rl4lBdMkvFoGQ4xu+3sYCeogTVnamJ7bmDoq9pMXcjw=","Migration":"-- Disable the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = off;\n-- Drop \"t4\" table\nDROP TABLE `t4`;\n-- Enable back the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = on;\n"}},"Changes":{}} +{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"},"Start":"2024-09-18T11:25:21.64465+07:00","End":"0001-01-01T00:00:00Z","Error":"Rejected by review policy: errors or warnings were found","Plan":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"local.db","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"","Fragment":"","RawFragment":"","Schema":"main"}},"Lint":{"Env":{"Driver":"sqlite3","URL":{"Scheme":"sqlite","Opaque":"","User":null,"Host":"file","Path":"","RawPath":"","OmitHost":false,"ForceQuery":false,"RawQuery":"mode=memory","Fragment":"","RawFragment":"","Schema":"main"}},"Schema":{},"Steps":[{"Name":"Analyze 20240918042521.sql","Text":"1 reports were found in analysis","Result":{"Name":"20240918042521.sql","Text":"-- Disable the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = off;\n-- Drop \"t4\" table\nDROP TABLE `t4`;\n-- Enable back the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = on;\n","Reports":[{"Text":"destructive changes detected","Diagnostics":[{"Pos":101,"Text":"Dropping table \"t4\"","Code":"DS102","SuggestedFixes":[{"Message":"Add a pre-migration check to ensure table \"t4\" is empty before dropping it"}]}]}],"Error":"destructive changes detected"}}],"Files":[{"Name":"20240918042521.sql","Text":"-- Disable the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = off;\n-- Drop \"t4\" table\nDROP TABLE `t4`;\n-- Enable back the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = on;\n","Reports":[{"Text":"destructive changes detected","Diagnostics":[{"Pos":101,"Text":"Dropping table \"t4\"","Code":"DS102","SuggestedFixes":[{"Message":"Add a pre-migration check to ensure table \"t4\" is empty before dropping it"}]}]}],"Error":"destructive changes detected"}]},"File":{"Name":"20240918042521","FromHash":"iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=","ToHash":"Rl4lBdMkvFoGQ4xu+3sYCeogTVnamJ7bmDoq9pMXcjw=","Migration":"-- Disable the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = off;\n-- Drop \"t4\" table\nDROP TABLE `t4`;\n-- Enable back the enforcement of foreign-keys constraints\nPRAGMA foreign_keys = on;\n","Stmts":[{"Pos":55,"Text":"PRAGMA foreign_keys = off;","Comments":["-- Disable the enforcement of foreign-keys constraints\n"]},{"Pos":101,"Text":"DROP TABLE `t4`;","Comments":["-- Drop \"t4\" table\n"]},{"Pos":177,"Text":"PRAGMA foreign_keys = on;","Comments":["-- Enable back the enforcement of foreign-keys constraints\n"]}]}},"Changes":{}} -- output.txt -- error<<_GitHubActionsFileCommandDelimeter_ Rejected by review policy: errors or warnings were found @@ -26,7 +23,7 @@ _GitHubActionsFileCommandDelimeter_ sqlite://local.db Plan Name - 20240912104758 + 20240918042521 From Hash @@ -50,8 +47,7 @@ PRAGMA foreign_keys = on; -
    1 new migration file detected - 20240912104758.sql
    Analyze 20240912104758.sql
    1 reports were found in analysis +
    Detect schema changes3 new statements detected +
    Analyze 20240918042521.sql
    1 reports were found in analysis Destructive changes detected
    Dropping table "t4" (DS102)
    - - + \ No newline at end of file diff --git a/go.mod b/go.mod index 150aae6d..e52a8c44 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23 require ( ariga.io/atlas v0.21.2-0.20240418081819-02b3f6239b04 - ariga.io/atlas-go-sdk v0.5.9-0.20240912095114-8fc188ca2398 + ariga.io/atlas-go-sdk v0.5.9-0.20240917095830-41bde7d654aa github.com/alecthomas/kong v0.8.0 github.com/mattn/go-sqlite3 v1.14.17 github.com/mitchellh/mapstructure v1.1.2 diff --git a/go.sum b/go.sum index d082733f..420f3dfe 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ ariga.io/atlas v0.21.2-0.20240418081819-02b3f6239b04 h1:YF3qiqtnhn+y4tfhZKTfZKfizpjqHYt7rWPUb+eA4ZA= ariga.io/atlas v0.21.2-0.20240418081819-02b3f6239b04/go.mod h1:VPlcXdd4w2KqKnH54yEZcry79UAhpaWaxEsmn5JRNoE= -ariga.io/atlas-go-sdk v0.5.9-0.20240912095114-8fc188ca2398 h1:u6mxEYmTYxmeyOuXi1C1pU6uyaqb2uQwWJE/P8k1qEw= -ariga.io/atlas-go-sdk v0.5.9-0.20240912095114-8fc188ca2398/go.mod h1:9Q+/04PVyJHUse1lEE9Kp6E18xj/6mIzaUTcWYSjSnQ= +ariga.io/atlas-go-sdk v0.5.9-0.20240917095830-41bde7d654aa h1:zdQVDEW8c8n7SbBDjY7vcuaoOTnhfh/QKqhTKrZ1aqQ= +ariga.io/atlas-go-sdk v0.5.9-0.20240917095830-41bde7d654aa/go.mod h1:9Q+/04PVyJHUse1lEE9Kp6E18xj/6mIzaUTcWYSjSnQ= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=