What is the procedure to install an ORM component such as Doctrine into an existing custom PHP5 MVC framework?
What are the minimal requirement in terms of framework architecture and fonctionalities ?
What are the possible problems to face ?
Would it be problematic to have side by side tables generated by the ORM and some by "old fashioned " SQL request?
The ORM is simply an abstraction for your database interactions. The Doctrine ORM wraps PHPs PDO library and adds some useful abstractions. To implement Doctrine into your existing framework you'll need to download the code and put it into a directory in your project. If you're already using third party libraries, place it there. If not, create a vendors directory and drop doctrine in it. You can follow the Doctrine documentation for installation and configuration details.
Once you've implemented doctrine, your task will be to update existing database interactions. If all database interactions are already handled through models, you should be able to write an abstract or interface base class for your models. From there, models can be updated to implement Doctrine methods for interaction.
If you have SQL scattered around the app, you should probably decouple the database interactions and isolate them into models then follow the process described above.
There is nothing about using the ORM that will prevent existing database interactions from operating, but that is very messy and should be avoided if at all possible.
Related
I wonder if there is an interface that diverse ORM should implement for Symfony or not.
The question came up when I was building a service that accepts an ORM (Doctrine right now), and wanted to declare type.
I guess different ORM have different behaviour and classes... in those cases, how can build entities that do not depend on specific ORM in case one wants to switch later?
Generally, Symfony is agnostic in regard to your choice of ORM.
The standard edition comes bundled with Doctrine and also contains some “bridge” code to ease the integration.
However, you can use any ORM you’d like to. For example, Propel is known to work well with Symfony, too. The Propel team also maintains an integration bundle.
There is no “interface” in the sense of a formal description an ORM has to comply with. There is no such thing as interface SymfonyOrmInterface {}.
Think about it, how and why should Symfony demand this? Symfony is a HTTP framework built on a set of loosely coupled components. Most of these components don’t even know what an ORM is or if one is currently available in the application.
You will usually install your ORM through composer, and it will be available in your business code (assuming that it supports autoloading with PSR-0/-4).
Of course, for a proper integration of an ORM into Symfony, there are some conventions and features, such as:
CLI commands, e.g. for schema updates,
Managing configuration values through the global config.yml and parameters.yml files,
Providing services and dependencies through Dependency Injection.
These are implemented in integration bundles, usually provided by the respective ORM vendor.
For your business code, this means that you can’t just replace one ORM with another one. There are significant differences accross ORMs in regard to storage abstraction, caching, querying, hydration, etc. Replacing an ORM will always require you to adapt your business logic to some exent, and not only in a Symfony project.
I am developing a web application using Zend Framework 2 and Doctrine 2. I'm new to Doctrine 2 in general and Migrations in particular. I was wondering if there are any recommended best practices in using this. Some specific things I'm looking for:
A recommended workflow from development to deployment?
Do you include pre-populating data in migrations?
How to handle reverting to a previous version if migration fails.
Many thanks!
Doctrine has own library for migrations, that includes also Symfony bundle.
For Zend there probably is some bundle as well (maybe seek on Github a bit more)
As for your specific questions:
Nothing special. Basic workflow is nicely described in Symfony bundle documentation. We use it in pretty same way even in a different framework.
Yes, so every developer has fully operational system. For tests we use data-fixtures with minimal required data only.
It's managed by this package itself.
The Doctrine ORM module for ZF2 (DoctrineORMModule) has built-in support for Doctrine ORM migrations. There's a very brief blurb in the documentation about how to configure it. You can then access the migration commands (generate, migrate, etc) through the CLI interface that module provides (vendor/bin/doctrine-module)
As for my personal workflow I generally put initialization or pre-population data - the stuff you initially seed a new installation with - into database fixtures (which Doctrine ORM also supports and there is a ZF2 module for).
Is the Doctrine Migrations project compatible with Doctrine MongoDB?
It isn't clear to me from searching and looking at the Doctrine Migrations project whether it is compatible with ODM solutions (e.g. MongoDB) as well as ORM solutions.
If it is, can anyone suggest examples or articles on how to use the two together?
If it isn't, are there reasonable alternatives?
Question Background:
I understand, marginally, the different approaches to migrating a document's data from one version of the document to another and the pros and cons of each.
I am leaning towards possibly implementing a hybrid approach of gradual schema changes and migration scripts as suggested here. Leveraging the functionality within Doctrine's MongoDB library written about by Jonathan Wage in his post: Doctrine MongoDB ODM Schema Migrations.
Even with that, I need to find some way of creating a migration script or performing the data migration, and Doctrine Migrations seemed like a good first choice.
As an aside, another user warns against using the approach Jonathan Wage presents above for migrating data and instead running commands (JavaScript?) directly against the database.
Despite doctrine-migrations is not compabible with MongoDB ODM (it only supports DBAL) you can bet for the alternative mongo-based migration components made by 3rd party teams.
It was firstly developed here https://github.com/antimattr/mongodb-migrations
but after it has been abandoned the project continues here https://github.com/doesntmattr/mongodb-migrations
Ufortunately, it isn't compatible with ODM. It supports ORM only.
I need to load data from an old DB into a migrated schema of this DB using Doctrine migration system.
I guess Doctrine might help me in this process.
I tried and lost a few hours using ETL scripts programs, without success.
From my point of view I need to :
Create a DB with the V0 schema
Load the data from the old DB (schema are identical)
Migrate DB to latest version using Doctrine migration
Extract data
Load it in the new DB
WHat do you think of this process?
Do you think it is feasable using Doctrine?
I tried a few searches on Google without success.
I am currently reviewed the features of Doctrine_Core class.
Thanks for your help
Yes, it is possible to migrate data from one database to another using Doctrine.
It sounds like you're trying to do a one-time database revision and migration and that your applications are not currently written using Doctrine. In that scenario, database abstraction has little or no benefit, unless you're also rewriting the applications to use it.
If you have no prior experience using Doctrine then I seriously doubt that writing custom migration classes in it will be easier than doing it with whatever database API you are already experienced using. It makes sense to use the migration classes (some times) if you are already using Doctrine for your development. Otherwise it's another layer and API you don't need.
I'm using Doctrine 1.2, which has some nice features for migrations but also a number of bugs and omissions of expected functionality. Reportedly version 2 improves on this but I haven't used it yet.
I was wondering if there were any good pre-built ways to implement an EAV design pattern in Zend Framework?
I am trying to decide if I should create my own implementation or use one that has already been built.
Use Doctrine with MongoDB Document Mapper http://www.doctrine-project.org/
Zend Framework 2.0 has automated install for Doctrine with Composer, so it means Zend People also offer this as an Option apart from the built-in Zend_Db.
Using EAV on a document-oriented NoSQL database system like MongoDB or CouchDB is way much better than implementing a Hack over Traditional Relational Databases like MySql ( something that Magento did ). NoSQL Databases are better at implementing Sparse Matrix type Data.
Check out Zend Framework EAV on Google Code.
Digitalus CMS uses the EAV pattern, and is based on MySQL. It is true that Mongo or Couch might be more appropriate, but MySQL is often an easier choice because you don't have to install anything. I have tried using SimpleDB, but the local MySQL version is 4x faster. SQLite also works very well.
There are a lot of opponents to this approach, and their claims are largely founded. Any time I need to be able to query data I use a standard relational approach, but EAV shines when you are working with very loosely structured data like the content on a web page.
Digitalus uses an approach where there is the base CMS item model that handles all of the EAV logic. This model also handles a write-through cache so the system ultimately serves content as fast as a flat file system.
All the purists are probably technically correct, but fast and easy have a place in my toolbox.