Hello,
Am Freitag, 2. November 2007 schrieb David Goodwin:
> > Simply use CREATE TABLE IF NOT EXISTS ;-) (given PgSQL supports
> > it).
>
> Yes, that was my problem - I don't think PostgreSQL does.
:-(
> > I don't know if PgSQL supports the SHOW TABLES command or if we
> > have to read from information schema
> > http://www.postgresql.org/docs/8.2/interactive/infoschema-tables.ht
> >ml
>
> Probably.
You'll need to search for the details - I don't know much about PgSQL
and had to do lots of searches in the PgSQL documemtation to make the
SQL commands in upgrade.php as compatible as possibe.
> > Another option is to simply ignore the error ;-)
>
> I couldn't - as db_query was calling 'die()' when it failed.
Seems you used an old revision ;-)))
> > The basic idea is good.
> >
> > However, I change the do_upgrade function to use a classical
> > for ($i = 1; $i <= 10; $i++)
> > loop and function_exists(). This awoids the need to sort the
> > upgrade functions (which will break when we have >99 functions) ;-)
> > Note that you may not use leading zeros!
>
> Can they not be ordered lexiographically (spelling?) which would fix
> that issue; or alterantively, the script 'casts' the number into
> something with enough leading zeros as required using printf?
Maybe we talk at cross purposes - there is no need to use leading zeros.
This avoids all problems with fixed length. Given we would use fixed
length: what if we exceed the number the length allows? (Short answer:
rename _all_ upgrade_* functions.)
Without leading zeroes, it's very easy - there is no limit that we could
exceed.
The "sorting" of the functions is simply done when editing upgrade.php -
and if someone adds upgrade_42 between upgrade_2 and upgrade_3, I
promise to learn how to use the svn revert command ;-))
Running all functions in the correct order is also no problem. If you
have doubts, try
for ($i = 1, $i <= 100; $i++) { echo "$i\n"; }
> > I also added the option to create upgrade_<number>_mysql and
> > upgrade_<number>_pgsql functions for database-specific changes.
>
> I thought of that - but decided to not bother splitting it into two
> seperate bits - thinking that if all of a change was in one statement
> it would make it easier to follow. Of course, I could be mistaken
> about this.
This was also my first thought, but then I noticed that
- some changes only affect a specific database type (for example MySQL
engine and charset changes)
- some changes need a very different syntax, and it's not always
possible to merge into a single query
Therefore I added the _option_ to have database specific functions.
You can (and usually should) use upgrade_<number> for changes that
affect all database types.
The _mysql and _pgsql functions are just to avoid the need for checking
the database type in each function. In this case, I recommend to add a
comment "# MySQL only" or "# PgSQL only" at the "function ...()" line
to make it more visible that the function only runs on one database.
[...]
> > There are still several TODO notes in upgrade.php, especially
> > related to PgSQL.
>
> I'll try and resolve these soon.
Have fun - writing the ALTER statements can sometimes be very
interesting...
> > While talking about database upgrade:
> > I propose we should
> > - create the tables within upgrade.php (maybe we should rename it
> > ;-) - do all future database changes as ALTER statements within
> > upgrade.php - the function numbers should always be the SVN
> > revision numbers of the change
> > - drop DATABASE_*.TXT
> > - remaining question: where do we put the GRANT statements etc.?
> > Or can we assume that people who run a mailserver know how to
> > grant database permissions?
> > - drop DOCUMENTS/TABLE_BACKUP_MX.TXT and
> > DOCUMENTS/TABLE_CHANGES.TXT and remove the references to these
> > files in DOCUMENTS/UPGRADE.TXT
>
> All good ideas to me. If it's easy enough to write, it does make more
> sense to create the initial database structure from 'upgrade.php'
We will have to make the database dumps database independent (with
{whatever} placeholders if needed), but this shouldn't be too hard.
This is the "hardest" part - actually creating the tables simply means
adding another upgrade_* function. (Having a table_exists() function
would be nice, but ignoring errors also works.)
While talking about ignoring errors: Maybe we could even check for
the "usual" error messages and display everything else.
The list of error messages to ignore isn't too long. For MySQL, in RegEx
format:
Invalid query: Can't DROP .*; check that column/key exists
-> Index already dropped
Invalid query: Duplicate column name .*
-> column already added
Invalid query: Unknown column 'change_date' in .*
Invalid query: Unknown column 'create_date' in .*
-> renamed columns, listed with name because this shouldn't happen
too often
You'll have to find out the PgSQL error messages ;-)
> as well as handling anything else.
Tip: The developer doing a database change can simply paste his ALTER
TABLE statement (he needs it anyway to change his local database)
to upgrade.php, which is even easier than hand-editing the DATABASE_*
files.
Regards,
Christian Boltz
--
And as Novell has shown with the packager: it's never too late for
a beta, to add new features ;-) [Marcel Hilzinger in opensuse]
|