1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
only mysql8
atlas migrate lint --dir file://migrations1 --dev-url URL --latest=1 > got.txt
cmp got.txt expected1.txt
atlas migrate lint --dir file://migrations2 --dev-url URL --latest=1 > got.txt
cmp got.txt expected2.txt
atlas migrate lint --dir file://migrations3 --dev-url URL --latest=1 > got.txt
cmp got.txt empty.txt
atlas migrate lint --dir file://migrations4 --dev-url URL --latest=1 > got.txt
cmp got.txt expected4.txt
-- empty.txt --
-- migrations1/1.sql --
CREATE TABLE users (id int);
-- migrations1/2.sql --
ALTER TABLE users ADD COLUMN `rank` int NOT NULL DEFAULT 1;
ALTER TABLE users MODIFY COLUMN id int NOT NULL;
-- expected1.txt --
2.sql: data dependent changes detected:
L2: Modifying nullable column "id" to non-nullable might fail in case it contains NULL values
-- migrations2/1.sql --
CREATE TABLE users (id int);
-- migrations2/2.sql --
-- Add (a, b, c), backfill (a, b) and then modify all to not-null.
ALTER TABLE users ADD COLUMN `a` int, ADD COLUMN `b` int, ADD COLUMN `c` int;
UPDATE users SET `a` = 1;
UPDATE users SET `b` = 1 WHERE `b` IS NULL;
ALTER TABLE users MODIFY COLUMN `a` int NOT NULL, MODIFY COLUMN `b` int NOT NULL, MODIFY COLUMN `c` int NOT NULL;
-- expected2.txt --
2.sql: data dependent changes detected:
L5: Modifying nullable column "c" to non-nullable might fail in case it contains NULL values
-- migrations3/1.sql --
CREATE TABLE users (id int);
ALTER TABLE users MODIFY COLUMN id int NOT NULL;
-- migrations4/1.sql --
CREATE TABLE users (id int);
CREATE TABLE pets (id int);
-- migrations4/2.sql --
ALTER TABLE users ADD COLUMN name varchar(255), ADD COLUMN age float;
UPDATE users SET name = 'Unknown', age = 0;
-- No diagnostics.
ALTER TABLE users MODIFY COLUMN name varchar(255) NOT NULL, MODIFY COLUMN age float NOT NULL;
ALTER TABLE pets ADD COLUMN name varchar(255), ADD COLUMN age float;
UPDATE pets SET name = 'Unknown', age = 0 WHERE RAND() > 0.5;
-- With diagnostics as statement above cannot be sure NULL values are back-filled.
ALTER TABLE pets MODIFY COLUMN name varchar(255) NOT NULL, MODIFY COLUMN age float NOT NULL;
-- expected4.txt --
2.sql: data dependent changes detected:
L9: Modifying nullable column "name" to non-nullable might fail in case it contains NULL values
L9: Modifying nullable column "age" to non-nullable might fail in case it contains NULL values
|