Skip to content

Migrations and encryption

Local Barq files can use schema versions, migrations, compaction, and encryption keys.

When changing a local schema, bump schemaVersion and provide onMigration if old data needs to be moved.

const barq = await Barq.open({
schema: [Task],
schemaVersion: 2,
onMigration(oldBarq, newBarq) {
// Move old data into the new schema here.
},
});

onMigration is not used together with sync.

Pass a 64-byte key to encrypt a local database file.

const key = crypto.getRandomValues(new Uint8Array(64));
const barq = await Barq.open({
path: 'secure.barq',
schema: [Task],
encryptionKey: key,
});

Store encryption keys outside the database file.

The sync server can derive per-tenant database keys from a master secret when run with --tenant-encryption-master-key.