[Openvas-commits] r5656 - in trunk/openvas-manager: . src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 20 22:32:15 CEST 2009
Author: mattm
Date: 2009-10-20 22:32:14 +0200 (Tue, 20 Oct 2009)
New Revision: 5656
Modified:
trunk/openvas-manager/ChangeLog
trunk/openvas-manager/src/tasks_sql.h
Log:
Add database migration from version 0 to 1.
* src/tasks_sql.h (manage_db_version): Correct doc.
(set_db_version): New function.
(migrate_0_to_1): Enable, and add implementation.
(database_migrators): Enable 0 to 1 migration.
(init_manage): Use set_db_version.
* ChangeLog: Add actual versions at DATABASE_VERSION changes. Replace
indent spaces with tabs.
Modified: trunk/openvas-manager/ChangeLog
===================================================================
--- trunk/openvas-manager/ChangeLog 2009-10-20 20:31:58 UTC (rev 5655)
+++ trunk/openvas-manager/ChangeLog 2009-10-20 20:32:14 UTC (rev 5656)
@@ -1,5 +1,18 @@
2009-10-20 Matthew Mundell <matthew.mundell at intevation.de>
+ Add database migration from version 0 to 1.
+
+ * src/tasks_sql.h (manage_db_version): Correct doc.
+ (set_db_version): New function.
+ (migrate_0_to_1): Enable, and add implementation.
+ (database_migrators): Enable 0 to 1 migration.
+ (init_manage): Use set_db_version.
+
+ * ChangeLog: Add actual versions at DATABASE_VERSION changes. Replace
+ indent spaces with tabs.
+
+2009-10-20 Matthew Mundell <matthew.mundell at intevation.de>
+
* src/tasks_sql.h: Bring docs up to date. Remove docs from DEF_ACCESS
invocations so that they're all the same.
@@ -143,7 +156,7 @@
(process_otp_scanner_input): In SCANNER_PLUGIN_LIST_CATEGORY set the
category number according to the OTP field.
- * src/tasks_sql.h (DATABASE_VERSION): Increment, due to nvts category
+ * src/tasks_sql.h (DATABASE_VERSION): Increment to 2, due to nvts category
column type specification.
(init_manage): Specify type for category column in table nvts.
(make_nvt_from_nvti): Insert category as int.
@@ -370,7 +383,8 @@
2009-09-30 Matthew Mundell <matthew.mundell at intevation.de>
- * src/tasks_sql.h (DATABASE_VERSION): Increase, for row added 2009-08-28.
+ * src/tasks_sql.h (DATABASE_VERSION): Increase to 1, for row added
+ 2009-08-28.
2009-09-28 Matthew Mundell <matthew.mundell at intevation.de>
@@ -1090,7 +1104,7 @@
Add a database version check.
- * src/tasks_sql.h (DATABASE_VERSION): New define.
+ * src/tasks_sql.h (DATABASE_VERSION): New define. Version 0.
(init_manage): Check database version. Ensure version is set.
* src/omp.c (init_omp): Add version return to doc.
@@ -1174,17 +1188,17 @@
2009-08-26 Matthew Mundell <matthew.mundell at intevation.de>
- * src/tasks_sql.h (init_manage): Ensure that the predefined database
+ * src/tasks_sql.h (init_manage): Ensure that the predefined database
entries always exists.
2009-08-26 Matthew Mundell <matthew.mundell at intevation.de>
- * src/tasks_sql.h (scan_start_time, scan_end_time): Return an empty string
+ * src/tasks_sql.h (scan_start_time, scan_end_time): Return an empty string
if the field is NULL, so that the resulting XML entity is empty.
2009-08-26 Matthew Mundell <matthew.mundell at intevation.de>
- * src/omp.c: Always free the returns from scan_start_time and
+ * src/omp.c: Always free the returns from scan_start_time and
scan_end_time.
2009-08-26 Matthew Mundell <matthew.mundell at intevation.de>
Modified: trunk/openvas-manager/src/tasks_sql.h
===================================================================
--- trunk/openvas-manager/src/tasks_sql.h 2009-10-20 20:31:58 UTC (rev 5655)
+++ trunk/openvas-manager/src/tasks_sql.h 2009-10-20 20:32:14 UTC (rev 5656)
@@ -393,9 +393,9 @@
}
/**
- * @brief Return the database version supported by this manager.
+ * @brief Return the database version of the actual database.
*
- * @return Database version supported by this manager if found, else -1.
+ * @return Database version read from database if possible, else -1.
*/
int
manage_db_version ()
@@ -414,6 +414,20 @@
}
/**
+ * @brief Set the database version of the actual database.
+ *
+ * @param version New version number.
+ */
+static void
+set_db_version (int version)
+{
+ assert (version >= DATABASE_VERSION);
+ sql ("INSERT OR REPLACE INTO meta (name, value)"
+ " VALUES ('database_version', '%i');",
+ version);
+}
+
+/**
* @brief A migrator.
*/
typedef struct
@@ -422,7 +436,6 @@
int (*function) (); ///< Function that does the migration. NULL if too hard.
} migrator_t;
-#if 0
/**
* @brief Migrate the database from version 0 to version 1.
*
@@ -432,21 +445,53 @@
migrate_0_to_1 ()
{
/* Ensure that the database is currently version 0. */
+
if (manage_db_version () != 0) return -1;
/* Update the database. */
+ /* In SVN the database version flag changed from 0 to 1 on 2009-09-30,
+ * while the database changed to the version 1 schema on 2009-08-29. This
+ * means the database could be flagged as version 0 while it has a version
+ * 1 schema. In this case the ADD COLUMN below would fail. A work around
+ * would be simply to update the version number in the database by hand. */
+
+ sql ("ALTER TABLE reports ADD COLUMN scan_run_status INTEGER;");
+
+ /* SQLite 3.1.3 and earlier require a VACUUM before they can read
+ * from the new column. However, vacuuming might change the ROWIDs,
+ * which would screw up the data. Debian 5.0 (Lenny) is 3.5.9-6
+ * already. */
+
+ sql ("UPDATE reports SET scan_run_status = '%u';",
+ TASK_STATUS_INTERNAL_ERROR);
+
+ sql ("UPDATE reports SET scan_run_status = '%u'"
+ " WHERE start_time IS NULL OR end_time IS NULL;",
+ TASK_STATUS_STOPPED);
+
+ sql ("UPDATE reports SET scan_run_status = '%u'"
+ " WHERE end_time IS NOT NULL;",
+ TASK_STATUS_DONE);
+
+ /* Set the database version to 1. */
+
+ set_db_version (1);
+
return 0;
}
-#endif
/**
* @brief Array of database version migrators.
*/
static migrator_t database_migrators[]
= {{0, NULL},
+ {1, migrate_0_to_1},
#if 0
- {1, migrate_0_to_1},
+ {2, migrate_1_to_2},
+ {3, migrate_2_to_3},
+ {4, migrate_3_to_4},
+ {5, migrate_4_to_5},
#endif
/* End marker. */
{-1, NULL}};
@@ -989,8 +1034,7 @@
/* Ensure the version is set. */
- sql ("INSERT OR REPLACE INTO meta (name, value)"
- " VALUES ('database_version', '" G_STRINGIFY (DATABASE_VERSION) "');");
+ set_db_version (DATABASE_VERSION);
/* Ensure the special "om" user exists. */
More information about the Openvas-commits
mailing list