blob: 9c036c71ce1748e72dba255cfbee8dbba6c48d99 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package io.v.syncbase.v23.services.syncbase.nosql;
/**
* A database schema.
* <p>
* Each database has a schema associated with it which defines the current version of the
* database. When a new version of an app wishes to change its data in a way that it is not
* compatible with the old app's data, this app must change the schema version and provide relevant
* upgrade logic in the specified {@link SchemaUpgrader}. The conflict resolution rules are also
* associated with the schema version. Hence if the conflict resolution rules change then the schema
* version also must be bumped.
*/
public class Schema {
private final SchemaMetadata metadata;
private final SchemaUpgrader upgrader;
/**
* Creates a new database schema with the specified metadata and schema upgrader.
* <p>
* Note: {@link SchemaUpgrader} is purely local and is not persisted.
*/
public Schema(SchemaMetadata metadata, SchemaUpgrader upgrader) {
this.metadata = metadata;
this.upgrader = upgrader;
}
/**
* Returns the metadata related to this schema.
*/
public SchemaMetadata metadata() { return this.metadata; }
/**
* Returns the upgrade logic used for upgrading the schema when an app's schema version differs
* from the database's schema version.
*/
public SchemaUpgrader upgrader() { return this.upgrader; }
}