Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding schema by adding nullable field #104

Open
AnaNek opened this issue Jan 17, 2023 · 0 comments
Open

Expanding schema by adding nullable field #104

AnaNek opened this issue Jan 17, 2023 · 0 comments

Comments

@AnaNek
Copy link
Contributor

AnaNek commented Jan 17, 2023

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants