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 status
}). }).
%%
-record(host_metrics, {
cpus = [],
cpu_temperature = 0,
memory = #memory_metric{},
disk = #disk_metric{},
interfaces = []
}).
%% %%
-record(host, { -record(host, {
%% ID %% ID
@ -67,15 +58,28 @@
model :: binary(), model :: binary(),
%% %%
cell_id :: integer(), cell_id :: integer(),
%%
terminal_num = 0 :: integer(),
%%
metrics = #host_metrics{},
%% %%
activated_ts = 0 :: integer(), activated_ts = 0 :: integer(),
%% 线 %% 线
update_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, { -record(microservice, {
%% ID %% ID, UUID生成
id :: binary(), id :: binary(),
%% %%
host_id :: binary(), host_id :: binary(),
%% %%
name :: binary(), name :: binary(),
%% ID %%
product_id :: integer(), category :: binary(),
%% ID %%
vendor_id :: integer(), apply_object :: binary(),
%% %%
model :: binary(), version :: binary(),
%% ID %%
cell_id :: integer(), execute_count = 0,
%% %%
status = 0 :: integer(), deploy_ts = 0 :: integer()
%% 线
update_ts = 0 :: integer()
}). }).

View File

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