Revision 6947
Added by ben leinfelder about 11 years ago
upgrade-db-to-2.0.0-postgres.sql | ||
---|---|---|
116 | 116 |
FROM xml_access |
117 | 117 |
WHERE docid like '%.%.%.%'; |
118 | 118 |
|
119 |
|
|
119 | 120 |
/** |
120 | 121 |
* Update the accessfileid to use their guid |
121 | 122 |
* NOTE: uses the last revision's guid as the new value for accessfileid |
122 |
*/ |
|
123 |
* uses a temporary table |
|
124 |
**/ |
|
125 |
|
|
126 |
CREATE TABLE max_identifier (guid text, docid VARCHAR(250), rev INT8); |
|
127 |
|
|
128 |
/** insert the max rev identifier for each document **/ |
|
129 |
INSERT INTO max_identifier (docid, rev, guid) |
|
130 |
SELECT docid, MAX(rev), docid || '.' || MAX(rev) |
|
131 |
FROM identifier |
|
132 |
GROUP BY docid |
|
133 |
|
|
134 |
/** only need to join on docid since there is a single row for the max docid **/ |
|
123 | 135 |
UPDATE xml_access |
124 |
SET accessfileid = id.guid |
|
125 |
FROM identifier id, xml_access xa
|
|
126 |
WHERE xa.accessfileid = id.docid |
|
136 |
SET accessfileid = maxid.guid
|
|
137 |
FROM max_identifier maxid, xml_access xa
|
|
138 |
WHERE xa.accessfileid = maxid.docid
|
|
127 | 139 |
AND xa.guid IS NOT null |
128 |
AND id.rev = |
|
129 |
(SELECT MAX(id2.rev) FROM identifier id2 WHERE id.docid = id2.docid); |
|
130 | 140 |
|
141 |
DROP TABLE max_identifier; |
|
142 |
|
|
131 | 143 |
/** |
132 | 144 |
* Remove old access rules |
133 | 145 |
*/ |
Also available in: Unified diff
use a temporary table to calculate the maximum revision for a given docid and use that when setting the accessfileid during upgrade. the query plan for the all-in-one statement must be brutal as it's been running for 4 hours at this point....