CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Opportunities while converting schema to Doctrine
Pages: [1]

Author Topic: Opportunities while converting schema to Doctrine  (Read 692 times)

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Opportunities while converting schema to Doctrine
January 07, 2014, 05:22:48 pm
In Peter Haight's October blog post on his Doctrine work and the resulting discussion a few items came up that I consider to be opportunities for schema cleanup as we move to Doctrine. I'm posting here to see if we can deliberately brainstorm for ideas about how we might want to refactor the schema during the move to Doctrine. To keep things focussed, I'd suggest we exclude things not related to schema refactoring, except insofar as they are necessary to support a particular refactoring or pattern of refactoring.

1. cleanup oddities like not using a unique numeric foreign key for things like payment processor reference.
2. Do some research on patterns to replace the entity_table / entity_id way of referring to foreign keys. The main pro of that pattern is that it is a simple way to implement a reference to 2-n foreign tables with just two fields. Cons include a) the fact that we need to code the maintenance of the references, and b) we cannot take advantage of MySQL's integrity constraint checking and enforcement. These are system quality and code maintenance issues. Less important cons are c) i suspect coders need to do more work to optimize query performance, and d) We may lose some of the convenience that is provided for foreign keys in the ORM, or at least have to do more work to get something close to it.

Other opportunities are more forward looking. Namely, Doctrine supports new field types thatwe for the most part have not used:
object: Type that maps a SQL CLOB to a PHP object using serialize() and unserialize()
array: Type that maps a SQL CLOB to a PHP array using serialize() and unserialize()
simple_array: Type that maps a SQL CLOB to a PHP array using implode() and explode(), with a comma as delimiter. IMPORTANT Only use this type if you are sure that your values cannot contain a ”,”.
json_array: Type that maps a SQL CLOB to a PHP array using json_encode() and json_decode()

anyway, just want to provoke some discussion.

cheers.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Opportunities while converting schema to Doctrine
January 07, 2014, 05:45:35 pm
Joe, one question that came up today for me was should we address what seems to be duplicated data between contribution records and contribution line items. For example, they both have a field called "financial_type_id" and it seems unnecessary for the contribution record to have that data.
Try asking your question on the new CiviCRM help site.

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Opportunities while converting schema to Doctrine
January 07, 2014, 08:14:19 pm
Don't get me going on the design by committee that was the CiviAccounts schema changes! In 5his case I think dgg wanted it to make it more similar to the past iirc. I would be pleased to drop it.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Owen

  • I post occasionally
  • **
  • Posts: 83
  • Karma: 2
    • Leukaemia & Lymphoma Research
  • CiviCRM version: 4.3.4
  • CMS version: Drupal 7
  • MySQL version: -
  • PHP version: -
Re: Opportunities while converting schema to Doctrine
January 08, 2014, 12:30:52 am
There might be specific use cases but as someone who interacts directly with DB for things like reporting, PHP arrays in SQL are a pain.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Opportunities while converting schema to Doctrine
January 08, 2014, 04:00:41 am
I'm keen on storing array-type data as json - either because it seems more modern & elegant - or because I have been brain-washed by the francophone.

WRT the duplication of financial_type_id - I think that CiviAccounts was a massive endeavour & inevitably some of the choices made will have been wrong. It would be good to document some of the ones that you have doubts about Joe so that we are in a better position to review them & hopefully over time simplify a few things around the margins. I would tend to agree with both your comments that the financial_type_id is not required in the civicrm_contribution table - but in order to remove it we would need to ensure the api still returned it (at least if there is only one line item - I think an array for multiple is over-kill).

Of course simplifications are rarely funded - but having an eye on what they will be will make it easier to build them into other pieces of work.

So as not to hijack this thread can I suggest that if you do feel you can document those things you reply here only with a link to the right place to discuss those specific to Accounts.


Another example of the entity_id :: entity_table pattern is the source_record_id field in civicrm_activity.

Does Doctrine offer us anything around logging or multilingual? We don't really use DAO for those so probably not
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Opportunities while converting schema to Doctrine
January 08, 2014, 04:25:15 am
So on multilingual / translations I see there is an extension to doctrine

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md

also of interest - timestampable

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/timestampable.

logable

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/loggable.md

Also a couple for Tree & Sort - http://symfony.com/doc/current/cookbook/doctrine/common_extensions.html

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Opportunities while converting schema to Doctrine
January 08, 2014, 07:43:17 am
@eileen, bravo et vive le json libre!

@joe, how do you see replacing entity_id/table for the tags (ie. something that can be applied to case or contacts or activities...)?

Something tangential to the entity_id/table and sql integrity: shouldn't we move to one table by custom group (for the core groups at least?) For why I understand, it's mostly a workaround to the lack of solution to easily have an UI to manage a list of "simple pseudo constants". It would implode the number of entities, but not a problem IMO.
added bonus, we won't have a join between an int field and a string optionvalue that has terrible performance.

X+



-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Parvez

  • I post occasionally
  • **
  • Posts: 91
  • Karma: 7
Re: Opportunities while converting schema to Doctrine
January 08, 2014, 07:56:38 am
Hey Guys,

As much as I love arrays/meta data in the code, I'd really love if we didn't end up storing them in the database! It makes reporting as at database level a nightmare and its one of the things that has made it really difficult to do proper automatic OLAP/Warehouse reporting at a few clients I've worked with. For session based information, fair enough - I can see the performance and ease of use. But for other things we really shouldn't, a prime example of the sort of thing I mean is in contact subtype (should really be a child table) and multi option custom fields (the same).

If we're looking to move to DOCTRINE would well be worth addressing these and putting in some guidance for QA.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Opportunities while converting schema to Doctrine

This forum was archived on 2017-11-26.