[odb-users] How to retrieve schema name ?
Boris Kolpackov
boris at codesynthesis.com
Thu Mar 19 10:11:18 EDT 2015
Hi David,
Yes, Per got it right, the easiest way to get this information is
to use a view. Section 13.2, "Schema Migration" has the description
of this table:
"... By default, when schema evolution is enabled, ODB maintains this
information in a special table called schema_version that has the
following (or equivalent, depending on the database used) definition:"
CREATE TABLE "schema_version" (
"name" TEXT NOT NULL PRIMARY KEY,
"version" BIGINT NOT NULL,
"migration" BOOLEAN NOT NULL);
"The name column is the schema name as specified with the --schema-name
option. It is empty for the default schema. The version column contains the
current database version. And, finally, the migration flag indicates whether
we are in the process of migrating the database, that is, between the pre and
post-migration stages."
One improvement on Per's suggestion would be to use a table view rather
than a native view. A bit less raw SQL:
#pragma db view table("schema_version")
struct schema_name
{
#pragma db column("name")
std::string name;
};
Boris
More information about the odb-users
mailing list