add database

This commit is contained in:
安礼成 2023-02-16 14:45:32 +08:00
parent 4402b4fa7c
commit b2d56f628e
2 changed files with 54 additions and 36 deletions

View File

@ -48,15 +48,6 @@
status
}).
%%
-record(host_metrics, {
cpus = [],
cpu_temperature = 0,
memory = #memory_metric{},
disk = #disk_metric{},
interfaces = []
}).
%%
-record(host, {
%% ID
@ -67,15 +58,28 @@
model :: binary(),
%%
cell_id :: integer(),
%%
terminal_num = 0 :: integer(),
%%
metrics = #host_metrics{},
%%
activated_ts = 0 :: integer(),
%% 线
update_ts = 0 :: integer(),
status = 0 :: integer()
%%
status = ?HOST_STATUS_INACTIVE :: integer()
}).
%%
-record(host_metric, {
%% ID
id :: binary(),
%% cpu相关
cpus = [],
%% cpu温度
cpu_temperature = 0,
%%
memory = #memory_metric{},
%%
disk = #disk_metric{},
%%
interfaces = []
}).
%%
@ -101,23 +105,21 @@
}).
%%
-record(micro_service, {
%% ID
-record(microservice, {
%% ID, UUID生成
id :: binary(),
%%
host_id :: binary(),
%%
name :: binary(),
%% ID
product_id :: integer(),
%% ID
vendor_id :: integer(),
%%
model :: binary(),
%% ID
cell_id :: integer(),
%%
status = 0 :: integer(),
%% 线
update_ts = 0 :: integer()
%%
category :: binary(),
%%
apply_object :: binary(),
%%
version :: binary(),
%%
execute_count = 0,
%%
deploy_ts = 0 :: integer()
}).

View File

@ -22,8 +22,9 @@ init_database() ->
%% schema
ok = mnesia:create_schema([node()]),
ok = mnesia:start(),
%%
%%
%%
mnesia:create_table(host, [
{attributes, record_info(fields, host)},
{record_name, host},
@ -31,9 +32,26 @@ init_database() ->
{type, set}
]),
%%
mnesia:create_table(host_metric, [
{attributes, record_info(fields, host_metric)},
{record_name, host_metric},
{disc_copies, [node()]},
{type, set}
]),
%%
mnesia:create_table(terminal, [
{attributes, record_info(fields, terminal)},
{record_name, host},
{record_name, terminal},
{disc_copies, [node()]},
{type, set}
]),
%%
mnesia:create_table(microservice, [
{attributes, record_info(fields, microservice)},
{record_name, microservice},
{disc_copies, [node()]},
{type, set}
]),
@ -56,10 +74,8 @@ copy_database(MasterNode) when is_atom(MasterNode) ->
mnesia:change_table_copy_type(schema, node(), disc_copies),
%%
mnesia:add_table_copy(booking, node(), ram_copies),
mnesia:add_table_copy(calendar, node(), ram_copies),
mnesia:add_table_copy(app, node(), ram_copies),
mnesia:add_table_copy(fake_app, node(), ram_copies),
mnesia:add_table_copy(app_extra, node(), ram_copies),
mnesia:add_table_copy(app_calendar, node(), ram_copies),
mnesia:add_table_copy(host, node(), ram_copies),
mnesia:add_table_copy(host_metric, node(), ram_copies),
mnesia:add_table_copy(terminal, node(), ram_copies),
mnesia:add_table_copy(microservice, node(), ram_copies),
ok.