\fBovsdb\-tool \fR[\fIoptions\fR] \fBconvert\fI db schema
\fR[\fItarget\fR]
.br
+\fBovsdb\-tool \fR[\fIoptions\fR] \fBneeds\-conversion\fI db schema\fR
+.br
\fBovsdb\-tool \fR[\fIoptions\fR] \fBdb\-version\fI db\fR
.br
\fBovsdb\-tool \fR[\fIoptions\fR] \fBschema\-version\fI schema\fR
set to their default values. All of \fIschema\fR's constraints apply
in full.
.
+.IP "\fBneeds\-conversion\fI db schema\fR"
+Reads the schema embedded in \fIdb\fR and the standalone schema in
+\fIschema\fR and compares them. If the schemas are the same, prints
+\fBno\fR on stdout; if they differ, print \fByes\fR.
+.
.IP "\fBdb\-version\fI db\fR"
.IQ "\fBschema\-version\fI schema\fR"
Prints the version number in the schema embedded within the database
ovsdb_schema_destroy(new_schema);
}
+static void
+do_needs_conversion(int argc OVS_UNUSED, char *argv[])
+{
+ const char *db_file_name = argv[1];
+ const char *schema_file_name = argv[2];
+ struct ovsdb_schema *schema1, *schema2;
+
+ check_ovsdb_error(ovsdb_file_read_schema(db_file_name, &schema1));
+ check_ovsdb_error(ovsdb_schema_from_file(schema_file_name, &schema2));
+ puts(ovsdb_schema_equal(schema1, schema2) ? "no" : "yes");
+ ovsdb_schema_destroy(schema1);
+ ovsdb_schema_destroy(schema2);
+}
+
static void
do_db_version(int argc OVS_UNUSED, char *argv[])
{
{ "create", 2, 2, do_create },
{ "compact", 1, 2, do_compact },
{ "convert", 2, 3, do_convert },
+ { "needs-conversion", 2, 2, do_needs_conversion },
{ "db-version", 1, 1, do_db_version },
{ "db-cksum", 1, 1, do_db_cksum },
{ "schema-version", 1, 1, do_schema_version },
return json;
}
+
+/* Returns true if 'a' and 'b' specify equivalent schemas, false if they
+ * differ. */
+bool
+ovsdb_schema_equal(const struct ovsdb_schema *a,
+ const struct ovsdb_schema *b)
+{
+ /* This implementation is simple, stupid, and slow, but I doubt that it
+ * will ever require much maintenance. */
+ struct json *ja = ovsdb_schema_to_json(a);
+ struct json *jb = ovsdb_schema_to_json(b);
+ bool equals = json_equal(ja, jb);
+ json_destroy(ja);
+ json_destroy(jb);
+
+ return equals;
+}
\f
static void
ovsdb_set_ref_table(const struct shash *tables,
struct ovsdb_schema **)
WARN_UNUSED_RESULT;
struct json *ovsdb_schema_to_json(const struct ovsdb_schema *);
+
+bool ovsdb_schema_equal(const struct ovsdb_schema *,
+ const struct ovsdb_schema *);
\f
/* Database. */
struct ovsdb {
AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9
])
AT_CLEANUP
+
+AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)])
+AT_KEYWORDS([ovsdb file positive])
+AT_DATA([schema], [ORDINAL_SCHEMA
+])
+touch .db.~lock~
+AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
+AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no
+])
+AT_CLEANUP
+
+AT_SETUP([ovsdb-tool needs-conversion (conversion needed)])
+AT_KEYWORDS([ovsdb file positive])
+AT_DATA([schema], [ORDINAL_SCHEMA
+])
+touch .db.~lock~
+AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore])
+sed 's/5\.1\.3/5.1.4/' < schema > schema2
+AT_CHECK([diff schema schema2], [1], [ignore])
+AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes
+])
+AT_CLEANUP