box.ctl.on_schema_init()
-
box.ctl.
on_schema_init
(trigger-function[, old-trigger-function])¶ Create a “schema_init trigger”. The
trigger-function
will be executed when box.cfg{} happens for the first time. That is, theschema_init
trigger is called before the server’s configuration and recovery begins, and thereforebox.ctl.on_schema_init
must be called beforebox.cfg
is called.Parameters: - trigger-function (
function
) – function which will become the trigger function - old-trigger-function (
function
) – existing trigger function which will be replaced by trigger-function
Return: nil or function pointer
If the parameters are (nil, old-trigger-function), then the old trigger is deleted.
A common use is: make a
schema_init
trigger function which creates abefore_replace
trigger function on a system space. Thus, since system spaces are created when the server starts, thebefore_replace
triggers will be activated for each tuple in each system space. For example, such a trigger could change the storage engine of a given space, or make a given space replica-local while a replica is being bootstrapped. Making such a change afterbox.cfg
is not reliable because other connections might use the database before the change is made.Details about trigger characteristics are in the triggers section.
Example:
Suppose that, before the server is fully up and ready for connections, you want to make sure that the engine of space
space_name
is vinyl. So you want to make a trigger that will be activated when a tuple is inserted in the_space
system space. In this case you could end up with a master that has space-name withengine='memtx'
and a replica that has space_name withengine='vinyl'
, with the same contents.function function_for_before_replace(old, new) if old == nil and new ~= nil and new[3] == 'space_name' and new[4] ~= 'vinyl' then return new:update{{'=', 4, 'vinyl'}} end end box.ctl.on_schema_init(function() box.space._space:before_replace(function_for_before_replace) end) box.cfg{replication='master_uri', ...}
- trigger-function (