Closed (fixed)
Project:
Drupal core
Version:
x.y.z
Component:
database system
Priority:
Critical
Category:
Task
Reporter:
Created:
17 Aug 2005 at 21:25 UTC
Updated:
18 Nov 2005 at 20:01 UTC
Jump to comment: Most recent file
Postgres, since 6.4, has version() function so you can check db version from SQL. This can be used in updates.inc for example for conditional dropping of the column (which is available since 7.3, not 7.4 as stated in updates.inc).
I need to check how the version string is returned in different versions before making changes.
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | drupal-head-db_add_column-29082_9.diff | 24.82 KB | Cvbge |
| #28 | drupal-head-db_add_column-29082_8.diff | 24.88 KB | Cvbge |
| #27 | drupal-head-db_add_column-29082_7.diff | 24.88 KB | Cvbge |
| #25 | drupal-head-db_add_column-29082_6.diff | 24.85 KB | Cvbge |
| #20 | drupal-head-db_add_column-29082-example_separate_files.diff | 30.74 KB | Cvbge |
Comments
Comment #1
Cvbge commentedHere's a function returning postgres db version. I'm not sure if it fits in updates.inc, maybe it should be somewhere else.
Comment #2
Cvbge commentedAdded 2 new functions to add or change column definition. The take care about mysql/pgsql. Code not tested, will test and update old code when I hear that this has a chanse to go in ;)
Comment #3
Cvbge commentedStill more work needed.
Comment #4
Cvbge commentedWith attached patch I could make all updates without errors (my LOCKs patch was needed - http://drupal.org/node/22911). There are still some issues that should be addressed (see the patch). Also mysql update is not tested - please test.
There are some problems when updating from 4.6 to cvs. Maybe the update should be made by 4.6 base itself?
So I've started with fresh 4.6.3.
After changing the base to cvs, patching with the LOCKs patch and simple debug helper patch, on update.php?op=update I get following errors:
As we can see the problem is that there is no cache column is session table - that's update_130. Also there's no column 'referer' in watchdog table - that's update_142. So I've commented out update_130 and 142, added the columns by hand in the db and started again from the begining.
After that I got another error:
That's update_136. So, disable update_136 and do it by hand and start again.
After all that, when accessing update.php?op=update I noticed no errors. After pressing Update all updates were applied without any errors. But when accessed main page I got a screen as on attached screenshot.
Comment #5
Cvbge commentedAnd the mentioned patch.
Critical because otherwise upgrades (at least for postgres) are impossibile.
Comment #6
Cvbge commentedI need people to test mysql updates, as I changed mysql part too.
Comment #7
Cvbge commentedA diffrent patch. Only adds 3 functions for adding and changing table columns, does not modifies any old updates.
There are still some issues to be solved, for example:
- when changing a column in mysql the PRIMARY KEY attribute is retained. In Postgres, due to the
nature of changing process (i.e. dropping the column) this attribute is dropped. How to workaround it?
Need to check other attributes too (e.g. NOT NULL, index etc).
- add more attributes? Like primary key, key (mysql: synonim dla unique), unique, index, auto increment (mysql: must be indexed and must have a default) ?
- in CHANGE when setting NOT NOLL, and DEFAULT is set, update the table to default WHERE column IS NULL ?
Comment #8
Cvbge commentedUpdated patch based on http://drupal.org/node/7582
Following functions are defined:
db_change_column() still need some work, the rest should work as documented.
Comment #9
Cvbge commentedAnother version: I've decided to stop supporting postgresql 7.2.
7.2 is still maintained, but first 7.2 release come out in 2002-02-04, last one (7.2.8) in 2005-05-09.
Next stable line, 7.3, came out in 2002-11-27, which is almost 3 years ago. That version introduced many new features, see http://www.postgresql.org/docs/8.0/interactive/release-7-3.html for details.
Currently latest stable version is 8.0.3 from 2005-05-09
This means DROP COLUMN and dropping primary keys as DROP CONSTRAINT works and there's no need for drupal_pg_version() nor db_drop_column().
It'd be good to ask on drupal.org if people are still using Postgresql 7.2. Would it be possibile to create a poll with questions "which database you are using?" and answers "postgres 7.2, postgres 7.3, ... , mysql 3.0.x, mysql 4.0.x, ..." ?
Comment #10
Cvbge commentedUpdated to current head.
Comment #11
Cvbge commentedAttaching fixed update_() functions up to update_143(). Not at least it executes those functions without errors, I still need to check if they are 100% ok (but I believe they are for 90% ;))
Besides this patch you need to apply the one from #10
Comment #12
Cvbge commentedupdate_() all execute without errors, but still not ideal.
Fixed database.pgsql a bit too.
You should apply this patch as first.
Comment #13
Cvbge commentedI've removed dropping columns, I'm not dropping postgresql 7.2 support after all.
Apply this patch as second.
Comment #14
Cvbge commentedFixed some small bugs. Now both parts in 1 patch.
After update there's a problem with themes? Or blocks? I don't know... The screen after update looks like http://cvbge.org/after_update.png
Any idea what can be the reason?
Comment #15
Cvbge commentedThe screen I got was because of lack of xtemplate engine. The template 4.6 was using was a bluemarine, which uses xtemplate in 4.6 branch.
HEAD branch does not have xtemplate which causes problems. I had to fix system table by hand:
Comment #16
Cvbge commentedI've just checked mysql part of the patch (me! mysql! horrible! ;) - done mysqldump of fresh 4.6 install, then upgraded to head with original and patched drupal, doing dump for each update. Then diff'ed the dump, which showed only 1 change in database schema:
- KEY `title` (`title`)in boxes table, which is intentional, because database.mysql does not have KEY on title in that table.
Thus I consider this patch ready to be committed.
BTW, the problem with xtemplate from previous comment occurs for mysql too.
Comment #17
Cvbge commentedOne more comment: I've tried not to make any changes to mysql part of update_() functions when creating the patch.
Comment #18
dries commentedDo we really need these helper functions? For me, the code becomes harder to read with those. When dealing with SQL queries, I'd like to know _exactly_ what's going on.
Comment #19
Cvbge commentedDo we *need* them? No, but using them is better then not using, IMO.
For example current update_115():
could be written as
This would take care of all differences between postgres, mysql (or future databases, sqlite?)
Another, even more drastic example is from update_137(), where 1 line of mysql sql code must be changed to 5(6) lines of postgres code:
could be wrote simply as
In case of mysql it is not a big problem IMO, because the functions execute almost identical statements. For example
which has large body and documentation, is in fact very simple and for mysql it only executes
Having this automated means I won't make some silly typo nor any other mistake when writing that code. Probably I won't have to fix nor add to the original patch at all!
Of course, I'll have to check if the function can be used. It does not work for *all* cases. But still it is huge help for me (or anyone who writes mysql and postgres code).
If the functions do no have bugs then all their calls should not have bugs.
And the last idea: maybe it'd be better to move the functions to updates.{mysql,pgsql}.inc and include them depending on $db_type, like it is done with database.{mysql,pgsql}.inc? That would make updates.inc less cluttered and code in the functions much simpler (in mysql case at least)
Comment #20
Cvbge commentedHere's implementation of the last idea (not tested, just an example).
I'd prefer to keep the functions as 1 function after all, they are very similar.
Comment #21
dries commentedI still disagree with your statement that it's easier to read:
is easier to read and faster to write than:
It might make sense for db_add_column() and db_change_column() (because the PostgreSQL alternative is complex) but it doesn't make sense for the other helper functions IMO. Either way, the proposed API functions are a lot less transparant.
No point moving this to separate files. This might change as soon the update system improvements hit core. If we move forward with this, we'll go with derivates of #14. I don't think I'll commit it with all the helper functions.
Comment #22
Cvbge commentedWell, if you add time to write
switch ($GLOBALS['db_type']) {and pgsql version, which I usually have to check and fix and post new patch - then I think db_* functions will be faster and easier.Besides, do you actually *need* to see the real SQL? I think there's only one correct way to add/drop index(key)/primary key. How using a function would break anything?
Anyway, if you still don't agree I see two possibile compromises:
db_add_column()anddb_change_column()and write separate code for other cases, as you proposedI'd prefer the second choise, but will live with the first one too.
Comment #23
Cvbge commentedI've forgot, there's of course 3rd possibility - leave mysql alone and use db_* functions for postgres only.
Comment #24
dries commentedSorry, I still don't agree.
Comment #25
Cvbge commentedChanged the patch as you asked, added small guide on mysql2pgsql conversion.
The only changes to mysql part are:
- removed AFTER timestamp in update_130()
- removed creation of index in update_131(), it's not in database.{mysql,pgsql}
Still need to test the patch.
Comment #26
Cvbge commentedTested as in #16, same result.
Comment #27
Cvbge commentedPostgresql bugfixes
Comment #28
Cvbge commentedMore bug, which would not happen if I could use db_ functions and didn't forgot a small change in two places ;)
Comment #29
dries commentedIs this correct?
Comment #30
Cvbge commentedYes, it was removed in update_105() in mysql part only. I've decided to support postgres 7.2 after all, so I've renamed the column to _old to be consistent. Executing or not executing this update should not change much now, but can be usefull in future or if someone needs to have quick list of "old" columns.
Comment #31
dries commentedThe patch no longer applies against HEAD. Sorry. Could you update it once more? Thanks Cvbge!
Comment #32
Cvbge commentedUpdated.
Comment #33
dries commentedCommitted to HEAD. Thanks.
Comment #34
(not verified) commented