[odb-users] schema validation

Alexander A. Prokhorov alexander.prokhorov at datadvance.net
Fri Oct 26 08:37:21 EDT 2012


Thanks!

On 26.10.2012 17:02, Boris Kolpackov wrote:
> Hi Alexander,
>
> Alexander A. Prokhorov <alexander.prokhorov at datadvance.net> writes:
>
>> Application is quite agile, schema often experiences minor changes, and
>> it's very desirable to perform a meaningful schema check every time I
>> open a new SQLite file.
>>
>> Otherwise, as I understand, user may encounter some database-related
>> exceptions/errors in runtime, which is highly undesirable.
>>
>> So, the question is, is there any recommended way to match current
>> schema (in odb::schema_catalog, I suppose) to be subset of schema in
>> some database?
> There is no automatic database schema versioning in ODB yet (we may
> add something like this in the future as part of the schema evolution
> work).
>
> In the meantime, it should be quite easy to implement this by storing
> the version of the schema in the database itself (this also seems to
> be the recommended way to do schema versioning). You could even create
> a small persistent class to assist with this, something along these
> lines:
>
> #pragma db object
> struct schema_version
> {
>    schema_version () {}
>    schema_version (unsigned short mj, unsigned short mn)
>      : id (1), major (mj), minor (mn)
>
>    #pragma db id
>    unsigned short id;
>
>    unsigned short major;
>    unsigned short minor
> };
>
> Then when creating a new database, you would also store the version:
>
> schema_version sv (2, 3);
> db.persis (sv);
>
> And when opening an existing database, you would check the version:
>
> schema_version sv;
> db.load (1, sv);
>
> if (sv.major < 2)
> {
>    // Incompatible schema version.
> }
>
> Boris


-- 
Alexander A. Prokhorov
Head of Software Development
DATADVANCE
Mob. +7 903 6249039
alexander.prokhorov at datadvance.net
prokher at datadvance.net

This message may contain confidential information
constituting a trade secret of DATADVANCE. Any distribution,
use or copying of the information contained in this
message is ineligible except under the internal
regulations of DATADVANCE and may entail liability in
accordance with the current legislation of the Russian
Federation. If you have received this message by mistake
please immediately inform me of it. Thank you!



More information about the odb-users mailing list