deleteman / lfpr

Find projects to contribute to or publish your project so others can find it.
www.lookingforpullrequests.com
64 stars 14 forks source link

[Work in progress] Refactoring of all database stuff #49

Open mpscholten opened 10 years ago

mpscholten commented 10 years ago

While hacking on a pdo replacement for the current implementation of our orm I got the feeling that I was reinventing the wheel :) Therefore I stopped working on building our "custom orm thing" and replaced it with propel 2.

Basically propel generates all the "basic" model code for us (stored in app/models/Base and app/models/Map). The generated code should not be stored in our repo, you have to generated it by running vendor/bin/propel build --input-dir=config -vvv. Propel uses a schema.xml for defining the database schema, which is used for the code generation. With this approach I could rebuild the models with propel very easy (and in nearly no time, I just had to write a few lines in the schema.xml).

I just need to update the controllers and this should be ready.

At this point I want to get some feedback before I will continue working on this. @deleteman: Please look over the code and let me know if you are happy with my choice or if we should rethink :)

deleteman commented 10 years ago

Hey @mpscholten , awesome job man! This is looking promising! Thanks so much for taking care of this! Now, gotta say I love everything BUT the use of XML for the schemas, I really hate XML for this... , could we keep the schema definition on the YML files? Maybe write into the db:load command something that generates the XML from the YML or something like that? Unless you have a strong reason to go with the XML I would really rather stick to the YML files for this.

Also, how is this new propel based persistence layer going to handle the migrations?

I'm really exited about this, thanks again!

mpscholten commented 10 years ago

Awesome to hear you like it. Currently only supports database schemas defined in the xml format. I'm also a big fan of yaml, but in this case I'd just stay with xml to keep it simple. Otherwise the other configuration files of propel can all be defined in yaml.

Migrations are very easy with propel. Basically you just call vendor/bin/propel migration:generate to generate a new migration file. Propel can automatically detect changes between your database and the schema.xml file and then automatically generates the required sql code for you. You just have to review the generated migration class file (you can also edit it, e.g. if the generated sql code is wrong). Then just call vendor/bin/propel migration:migrate to execute the new migration. You can read more here: http://propelorm.org/documentation/09-migrations.html (the link is a little bit out of date because propel 2 is relative new).