-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
The ddl module is responsible for applying the schema on the cluster.
This module does not allow to modify the schema after applying it.
In Tarantool, there are two types of schema migration that do not require data migration:
- adding a field to the end of a space;
- creating an index.
To make it easier to write migrations, we should add the ability to
expand the schema by adding nullable field to the end of the space.
Example of migrations:
Migration 1:
return {
up = function()
local ddl = require('ddl')
local schema = {
spaces = {
keyval = {
engine = 'memtx',
is_local = false,
temporary = false,
format = {
{ name = 'bucket_id', type = 'unsigned', is_nullable = false },
{ name = 'key', type = 'string', is_nullable = false },
{ name = 'value', type = 'string', is_nullable = false }
},
indexes = {{
name = 'pk',
type = 'TREE',
unique = true,
parts = {
{ path = 'key', type = 'string', is_nullable = false }
}
}, {
name = 'bucket_id',
type = 'TREE',
unique = false,
parts = {
{ path = 'bucket_id', type = 'unsigned', is_nullable = false }
}
}},
sharding_key = { 'key' }
}
}
}
assert(ddl.check_schema(schema))
ddl.set_schema(schema)
end
}Migration 2:
return {
up = function()
local ddl = require('ddl')
local schema = {
spaces = {
keyval = {
engine = 'memtx',
is_local = false,
temporary = false,
format = {
{ name = 'bucket_id', type = 'unsigned', is_nullable = false },
{ name = 'key', type = 'string', is_nullable = false },
{ name = 'value', type = 'string', is_nullable = false },
{ name = 'state', type = 'map', is_nullable = true }
},
indexes = {{
name = 'pk',
type = 'TREE',
unique = true,
parts = {
{ path = 'key', type = 'string', is_nullable = false }
}
}, {
name = 'bucket_id',
type = 'TREE',
unique = false,
parts = {
{ path = 'bucket_id', type = 'unsigned', is_nullable = false }
}
}},
sharding_key = { 'key' }
}
}
}
assert(ddl.check_schema(schema))
ddl.set_schema(schema)
end
}