+ {{- template "lint-report" . -}}
+ {{- end -}}
+{{/* Fallback to the old output */}}
+{{- else with .Changes -}}
+ {{- with .Error -}}
+The following SQL statement failed to execute:
+ {{- .Stmt | codeblock "sql" -}}
+ Database returned the following error:
+ {{- .Text | codeblock "" -}}
+ {{- end -}}
+ {{- with .Applied -}}
+ {{- join . "\n" | codeblock "sql" | details "๐ Succeeded SQL Applied" -}}
+ {{- end -}}
+ {{- with .Pending -}}
+ {{- join . "\n" | codeblock "sql" | details "๐ Pending SQL statements" -}}
+ {{- end }}
+{{- end -}}
diff --git a/atlasaction/testdata/github/schema-apply-envs.txtar b/atlasaction/testdata/github/schema-apply-envs.txtar
new file mode 100644
index 00000000..c270b92f
--- /dev/null
+++ b/atlasaction/testdata/github/schema-apply-envs.txtar
@@ -0,0 +1,136 @@
+# Mock the atlas command outputs
+mock-atlas $WORK/schema-apply
+# Setup the action input variables
+env INPUT_ENV=test
+env INPUT_PLAN=file://20240910173744.plan.hcl
+# Run the action
+! atlas-action schema/apply
+stdout '"atlas schema apply" completed successfully on the target "sqlite://local-bu.db"'
+stdout '"atlas schema apply" completed successfully on the target "sqlite://local-pi.db"'
+stdout '"atlas schema apply" completed successfully on the target "sqlite://local-su.db"'
+
+summary summary.html
+output output.txt
+
+-- schema-apply/1/args --
+schema apply --format {{ json . }} --env test --plan file://20240910173744.plan.hcl
+-- schema-apply/1/stderr --
+Abort: The plan "From" hash does not match the current state hash (passed with --from):
+
+ - iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE= (plan value)
+ + 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;"]}}
+-- 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)
+_GitHubActionsFileCommandDelimeter_
+-- summary.html --
+
Migration Passed
atlas schema apply Summary:
+
+
Database URL
+
sqlite://local-bu.db
+
+
Plan Name
+
20240910173744
+
+
+
From Hash
+
iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=
+
+
+
To Hash
+
Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=
+
+
Plan URL
+
file://20240910173744.plan.hcl
+
+
Total Time
+
11.94ms
+
Version 20240910173744.sql:
+
+
+
Status
+
Executed Statements
+
Execution Time
+
Error
+
Error Statement
+
+
1
+
621ยตs
-
-
+
๐ View Pre-planned SQL Statements
-- Add column "c2" to table: "t4"
+ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;
+
+
Migration Passed
atlas schema apply Summary:
+
+
Database URL
+
sqlite://local-pi.db
+
+
Plan Name
+
20240910173744
+
+
+
From Hash
+
iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=
+
+
+
To Hash
+
Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=
+
+
Plan URL
+
file://20240910173744.plan.hcl
+
+
Total Time
+
3.566ms
+
Version 20240910173744.sql:
+
+
+
Status
+
Executed Statements
+
Execution Time
+
Error
+
Error Statement
+
+
1
+
534ยตs
-
-
+
๐ View Pre-planned SQL Statements
-- Add column "c2" to table: "t4"
+ALTER TABLE `t4` ADD COLUMN `c2` integer NOT NULL;
+
+
Migration Passed
atlas schema apply Summary:
+
+
Database URL
+
sqlite://local-su.db
+
+
Plan Name
+
20240910173744
+
+
+
From Hash
+
iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=
+
+
+
To Hash
+
Cp8xCVYilZuwULkggsfJLqIQHaxYcg/IpU+kgjVUBA4=
+
+
Plan URL
+
file://20240910173744.plan.hcl
+
+
Total Time
+
7.532ms
+
Version 20240910173744.sql:
+
+
+
Status
+
Executed Statements
+
Execution Time
+
Error
+
Error Statement
+
+
1
+
755ยต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
new file mode 100644
index 00000000..dd55fcdd
--- /dev/null
+++ b/atlasaction/testdata/github/schema-apply-lint.txtar
@@ -0,0 +1,57 @@
+# Mock the atlas command outputs
+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
+
+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/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":{}}
+-- output.txt --
+error<<_GitHubActionsFileCommandDelimeter_
+Rejected by review policy: errors or warnings were found
+_GitHubActionsFileCommandDelimeter_
+-- summary.html --
+
Migration Failed
atlas schema apply Summary:
+
+
Database URL
+
sqlite://local.db
+
+
Plan Name
+
20240912104758
+
+
+
From Hash
+
iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=
+
+
+
To Hash
+
Rl4lBdMkvFoGQ4xu+3sYCeogTVnamJ7bmDoq9pMXcjw=
+
Error
Rejected by review policy: errors or warnings were found
๐ View SQL Statements
-- Disable the enforcement of foreign-keys constraints
+PRAGMA foreign_keys = off;
+-- Drop "t4" table
+DROP TABLE `t4`;
+-- Enable back the enforcement of foreign-keys constraints
+PRAGMA foreign_keys = on;
+
Atlas lint results
+
+
+
Status
+
Step
+
Result
+
+
+
+
1 new migration file detected
+
20240912104758.sql
Analyze 20240912104758.sql 1 reports were found in analysis