HaxeFoundation / record-macros

Macro-based ORM (object-relational mapping)
MIT License
49 stars 24 forks source link

Added: TableCreate sql index generation #25

Open ProPuke opened 6 years ago

ProPuke commented 6 years ago

TableCreate now also generates indexes when creating tables, and primary keys are added in SQLite (this was disabled before for some reason)

bablukid commented 6 years ago

record-macros is often used with dbadmin. Dbadmin allows to add indexes from the web interface

ProPuke commented 6 years ago

How does that relate to this pull request?

bablukid commented 6 years ago

you said "this was disabled before for some reason", the explaination could be that the initial developer and its team (Nicolas Cannasse and Motion Twin) used it always with dbadmin. This allowed to create tables first and add indexes later through dbadmin.

ProPuke commented 6 years ago

Ahh, no - It was only disabled in the case of SQLite. TableCreate had likely not been tested fully with SQLite so it was disabled there.

jonasmalacofilho commented 4 years ago

This fails the MySQL unit tests:

CREATE TABLE MySpodClass (theId INTEGER AUTO_INCREMENT NOT NULL,`int` INTEGER NOT NULL,`double` DOUBLE NOT NULL,boolean TINYINT(1) NOT NULL,string VARCHAR(255) NOT NULL,date DATETIME NOT NULL,`binary` MEDIUMBLOB NOT NULL,abstractType MEDIUMTEXT NOT NULL,nullInt INTEGER,enumFlags INTEGER NOT NULL,data MEDIUMBLOB NOT NULL,anEnum TINYINT UNSIGNED NOT NULL,bytes BINARY(2) NOT NULL,rid INTEGER NOT NULL,rnid INTEGER,spid INTEGER)
Incorrect table definition; there can be only one auto column and it must be defined as a key

Possibly related to the absence of an index on that table and the change to:

if( !hasID )
        decls.push("PRIMARY KEY ("+Lambda.map(infos.key,quote).join(",")+")");
grepsuzette commented 4 years ago

This PR is a very useful one. I recommand we make the above suggested change, and if it passes the tests pull the commits :)