4
Question: Do we use one config array/object for all generation classes and let them choose which configuration options they want to use or do we separate configuration?
6
Some of this question lies within where each of the generation classes responsibility lies, but even if we clearly define separate responsibilities, we might still want a shared configuration...
8
With that, lets go ahead and define the responsibilities:
10
SchemaGenerator (or maybe CoughSchemaGenerator to avoid naming collisions)
13
A Schema Generator is reponsible for creating a Schema object. It's input is undefined, so that it may take a file name (e.g. XML file for the XML Driven Schema Generator) or an array containing database configuration information (e.g. Database Driven Schema Generator). The point is that they all support a `generateSchema()` method which should return a Schema object (or throw an Exception if no Schema can be generated).
15
Schema (or maybe CoughSchema to avoid naming collisions)
18
Representation of the structure of a single database. This includes tables, the table's columns, and relationship between the tables.
20
Our requirements of the Schema are that it implements a particular interface:
25
getDatabase() -- reference to parent
27
getPrimaryKey() -- returns columns that take part in the PK
39
Takes a single Schema and generates a collection (array) of CoughFile objects.
44
Capable of writing itself to disk, a CoughFile is simply a filename, its (soon to be) contents, and any metadata Cough needs (e.g. whether or not it is a "starter" file).
46
CoughWriter (or CoughFileHandler ?)
49
Takes a collection (array) of CoughFile objects and chooses which ones to write to disk.
51
It is also capable of providing information of what changes would take effect before making them (e.g. files that might be removed, added, modified).
56
Do we need a class to manage the configuration settings? It seems like we might need to move away from the single array in one config file to several config files. For example:
60
DatabaseSchemaGenerator.config.php
61
CoughGenerator.config.php
63
DatabaseSchemaGenerator.config.php would probably contain configuration for the databases and tables to scan.
65
CoughGenerator.config.php would probably contain information on how to name the generated classes "_Collection", etc.
69
schema_generator.conf.php
70
<xml_schema.xml> -- if the schema generator to be used is the Xml one...
71
<database_schema_generator.conf.php> -- if the schema generator to be used is the Database one...
72
cough_generator.conf.php
79
We *could* make a factory that creates the correct schema generator object...
82
$schema = SchemaGeneratorFactory::getSchemaGenerator($coughConfig); // ?
86
// Database Schema Generator example
87
include_once(CONFIG_DIR . 'database_schema_generator.conf.php');
88
$schemaGenerator = new DatabaseSchemaGenerator($config);
89
$schemaGenerator->generateSchema();
93
There will of course be assistants that already know how all the parts interact as a hole. Among these will be:
95
* A command line script
96
* Can show status (added, removed, and modified files) without actually writing anything to disk.
97
* Can (re)-generate files.
98
* Will use config files.
100
* Same as command line script, but with a GUI.
101
* Will use config files.
103
* Will assist in the modification of config files.
110
Checklist for implementation
111
----------------------------
113
Besides any missing documentation, the Schema needs:
119
Columns in general need relationship or FK checking if that is not going to be done on the table level...
135
* What is interface for retrieving relationships between objects?
137
Just thinking, but maybe:
140
foreach ($schema->getDatabases() as $database) {
141
foreach ($database->getTables() as $table) {
143
$columns = $table->getColumns();
144
$pk = $table->getPrimaryKey();
146
// Other tables that have this one's key
147
foreach ($table->getHasOneRelationships() as $relationship) {
149
$relationship = array(
150
array($table->getColumn($col1), $relatedTable->getColumn($col2)),
151
// Most will only have one id -> one id, but we can allow more than one via:
152
// array($table->getColumn($col3), $relatedTable->getColumn($col4)),
154
// Um, how do we know which keys relate?
155
// We just want what columns on $table link to what columns on $relatedTable.
156
// ticket_line_id -> order_line_item_id, e.g. So we just need references...
164
TODO: Resolve potential method naming collisions:
181
getLoadSqlWithoutWhere
183
These are also here, but we haven't discussed how we are going to do them for the 1.0 release: