propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 398 forks source link

sql:build for sqlite including invalid syntax (enum and unsigned) #933

Open elijahb opened 9 years ago

elijahb commented 9 years ago

We use the sql:build option to export our MySQL intended schema to SQLite to perform some integration tests. We found that when exporting an schema that uses ENUM and UNSIGNED, the SqlitePlatform exports them, but they are invalid to SQLite.

As far as I can see it's because SqlitePlatform.php falls back to DefaultPlatform.php that includes the sqlType property. Maybe SqlitePlatform should filter invalid types, or maybe there should be a way to set that the schema is intended to one platform and if you export it to some other it should ignore the sqlType field at all (or maybe it could be an option in the command line to ingore it), or maybe SqlitePlatform should ignore sqlType at all since it supports only a few types.

Schema column example:

<column name="mode" type="VARCHAR" sqlType="enum('one','two')" defaultValue="two"/>

sql:build --platform sqlite

[mode] ENUM('one', 'two') DEFAULT 'two' 

Should be exported as

[mode] TEXT DEFAULT 'two' 
marcj commented 9 years ago

I'd rather go with additional attributes allowing you to overwrite the sqlType for a particular platform. So like <column name="mode" type="VARCHAR" sqlType="enum('one','two')" sqlType-sqlite="TEXT" defaultValue="two"/>. So sqlType being the default and all additional attributes overwrite the value for its platform. Guess that's the easiest way to bypass such use cases.