# Expect the command to fail; exit code 1.
! atlas migrate lint --dir file://migrations --dev-url URL --latest=1
stdout 'Analyzing changes from version 2 to 3 \(1 migration in total\):'
stdout ''
stdout '  -- analyzing version 3'
stdout '    -- destructive changes detected:'
stdout '      -- L1: Dropping table "pets" https://atlasgo.io/lint/analyzers#DS102'
stdout '    -- suggested fix:'
stdout '      -> Add a pre-migration check to ensure table "pets" is empty before dropping it'
stdout '  -- ok \(.+\)'
stdout ''
stdout '  -------------------------'
stdout '  -- .+'
stdout '  -- 1 version with errors'
stdout '  -- 1 schema change'
stdout '  -- 1 diagnostic'

# Expect the command to fail; exit code 1.
! atlas migrate lint --dir file://migrations --dev-url URL --latest=2
stdout 'Analyzing changes from version 1 to 3 \(2 migrations in total\):'
stdout ''
stdout '  -- analyzing version 2'
stdout '    -- destructive changes detected:'
stdout '      -- L1: Dropping table "users" https://atlasgo.io/lint/analyzers#DS102'
stdout '    -- suggested fix:'
stdout '      -> Add a pre-migration check to ensure table "users" is empty before dropping it'
stdout '  -- ok \(.+\)'
stdout ''
stdout '  -- analyzing version 3'
stdout '    -- destructive changes detected:'
stdout '      -- L1: Dropping table "pets" https://atlasgo.io/lint/analyzers#DS102'
stdout '    -- suggested fix:'
stdout '      -> Add a pre-migration check to ensure table "pets" is empty before dropping it'
stdout '  -- ok \(.+\)'
stdout ''
stdout '  -------------------------'
stdout '  -- .+'
stdout '  -- 2 versions with errors'
stdout '  -- 2 schema changes'
stdout '  -- 2 diagnostics'

-- migrations/1.sql --
CREATE TABLE users (id int);

CREATE TABLE pets (id int);

ALTER TABLE users RENAME COLUMN id TO oid;

-- migrations/2.sql --
DROP TABLE users;

-- migrations/3.sql --
DROP TABLE pets;
