~coughphp/coughphp/2.0

« back to all changes in this revision

Viewing changes to design/Cough Generation.markdown

  • Committer: Anthony Bush
  • Date: 2008-08-23 03:35:08 UTC
  • mfrom: (262.1.18 coughphp-release-1.3)
  • Revision ID: anthony@anthonybush.com-20080823033508-uy4yn5pmio6wcetv
Accept release-1.3 branch changes into trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Cough Generation
2
 
================
3
 
 
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?
5
 
 
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...
7
 
 
8
 
With that, lets go ahead and define the responsibilities:
9
 
 
10
 
SchemaGenerator (or maybe CoughSchemaGenerator to avoid naming collisions)
11
 
---------------
12
 
 
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).
14
 
 
15
 
Schema (or maybe CoughSchema to avoid naming collisions)
16
 
------
17
 
 
18
 
Representation of the structure of a single database. This includes tables, the table's columns, and relationship between the tables.
19
 
 
20
 
Our requirements of the Schema are that it implements a particular interface:
21
 
 
22
 
        getDatabase()
23
 
                getDatabaseName()
24
 
                getTables()
25
 
                        getDatabase() -- reference to parent
26
 
                        getTableName()
27
 
                        getPrimaryKey() -- returns columns that take part in the PK
28
 
                        getColumns()
29
 
                                getColumnName()
30
 
                                isNullAllowed()
31
 
                                getDefaultValue()
32
 
                                getType()
33
 
                                getSize()
34
 
                                isPrimaryKey()
35
 
 
36
 
CoughGenerator
37
 
--------------
38
 
 
39
 
Takes a single Schema and generates a collection (array) of CoughFile objects.
40
 
 
41
 
CoughFile
42
 
---------
43
 
 
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).
45
 
 
46
 
CoughWriter (or CoughFileHandler ?)
47
 
-----------
48
 
 
49
 
Takes a collection (array) of CoughFile objects and chooses which ones to write to disk.
50
 
 
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).
52
 
 
53
 
CoughConfig
54
 
-----------
55
 
 
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:
57
 
 
58
 
        config/
59
 
                default/
60
 
                        DatabaseSchemaGenerator.config.php
61
 
                        CoughGenerator.config.php
62
 
 
63
 
DatabaseSchemaGenerator.config.php would probably contain configuration for the databases and tables to scan.
64
 
 
65
 
CoughGenerator.config.php would probably contain information on how to name the generated classes "_Collection", etc.
66
 
 
67
 
        config/
68
 
                default/
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
73
 
 
74
 
 
75
 
 
76
 
Usage Samples
77
 
-------------
78
 
 
79
 
We *could* make a factory that creates the correct schema generator object...
80
 
 
81
 
        <?php
82
 
        $schema = SchemaGeneratorFactory::getSchemaGenerator($coughConfig); // ?
83
 
        ?>
84
 
 
85
 
        <?php
86
 
        // Database Schema Generator example
87
 
        include_once(CONFIG_DIR . 'database_schema_generator.conf.php');
88
 
        $schemaGenerator = new DatabaseSchemaGenerator($config);
89
 
        $schemaGenerator->generateSchema();
90
 
        ?>
91
 
 
92
 
 
93
 
There will of course be assistants that already know how all the parts interact as a hole. Among these will be:
94
 
 
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.
99
 
* A web panel
100
 
        * Same as command line script, but with a GUI.
101
 
        * Will use config files.
102
 
* A wizard
103
 
        * Will assist in the modification of config files.
104
 
 
105
 
 
106
 
 
107
 
 
108
 
 
109
 
 
110
 
Checklist for implementation
111
 
----------------------------
112
 
 
113
 
Besides any missing documentation, the Schema needs:
114
 
 
115
 
* DriverColumn
116
 
* MysqlColumn
117
 
* ServerColumn
118
 
 
119
 
Columns in general need relationship or FK checking if that is not going to be done on the table level...
120
 
 
121
 
* DriverServer
122
 
* MysqlServer
123
 
* ServerServer
124
 
 
125
 
* DriverTable
126
 
* MysqlTable
127
 
* ServerTable
128
 
 
129
 
* DriverDatabase
130
 
* MysqlDatabase
131
 
* ServerDatabase
132
 
 
133
 
Next Up:
134
 
 
135
 
* What is interface for retrieving relationships between objects? 
136
 
 
137
 
Just thinking, but maybe:
138
 
 
139
 
        <?php
140
 
        foreach ($schema->getDatabases() as $database) {
141
 
                foreach ($database->getTables() as $table) {
142
 
                        // This tables data
143
 
                        $columns = $table->getColumns();
144
 
                        $pk = $table->getPrimaryKey();
145
 
                        
146
 
                        // Other tables that have this one's key 
147
 
                        foreach ($table->getHasOneRelationships() as $relationship) {
148
 
                                
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)),
153
 
                                );
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...
157
 
                        }
158
 
                        
159
 
                }
160
 
        }
161
 
        ?>
162
 
 
163
 
 
164
 
TODO: Resolve potential method naming collisions:
165
 
 
166
 
getCollection
167
 
getObject
168
 
getField
169
 
getFields
170
 
getFieldsWithoutPk
171
 
getPk
172
 
getKeyId
173
 
getPkFieldNames
174
 
getCollector
175
 
getValidationErrors
176
 
getUpdateFields
177
 
getInsertFields
178
 
getModifiedFields
179
 
getDerivedFields
180
 
getLoadSql
181
 
getLoadSqlWithoutWhere
182
 
 
183
 
These are also here, but we haven't discussed how we are going to do them for the 1.0 release:
184
 
 
185
 
getJoinField
186
 
getJoinFields
187
 
getJoinSelectSql
188
 
getJoinTableName
189