|
| 1 | +#!/usr/bin/env tarantool |
| 2 | + |
| 3 | +require('strict').on() |
| 4 | +_G.is_initialized = function() return false end |
| 5 | + |
| 6 | +local log = require('log') |
| 7 | +local errors = require('errors') |
| 8 | +local cartridge = require('cartridge') |
| 9 | + |
| 10 | +package.preload['customers-storage'] = function() |
| 11 | + local engine = os.getenv('ENGINE') or 'memtx' |
| 12 | + return { |
| 13 | + role_name = 'customers-storage', |
| 14 | + init = function() |
| 15 | + local customers_space = box.schema.space.create('customers', { |
| 16 | + format = { |
| 17 | + {name = 'id', type = 'unsigned'}, |
| 18 | + {name = 'bucket_id', type = 'unsigned'}, |
| 19 | + {name = 'name', type = 'string'}, |
| 20 | + {name = 'last_name', type = 'string'}, |
| 21 | + {name = 'age', type = 'number'}, |
| 22 | + {name = 'city', type = 'string'}, |
| 23 | + }, |
| 24 | + if_not_exists = true, |
| 25 | + engine = engine, |
| 26 | + id = 542, |
| 27 | + }) |
| 28 | + -- primary index |
| 29 | + customers_space:create_index('id_index', { |
| 30 | + parts = { {field = 'id'} }, |
| 31 | + if_not_exists = true, |
| 32 | + }) |
| 33 | + customers_space:create_index('bucket_id', { |
| 34 | + parts = { {field = 'bucket_id'} }, |
| 35 | + unique = false, |
| 36 | + if_not_exists = true, |
| 37 | + }) |
| 38 | + customers_space:create_index('age_index', { |
| 39 | + parts = { {field = 'age'} }, |
| 40 | + unique = false, |
| 41 | + if_not_exists = true, |
| 42 | + }) |
| 43 | + end, |
| 44 | + } |
| 45 | +end |
| 46 | + |
| 47 | +local ok, err = errors.pcall('CartridgeCfgError', cartridge.cfg, { |
| 48 | + advertise_uri = 'localhost:3301', |
| 49 | + http_port = 8081, |
| 50 | + bucket_count = 3000, |
| 51 | + roles = { |
| 52 | + 'cartridge.roles.crud-router', |
| 53 | + 'cartridge.roles.crud-storage', |
| 54 | + 'customers-storage', |
| 55 | + }, |
| 56 | + roles_reload_allowed = true, |
| 57 | +}) |
| 58 | + |
| 59 | +if not ok then |
| 60 | + log.error('%s', err) |
| 61 | + os.exit(1) |
| 62 | +end |
| 63 | + |
| 64 | +_G.is_initialized = cartridge.is_healthy |
0 commit comments