matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.85k stars 2.64k forks source link

trunk: Data access abstraction #1368

Closed robocoder closed 13 years ago

robocoder commented 14 years ago

Users have requested Piwik support for non-MySQL databases, e.g., PostgreSQL (#500), MSSQL (#1335), and NoSQL (see mailing list).

Obstacles:

Considerations:

TODO:

Propose changing instances of:

Piwik_Query($sql, $optional_parameter_array);
// or
Zend_Registry::get('db')->query($sql, $optional_parameter_array);

to:

Piwik_Repository::execute('Db_QueryName_XYZ', $optional_parameter_array);

The $sql is moved into Query classes, defined in:

(Any of the above is acceptable and handled by the autoloader.)

Piwik_Repository::execute($queryName, $parameters) could be something like:

$schemaClassName = 'Piwik_Db_Query_' . Zend_Registry::get('schema');
$query = $schemaClassName::factory($queryName, $parameters);

$db = Zend_Registry::get('db');
return $db->query($query, $parameters);

The factory method returns an object or string (e.g., schema-specific SQL). Non-MySQL schemas can either:

The prefix on the query name tells the factory method how to construct the class name. A query name prefixed by Db is treated as a core query. A query name prefixed by the plugin's name, e.g., GeoIP refers to a query in the GeoIP plugin's Query folder.

Additional ideas:

halfdan commented 14 years ago

Considering that the 1.0 version jump will increase popularity of Piwik and more developers might start developing plugins, shouldn't we have a stable data access layer by then? (meaning: Shouldn't the target version be 1.0 instead of after 1.0?)

If you guys need help making these changes, I'm more than happy to help.

robocoder commented 14 years ago

Post-1.0 means it isn't on the 1.0 roadmap, and that 1.0's release doesn't depend on this feature. Any/all help is welcome since many have asked for this feature, and it currently isn't the highest priority on my plate.

I've glossed over some implementation details, so feel free to ask questions, request feedback on patches, or prod me on some task.

robocoder commented 14 years ago

We should also reconsider using Zend for the Tracker.

Pros:

mattab commented 14 years ago

I moved some items from 'additional ideas' to TODO.

Side note: this Data access abstraction would make it easier to build sharding into Piwik, as we could have a Sharding schema, subclassing Mysql, that would modify queries to access the right shard when applicable.

robocoder commented 14 years ago

(In [refs #1368 - hard-code the list of supported adapters since it seems unlikely we'll have adapters as plugins; no longer depends on globr() or hack from 1632)

robocoder commented 14 years ago

(In [2265]) refs #1368 - Piwik::prefixTable() is deprecated

robocoder commented 14 years ago

(In [2266]) refs #1368 - Piwik::prefixTable() is deprecated

robocoder commented 14 years ago

(In [2267]) refs #1368 - remove deprecated functions: prefixTable (since 0.2.27), isPhpCliMode (since 0.4.4), and getMysqlVersion (since 0.4.4)

robocoder commented 14 years ago

(In [2268]) refs #1368 - initial refactoring of MySQL schema methods from Piwik.php

robocoder commented 14 years ago

(In [2273]) refs #1368 - rename Piwik_Db_iAdapter to Piwik_Db_Adapter_Interface for consistency

robocoder commented 14 years ago

(In [2274]) refs #1368 - further refactoring of Piwik.php; initial abstraction of MySQL schema

robocoder commented 14 years ago

(In [2276]) refs #1368 - move low-level $dbInfos mangling to adapter

robocoder commented 14 years ago

(In [2277]) refs #1368

robocoder commented 14 years ago

(In [2278]) refs #1335, refs #1368 - check in Jason's Piwik_Db_Adapter_Pdo_Mssql class (excluding the schema and query methods being refactored elsewhere; edited to conform to coding style guidelines; note: a lot of the logic in getConnection() looks like it should be moved upstream to ZF (2.0 CTP1 related?) especially if CTP2 introduces breaking changes to the DSN

robocoder commented 14 years ago

(In [2279]) refs #1368 - preprocessing the SQL to be made obsolete by query classes/methods

robocoder commented 14 years ago

(In [2281]) refs #1368 - more refactoring and phpdocs

robocoder commented 14 years ago

(In [2282]) refs #1368 - implemented isAvailable() and private method hasStorageEngine(); added Schema.loadSchema hook for Sharding plugin; more phpdocs

robocoder commented 14 years ago

(In [2739]) refs #1368 - use schema instead of adapter; in strict mode, update() can't be abstract

robocoder commented 14 years ago

Zend_Db_Adapter_Pdo_Sqlsrv: http://github.com/akrabat/Akrabat/blob/master/zf1/Akrabat/Db/Adapter/Pdo/Sqlsrv.php

mattab commented 13 years ago

Moving as it is more long term project

mattab commented 13 years ago

This will definitely be worked on to some extent (most likely: tracking code, archiving code for performance optimization) in 1.x, but it will be fully implemented (eg. sites/users/goals SQL will stay as is).

anonymous-matomo-user commented 13 years ago

Are there any updates?

Is it possible to get piwik at least tracking with mssql?

robocoder commented 13 years ago

dk-at-cabag: if there were updates, it would appear here in the trac log. This is a low priority enhancement. In terms of timeframe, I plan to work on this after the plugins repository is online.

re: mssql. You can try to port Jason's code (see #1335) to the latest Piwik release.

robocoder commented 13 years ago

(In [4690]) refs #1368 - refactoring the batch insert code

robocoder commented 13 years ago

(In [4693]) refs #1368

robocoder commented 13 years ago

See ticket #2593