Fluid Schema Evolution

Configuration

Getting Started

> fluid
Usage: fluid <command>
Available commands: check Checks generate has been called following schema change
generate Generates template migration and test scripts
test Runs the migration test scripts
revert Rolls back the changes made by the last generate
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"name",
"location"
],
"properties": {
"name": {
"type": "string"
},
"location": {
"type": "string"
},
"hobby": {
"type": "string"
},
}
}
> fluid check
Failure: Schema changed, generate migration scripts
> fluid generate
First schema version, no migration required
> fluid check
Version: 1
/.fluid
/v1
meta.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "The Root Schema",
"required": [
"name",
"city",
"hobbies"
],
"properties": {
"name": {
"type": "string"
},
"city": {
"type": "string"
},
"hobbies": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
> fluid generate
Generated version 2, complete migration and test scripts
/.fluid
/v1
meta.json
/v2
meta.json
migrate.js
test.js
function testMigration() {
testDowngradeUser();
}
function testDowngradeUser() { v2 = {
"name": "name0",
"city": "city0",
"hobbies": [ "hobbies0" ]
}
v1 = {
"name": "name0",
"location": "location0",
"hobby": "hobby0"
}
assertEquals(downgradeUser(v2), v1)
}
function testMigration() {
testUserModel();
}
function testUserMode() { v2 = {
"name": "name0",
"city": "city0",
"hobbies": [ "hobbies0", "hobbies1" ]
}
v1 = {
"name": "name0",
"location": "city0",
"hobby": "hobbies0"
}
assertEquals(downgradeUser(v2), v1)
}
> fluid test
Migration failed:
: # failure messages omitted
function downgradeUser(v2) = {
// Unused v2 properties: city, hobbies
v1 = {
"name": v2.name,
"location": v2.___,
"hobby": v2.___
}
return v1;
}
function downgradeUser(v2) {
v1 = {
name: v2.name,
location: v2.city
}
if (v2.hobbies.length > 0) v1.hobby = v2.hobbies[0];
return v1;
}
> fluid test
OK
> fluid check
Version: 2

Wrap Up

--

--

London based developer of software and ideas. To get in contact www.linkedin.com/in/simon-maxen.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store