| | @@ -78,19 +78,39 @@ |
| 78 | 78 | @ mtime INTEGER, -- Time last modified. Seconds since 1970 |
| 79 | 79 | @ cols TEXT, -- A color-key specification |
| 80 | 80 | @ sqlcode TEXT -- An SQL SELECT statement for this report |
| 81 | 81 | @ ); |
| 82 | 82 | ; |
| 83 | +static const char zCreateHnameTable[] = |
| 84 | +@ -- The hname table provides mappings from artifact hashes (hval) to the |
| 85 | +@ -- artifact id (rid). This table was added in Fossil-2.0. Prior to |
| 86 | +@ -- Fossil-2.0, there was only a single SHA1 hash value for each artifact |
| 87 | +@ -- which was stored in the BLOB.UUID field. With the introduction of |
| 88 | +@ -- multiple hash algorithms, the hval to rid mapping went from one-to-one to |
| 89 | +@ -- many-to-one and a new table became necessary. |
| 90 | +@ -- |
| 91 | +@ CREATE TABLE hname( |
| 92 | +@ hval TEXT, -- Hex-encoded hash value |
| 93 | +@ htype ANY, -- Type of hash. Preferred hash: 0 |
| 94 | +@ rid INTEGER REFERENCES blob, -- Blob that this hash names |
| 95 | +@ PRIMARY KEY(hval,htype) |
| 96 | +@ ) WITHOUT ROWID; |
| 97 | +@ INSERT INTO hname(hval,htype,rid) SELECT uuid,0,rid FROM blob; |
| 98 | +@ CREATE INDEX hname_rid ON hname(rid,htype); |
| 99 | +; |
| 83 | 100 | |
| 101 | +/* |
| 102 | +** Update the schema as necessary |
| 103 | +*/ |
| 84 | 104 | static void rebuild_update_schema(void){ |
| 85 | 105 | int rc; |
| 86 | 106 | db_multi_exec("%s", zSchemaUpdates1 /*safe-for-%s*/); |
| 87 | 107 | db_multi_exec("%s", zSchemaUpdates2 /*safe-for-%s*/); |
| 88 | 108 | |
| 89 | | - rc = db_exists("SELECT 1 FROM sqlite_master" |
| 90 | | - " WHERE name='user' AND sql GLOB '* mtime *'"); |
| 91 | | - if( rc==0 ){ |
| 109 | + /* Add the user.mtime column if it is missing. |
| 110 | + */ |
| 111 | + if( !db_table_has_column("repository", "user", "mtime") ){ |
| 92 | 112 | db_multi_exec( |
| 93 | 113 | "CREATE TEMP TABLE temp_user AS SELECT * FROM user;" |
| 94 | 114 | "DROP TABLE user;" |
| 95 | 115 | "CREATE TABLE user(\n" |
| 96 | 116 | " uid INTEGER PRIMARY KEY,\n" |
| | @@ -109,32 +129,32 @@ |
| 109 | 129 | " ipaddr, cexpire, info, now(), photo FROM temp_user;" |
| 110 | 130 | "DROP TABLE temp_user;" |
| 111 | 131 | ); |
| 112 | 132 | } |
| 113 | 133 | |
| 114 | | - rc = db_exists("SELECT 1 FROM sqlite_master" |
| 115 | | - " WHERE name='config' AND sql GLOB '* mtime *'"); |
| 116 | | - if( rc==0 ){ |
| 134 | + /* Add the config.mtime column if it is missing. |
| 135 | + */ |
| 136 | + if( !db_table_has_column("repository", "config", "mtime") ){ |
| 117 | 137 | db_multi_exec( |
| 118 | 138 | "ALTER TABLE config ADD COLUMN mtime INTEGER;" |
| 119 | 139 | "UPDATE config SET mtime=now();" |
| 120 | 140 | ); |
| 121 | 141 | } |
| 122 | 142 | |
| 123 | | - rc = db_exists("SELECT 1 FROM sqlite_master" |
| 124 | | - " WHERE name='shun' AND sql GLOB '* mtime *'"); |
| 125 | | - if( rc==0 ){ |
| 143 | + /* Add the shun.mtime and shun.scom columns if they are missing. |
| 144 | + */ |
| 145 | + if( !db_table_has_column("repository", "shun", "mtime") ){ |
| 126 | 146 | db_multi_exec( |
| 127 | 147 | "ALTER TABLE shun ADD COLUMN mtime INTEGER;" |
| 128 | 148 | "ALTER TABLE shun ADD COLUMN scom TEXT;" |
| 129 | 149 | "UPDATE shun SET mtime=now();" |
| 130 | 150 | ); |
| 131 | 151 | } |
| 132 | 152 | |
| 133 | | - rc = db_exists("SELECT 1 FROM sqlite_master" |
| 134 | | - " WHERE name='reportfmt' AND sql GLOB '* mtime *'"); |
| 135 | | - if( rc==0 ){ |
| 153 | + /* Add the reportfmt.mtime column if it is missing. |
| 154 | + */ |
| 155 | + if( !db_table_has_column("repository", "reportfmt", "mtime") ){ |
| 136 | 156 | db_multi_exec( |
| 137 | 157 | "CREATE TEMP TABLE old_fmt AS SELECT * FROM reportfmt;" |
| 138 | 158 | "DROP TABLE reportfmt;" |
| 139 | 159 | ); |
| 140 | 160 | db_multi_exec("%s", zSchemaUpdates2/*safe-for-%s*/); |
| | @@ -145,18 +165,30 @@ |
| 145 | 165 | " SELECT rn, owner, title || ' (' || rn || ')', cols, sqlcode, now()" |
| 146 | 166 | " FROM old_fmt;" |
| 147 | 167 | ); |
| 148 | 168 | } |
| 149 | 169 | |
| 150 | | - rc = db_exists("SELECT 1 FROM sqlite_master" |
| 151 | | - " WHERE name='concealed' AND sql GLOB '* mtime *'"); |
| 152 | | - if( rc==0 ){ |
| 170 | + /* Add the concealed.mtime column if it is missing. |
| 171 | + */ |
| 172 | + if( !db_table_has_column("repository", "concealed", "mtime") ){ |
| 153 | 173 | db_multi_exec( |
| 154 | 174 | "ALTER TABLE concealed ADD COLUMN mtime INTEGER;" |
| 155 | 175 | "UPDATE concealed SET mtime=now();" |
| 156 | 176 | ); |
| 157 | 177 | } |
| 178 | + |
| 179 | + /* If the hname table is missing, that means we are dealing with an |
| 180 | + ** older Fossil 1.x database. Create the hname table an populate it |
| 181 | + ** with the SHA1 hash values in the blob.uuid field. |
| 182 | + ** |
| 183 | + ** TODO: After all the rest of the code is updated to use the hname |
| 184 | + ** table instead of the blob.uuid column, also delete the blob.uuid |
| 185 | + ** column. |
| 186 | + */ |
| 187 | + if( !db_table_exists("repository", "hname") ){ |
| 188 | + db_multi_exec("%s", zCreateHnameTable/*safe-for-%s*/); |
| 189 | + } |
| 158 | 190 | } |
| 159 | 191 | |
| 160 | 192 | /* |
| 161 | 193 | ** Variables used to store state information about an on-going "rebuild" |
| 162 | 194 | ** or "deconstruct". |
| 163 | 195 | |