[128499] trunk/base/src
cal at macports.org
cal at macports.org
Sat Nov 22 05:27:38 PST 2014
Revision: 128499
https://trac.macports.org/changeset/128499
Author: cal at macports.org
Date: 2014-11-22 05:27:38 -0800 (Sat, 22 Nov 2014)
Log Message:
-----------
base: Clean up registry database, see https://lists.macosforge.org/pipermail/macports-dev/2014-November/028782.html
The following changes are included in this change:
- Drop the `url' column from the ports table. It was unused and just wasting
space and time (because there was a unique index using it). Since SQLite
doesn't support ALTER TABLE DROP COLUMN, copy all data into a temporary
table, re-create the original one with the new schema and copy the data
back. Since this also drops all indices, re-create those as well.
- Drop the `url' column from the registry2.0/entryobj.c file, i.e. the Tcl
bindings for the registry.
- Drop the index using the `url' column.
- Drop the `mtime', `md5sum' and `editable' columns from the files table.
Those were originally added to support configuration file handling, which
has been implemented in GSoC 2010, but is currently not in a state that
could be merged into trunk. Let's drop these fields now, knowing that we can
easily re-add them later using the database upgrade code (which wasn't there
when the branch was developed), rather than keeping them around and unused
for a couple more years.
- Modify the Tcl API registry2.0/fileobj.c to no longer support the removed
fields.
- Change registry2.0/registry.tcl fileinfo_for_file to always return a dummy
md5 rather than querying the database for it. Essentially, this should mean
no change for clients of the API, because the database fields never
contained anything useful.
- Modify the C registry API cregistry/entry.c to no longer set the `mtime' to
the dummy value "0" on file creation.
- Add an index on dependencies(id) to help speed up JOINs involving
dependencies.
- Add indices portgroups(id) and portgroups(id, name, version, size, sha256)
to speed up portgroup management (the ID index) and opening portgroups from
registry.
- Update database version to 1.202
- Reformat database creation SQL statements to allow for easier diffing,
copying and changing by listing one field per line.
Modified Paths:
--------------
trunk/base/src/cregistry/entry.c
trunk/base/src/cregistry/sql.c
trunk/base/src/registry2.0/entryobj.c
trunk/base/src/registry2.0/fileobj.c
trunk/base/src/registry2.0/registry.tcl
Modified: trunk/base/src/cregistry/entry.c
===================================================================
--- trunk/base/src/cregistry/entry.c 2014-11-22 13:08:38 UTC (rev 128498)
+++ trunk/base/src/cregistry/entry.c 2014-11-22 13:27:38 UTC (rev 128499)
@@ -783,8 +783,8 @@
reg_registry* reg = entry->reg;
int result = 1;
sqlite3_stmt* stmt = NULL;
- char* insert = "INSERT INTO registry.files (id, path, mtime, active) "
- "VALUES (?, ?, 0, 0)";
+ char* insert = "INSERT INTO registry.files (id, path, active) "
+ "VALUES (?, ?, 0)";
if ((sqlite3_prepare_v2(reg->db, insert, -1, &stmt, NULL) == SQLITE_OK)
&& (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)) {
int i;
Modified: trunk/base/src/cregistry/sql.c
===================================================================
--- trunk/base/src/cregistry/sql.c 2014-11-22 13:08:38 UTC (rev 128498)
+++ trunk/base/src/cregistry/sql.c 2014-11-22 13:27:38 UTC (rev 128499)
@@ -129,43 +129,64 @@
/* metadata table */
"CREATE TABLE registry.metadata (key UNIQUE, value)",
- "INSERT INTO registry.metadata (key, value) VALUES ('version', '1.201')",
+ "INSERT INTO registry.metadata (key, value) VALUES ('version', '1.202')",
"INSERT INTO registry.metadata (key, value) VALUES ('created', strftime('%s', 'now'))",
/* ports table */
"CREATE TABLE registry.ports ("
- "id INTEGER PRIMARY KEY, "
- "name TEXT COLLATE NOCASE, portfile TEXT, url TEXT, "
- "location TEXT, epoch INTEGER, version TEXT COLLATE VERSION, "
- "revision INTEGER, variants TEXT, negated_variants TEXT, "
- "state TEXT, date DATETIME, installtype TEXT, archs TEXT, "
- "requested INT, os_platform TEXT, os_major INTEGER, "
- "UNIQUE (name, epoch, version, revision, variants), "
- "UNIQUE (url, epoch, version, revision, variants)"
+ "id INTEGER PRIMARY KEY"
+ ", name TEXT COLLATE NOCASE"
+ ", portfile TEXT"
+ ", location TEXT"
+ ", epoch INTEGER"
+ ", version TEXT COLLATE VERSION"
+ ", revision INTEGER"
+ ", variants TEXT"
+ ", negated_variants TEXT"
+ ", state TEXT"
+ ", date DATETIME"
+ ", installtype TEXT"
+ ", archs TEXT"
+ ", requested INTEGER"
+ ", os_platform TEXT"
+ ", os_major INTEGER"
+ ", UNIQUE (name, epoch, version, revision, variants)"
")",
- "CREATE INDEX registry.port_name ON ports "
+ "CREATE INDEX registry.port_name ON ports"
"(name, epoch, version, revision, variants)",
- "CREATE INDEX registry.port_url ON ports "
- "(url, epoch, version, revision, variants)",
- "CREATE INDEX registry.port_state ON ports (state)",
+ "CREATE INDEX registry.port_state ON ports(state)",
/* file map */
- "CREATE TABLE registry.files (id INTEGER, path TEXT, actual_path TEXT, "
- "active INT, mtime DATETIME, md5sum TEXT, editable INT, binary BOOL, "
- "FOREIGN KEY(id) REFERENCES ports(id))",
- "CREATE INDEX registry.file_port ON files (id)",
+ "CREATE TABLE registry.files ("
+ "id INTEGER"
+ ", path TEXT"
+ ", actual_path TEXT"
+ ", active INTEGER"
+ ", binary BOOL"
+ ", FOREIGN KEY(id) REFERENCES ports(id))",
+ "CREATE INDEX registry.file_port ON files(id)",
"CREATE INDEX registry.file_path ON files(path)",
"CREATE INDEX registry.file_actual ON files(actual_path)",
/* dependency map */
- "CREATE TABLE registry.dependencies (id INTEGER, name TEXT, variants TEXT, "
- "FOREIGN KEY(id) REFERENCES ports(id))",
- "CREATE INDEX registry.dep_name ON dependencies (name)",
+ "CREATE TABLE registry.dependencies ("
+ "id INTEGER"
+ ", name TEXT"
+ ", variants TEXT"
+ ", FOREIGN KEY(id) REFERENCES ports(id))",
+ "CREATE INDEX registry.dep_id ON dependencies(id)",
+ "CREATE INDEX registry.dep_name ON dependencies(name)",
/* portgroups table */
- "CREATE TABLE registry.portgroups (id INTEGER, "
- "name TEXT, version TEXT COLLATE VERSION, size INTEGER, sha256 TEXT, "
- "FOREIGN KEY(id) REFERENCES ports(id))",
+ "CREATE TABLE registry.portgroups ("
+ "id INTEGER"
+ ", name TEXT"
+ ", version TEXT COLLATE VERSION"
+ ", size INTEGER"
+ ", sha256 TEXT"
+ ", FOREIGN KEY(id) REFERENCES ports(id))",
+ "CREATE INDEX registry.portgroup_id ON portgroups(id)",
+ "CREATE INDEX registry.portgroup_open ON portgroups(id, name, version, size, sha256)",
"COMMIT",
NULL
@@ -335,9 +356,13 @@
from Tcl, so here we'll just flag that it needs to be done. */
static char* version_1_2_queries[] = {
/* portgroups table */
- "CREATE TABLE registry.portgroups (id INTEGER, "
- "name TEXT, version TEXT COLLATE VERSION, size INTEGER, sha256 TEXT, "
- "FOREIGN KEY(id) REFERENCES ports(id))",
+ "CREATE TABLE registry.portgroups ("
+ "id INTEGER"
+ ", name TEXT"
+ ", version TEXT COLLATE VERSION"
+ ", size INTEGER"
+ ", sha256 TEXT"
+ ", FOREIGN KEY(id) REFERENCES ports(id))",
"UPDATE registry.metadata SET value = '1.200' WHERE key = 'version'",
@@ -380,6 +405,179 @@
continue;
}
+ if (sql_version(NULL, -1, version, -1, "1.202") < 0) {
+ static char* version_1_202_queries[] = {
+ "CREATE INDEX registry.portgroup_id ON portgroups(id)",
+ "CREATE INDEX registry.portgroup_open ON portgroups(id, name, version, size, sha256)",
+ "CREATE INDEX registry.dep_id ON dependencies(id)",
+
+ /*
+ * SQLite doesn't support ALTER TABLE DROP CONSTRAINT or ALTER
+ * TABLE DROP COLUMN, so we're doing the manual way to remove
+ * UNIQUE(url, epoch, version, revision, variants) and the url
+ * column.
+ */
+
+ /* Create a temporary table */
+ "CREATE TEMPORARY TABLE mp_ports_backup ("
+ "id INTEGER PRIMARY KEY"
+ ", name TEXT COLLATE NOCASE"
+ ", portfile CLOB"
+ ", location TEXT"
+ ", epoch INTEGER"
+ ", version TEXT COLLATE VERSION"
+ ", revision INTEGER"
+ ", variants TEXT"
+ ", negated_variants TEXT"
+ ", state TEXT"
+ ", date DATETIME"
+ ", installtype TEXT"
+ ", archs TEXT"
+ ", requested INT"
+ ", os_platform TEXT"
+ ", os_major INTEGER"
+ ", UNIQUE(name, epoch, version, revision, variants))",
+
+ /* Copy all data into the temporary table */
+ "INSERT INTO mp_ports_backup "
+ "SELECT"
+ " id"
+ ", name"
+ ", portfile"
+ ", location"
+ ", epoch"
+ ", version"
+ ", revision"
+ ", variants"
+ ", negated_variants"
+ ", state"
+ ", date"
+ ", installtype"
+ ", archs"
+ ", requested"
+ ", os_platform"
+ ", os_major"
+ " FROM registry.ports",
+
+ /* Drop the original table and re-create it with the new structure */
+ "DROP TABLE registry.ports",
+ "CREATE TABLE registry.ports ("
+ "id INTEGER PRIMARY KEY"
+ ", name TEXT COLLATE NOCASE"
+ ", portfile CLOB"
+ ", location TEXT"
+ ", epoch INTEGER"
+ ", version TEXT COLLATE VERSION"
+ ", revision INTEGER"
+ ", variants TEXT"
+ ", negated_variants TEXT"
+ ", state TEXT"
+ ", date DATETIME"
+ ", installtype TEXT"
+ ", archs TEXT"
+ ", requested INT"
+ ", os_platform TEXT"
+ ", os_major INTEGER"
+ ", UNIQUE(name, epoch, version, revision, variants))",
+
+ /* Copy all data back from temporary table */
+ "INSERT INTO registry.ports "
+ "SELECT"
+ " id"
+ ", name"
+ ", portfile"
+ ", location"
+ ", epoch"
+ ", version"
+ ", revision"
+ ", variants"
+ ", negated_variants"
+ ", state"
+ ", date"
+ ", installtype"
+ ", archs"
+ ", requested"
+ ", os_platform"
+ ", os_major"
+ " FROM mp_ports_backup",
+
+ /* Re-create indices that have been dropped with the table */
+ "CREATE INDEX registry.port_name ON ports(name, epoch, version, revision, variants)",
+ "CREATE INDEX registry.port_state ON ports(state)",
+
+ /* Remove temporary table */
+ "DROP TABLE mp_ports_backup",
+
+ /*
+ * SQLite doesn't support ALTER TABLE DROP COLUMN, so we're
+ * doing the manual way to remove files.md5sum, files.mtime,
+ * files.editable.
+ */
+
+ /* Create a temporary table */
+ "CREATE TEMPORARY TABLE mp_files_backup ("
+ "id INTEGER"
+ ", path TEXT"
+ ", actual_path TEXT"
+ ", active INTEGER"
+ ", binary BOOL"
+ ")",
+
+ /* Copy all data into the temporary table */
+ "INSERT INTO mp_files_backup "
+ "SELECT"
+ " id"
+ ", path"
+ ", actual_path"
+ ", active"
+ ", binary"
+ " FROM registry.files",
+
+ /* Drop the original table and re-create it with the new structure */
+ "DROP TABLE registry.files",
+ "CREATE TABLE registry.files ("
+ "id INTEGER"
+ ", path TEXT"
+ ", actual_path TEXT"
+ ", active INTEGER"
+ ", binary BOOL"
+ ", FOREIGN KEY(id) REFERENCES ports(id))",
+
+ /* Copy all data back from temporary table */
+ "INSERT INTO registry.files "
+ "SELECT"
+ " id"
+ ", path"
+ ", actual_path"
+ ", active"
+ ", binary"
+ " FROM mp_files_backup",
+
+ /* Re-create indices that have been dropped with the table */
+ "CREATE INDEX registry.file_port ON files(id)",
+ "CREATE INDEX registry.file_path ON files(path)",
+ "CREATE INDEX registry.file_actual ON files(actual_path)",
+
+ /* Remove temporary table */
+ "DROP TABLE mp_files_backup",
+
+ /* Update version and commit */
+ "UPDATE registry.metadata SET value = '1.202' WHERE key = 'version'",
+ "COMMIT",
+ NULL
+ };
+
+ sqlite3_finalize(stmt);
+ stmt = NULL;
+ if (!do_queries(db, version_1_202_queries, errPtr)) {
+ rollback_db(db);
+ return 0;
+ }
+
+ did_update = 1;
+ continue;
+ }
+
/* add new versions here, but remember to:
* - finalize the version query statement and set stmt to NULL
* - do _not_ use "BEGIN" in your query list, since a transaction has
Modified: trunk/base/src/registry2.0/entryobj.c
===================================================================
--- trunk/base/src/registry2.0/entryobj.c 2014-11-22 13:08:38 UTC (rev 128498)
+++ trunk/base/src/registry2.0/entryobj.c 2014-11-22 13:27:38 UTC (rev 128499)
@@ -42,7 +42,6 @@
const char* entry_props[] = {
"name",
"portfile",
- "url",
"location",
"epoch",
"version",
@@ -419,7 +418,6 @@
/* keys */
{ "name", entry_obj_prop },
{ "portfile", entry_obj_prop },
- { "url", entry_obj_prop },
{ "location", entry_obj_prop },
{ "epoch", entry_obj_prop },
{ "version", entry_obj_prop },
Modified: trunk/base/src/registry2.0/fileobj.c
===================================================================
--- trunk/base/src/registry2.0/fileobj.c 2014-11-22 13:08:38 UTC (rev 128498)
+++ trunk/base/src/registry2.0/fileobj.c 2014-11-22 13:27:38 UTC (rev 128499)
@@ -44,9 +44,6 @@
"path",
"actual_path",
"active",
- "mtime",
- "md5sum",
- "editable",
"binary",
NULL
};
@@ -110,9 +107,6 @@
{ "path", file_obj_prop },
{ "actual_path", file_obj_prop },
{ "active", file_obj_prop },
- { "mtime", file_obj_prop },
- { "md5sum", file_obj_prop },
- { "editable", file_obj_prop },
{ "binary", file_obj_prop },
{ NULL, NULL }
};
Modified: trunk/base/src/registry2.0/registry.tcl
===================================================================
--- trunk/base/src/registry2.0/registry.tcl 2014-11-22 13:08:38 UTC (rev 128498)
+++ trunk/base/src/registry2.0/registry.tcl 2014-11-22 13:27:38 UTC (rev 128499)
@@ -311,7 +311,7 @@
# 2: gid
# 3: mode
# 4: size
-# 5: md5 checksum information
+# 5: md5 checksum information (deprecated, will always be "MD5 ($filename) NONE")
#
# fname a path to a given file.
# return a 6-tuple about this file.
@@ -320,16 +320,7 @@
# (we won't store the md5 of the target of links since it's meaningless
# and $statvar(mode) tells us that links are links).
if {![catch {file lstat $fname statvar}]} {
- if {[::file isfile $fname] && [::file type $fname] ne "link"} {
- if {[catch {md5 file $fname} md5sum] == 0} {
- # Create a line that matches md5(1)'s output
- # for backwards compatibility
- set line "MD5 ($fname) = $md5sum"
- return [list $fname $statvar(uid) $statvar(gid) $statvar(mode) $statvar(size) $line]
- }
- } else {
- return [list $fname $statvar(uid) $statvar(gid) $statvar(mode) $statvar(size) "MD5 ($fname) NONE"]
- }
+ return [list $fname $statvar(uid) $statvar(gid) $statvar(mode) $statvar(size) "MD5 ($fname) NONE"]
}
return {}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20141122/119c086b/attachment-0001.html>
More information about the macports-changes
mailing list