@@ -97,6 +97,27 @@ local function get_server_alias(instance_uri)
97
97
return servers [1 ].alias
98
98
end
99
99
100
+ local function create_space_for_storing_applied_migrations ()
101
+ box .schema .sequence .create (' _migrations_id_seq' , { if_not_exists = true })
102
+ box .schema .create_space (' _migrations' , {
103
+ format = {
104
+ {' id' , type = ' unsigned' , is_nullable = false },
105
+ {' name' , type = ' string' , is_nullable = false },
106
+ },
107
+ if_not_exists = true ,
108
+ })
109
+ box .space ._migrations :create_index (' primary' , {
110
+ sequence = ' _migrations_id_seq' ,
111
+ if_not_exists = true ,
112
+ })
113
+ -- Workaround for https://github.com/tarantool/ddl/issues/122
114
+ -- If index is created by ddl, sequence is not set. Check and update is required.
115
+ if box .space ._migrations .index .primary ~= nil
116
+ and box .space ._migrations .index .primary .sequence_id == nil then
117
+ box .space ._migrations .index .primary :alter ({sequence = ' _migrations_id_seq' })
118
+ end
119
+ end
120
+
100
121
--- Run migrations on all nodes in the cluster
101
122
-- Throws an exception in case of any problems
102
123
-- @function up
@@ -290,29 +311,7 @@ local function move_migrations_state(current_server_only)
290
311
return migrations_by_alias
291
312
end
292
313
293
- local function init (opts )
294
- -- Create space for storing applied migrations.
295
- if opts .is_master then
296
- box .schema .sequence .create (' _migrations_id_seq' , { if_not_exists = true })
297
- box .schema .create_space (' _migrations' , {
298
- format = {
299
- {' id' , type = ' unsigned' , is_nullable = false },
300
- {' name' , type = ' string' , is_nullable = false },
301
- },
302
- if_not_exists = true ,
303
- })
304
- box .space ._migrations :create_index (' primary' , {
305
- sequence = ' _migrations_id_seq' ,
306
- if_not_exists = true ,
307
- })
308
- -- Workaround for https://github.com/tarantool/ddl/issues/122
309
- -- If index is created by ddl, sequence is not set. Check and update is required.
310
- if box .space ._migrations .index .primary ~= nil
311
- and box .space ._migrations .index .primary .sequence_id == nil then
312
- box .space ._migrations .index .primary :alter ({sequence = ' _migrations_id_seq' })
313
- end
314
- end
315
-
314
+ local function init ()
316
315
local httpd = cartridge .service_get (' httpd' )
317
316
if not httpd then return true end
318
317
@@ -381,10 +380,19 @@ local function validate_config(conf_new)
381
380
return true
382
381
end
383
382
383
+ local function apply_config ()
384
+ if not box .info ().ro then
385
+ create_space_for_storing_applied_migrations ()
386
+ end
387
+
388
+ return true
389
+ end
390
+
384
391
return {
385
392
init = init ,
386
393
387
394
validate_config = validate_config ,
395
+ apply_config = apply_config ,
388
396
389
397
permanent = true ,
390
398
0 commit comments