fukamachi / mito

An ORM for Common Lisp with migrations, relationships and PostgreSQL support
292 stars 31 forks source link

Function parse-statements unable to separate statements in some cases #74

Open svetlyak40wt opened 3 years ago

svetlyak40wt commented 3 years ago

Here is the minimal example to reproduce this issue:

CL-USER> (length (mito.migration.sql-parse::parse-statements
                      "
CREATE TABLE test_dist (id INTEGER, quicklisp_version TEXT NOT NULL DEFAULT '');

CREATE TABLE any_other_table_o_more (id INTEGER);

INSERT INTO test_dist (id, quicklisp_version) VALUES (0, 'some version');
"))
1

Expected value is 3.

However, when I replace '' default value with NULL, everything works!

CL-USER> (length (mito.migration.sql-parse::parse-statements
                      "
CREATE TABLE test_dist (id INTEGER, quicklisp_version TEXT NOT NULL DEFAULT NULL);

CREATE TABLE any_other_table_o_more (id INTEGER);

INSERT INTO test_dist (id, quicklisp_version) VALUES (0, 'some version');
"))
3

Also works with nonempty default string:

(length (mito.migration.sql-parse::parse-statements
                      "
CREATE TABLE test_dist (id INTEGER, quicklisp_version TEXT NOT NULL DEFAULT 'blah');

CREATE TABLE any_other_table_o_more (id INTEGER);

INSERT INTO test_dist (id, quicklisp_version) VALUES (0, 'some version');
"))
3

Tested on the latest Mito from the repository. Commit c51e6476ee518ceb554516a010406a20b658b908.