dbsrgits / sql-translator

SQL::Translator (SQLFairy)
http://sqlfairy.sourceforge.net/
82 stars 91 forks source link

Table with wrong data type could be created #157

Closed KES777 closed 1 year ago

KES777 commented 1 year ago

How to reproduce: put space before type.

--- a/lib/Schema/Result/Document.pm
+++ b/lib/Schema/Result/Document.pm
@@ -21,7 +21,7 @@ $X->add_columns(
        is_nullable =>  1,
    },
    document_type_id => {
-       data_type =>  'integer',
+       data_type =>  ' integer',
    },
    docn => {
        data_type =>  'varchar',

Generated migration script (Notice extra space before integer for document_type_id column):

CREATE TABLE "document" (
  "id" serial NOT NULL,
  "owner_id" integer,
  "document_type_id"  integer NOT NULL,
  PRIMARY KEY ("id")
);

I do not know how long this wrong data type lurking at production code. But we noticed it when started to use 'Mojolicious::Plugin::GraphQL', which issues 'document_type_id' unknown data type: integer error.

PS. In theory we can create { data_type => 'integer NOT NULL' } and this will works. Should we put quotes around data type to be more safe?

rabbiveesh commented 1 year ago

Hi; this looks like a bug in your code; i think the only sensible thing to do is allow the end user to pass through whatever they need.

I see that you raised this against the DBIC converter for GraphQL; that clearly takes the value straight out of DBIC. I don't even think it's a bug there, either.

You just need to not have typos in your code