mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-03-15 00:36:33 +00:00
Add app-layer params field to device-profile schema.
This commit is contained in:
parent
24b5202f49
commit
12c0334391
@ -86,5 +86,5 @@ alter table device_profile
|
||||
drop column abp_params,
|
||||
drop column class_b_params,
|
||||
drop column class_c_params,
|
||||
drop column relay_params;
|
||||
|
||||
drop column relay_params,
|
||||
drop column app_layer_params;
|
||||
|
@ -2,7 +2,11 @@ alter table device_profile
|
||||
add column abp_params jsonb null,
|
||||
add column class_b_params jsonb null,
|
||||
add column class_c_params jsonb null,
|
||||
add column relay_params jsonb null;
|
||||
add column relay_params jsonb null,
|
||||
add column app_layer_params jsonb not null default '{}';
|
||||
|
||||
alter table device_profile
|
||||
alter column app_layer_params drop default;
|
||||
|
||||
update device_profile
|
||||
set abp_params = json_build_object(
|
||||
@ -46,7 +50,7 @@ update device_profile
|
||||
'relay_notify_limit_reload_rate', relay_notify_limit_reload_rate,
|
||||
'relay_global_uplink_limit_reload_rate', relay_global_uplink_limit_reload_rate,
|
||||
'relay_overall_limit_reload_rate', relay_overall_limit_reload_rate,
|
||||
'relay_notify_limit_bucket_size', relay_join_req_limit_bucket_size,
|
||||
'relay_join_req_limit_bucket_size', relay_join_req_limit_bucket_size,
|
||||
'relay_notify_limit_bucket_size', relay_notify_limit_bucket_size,
|
||||
'relay_global_uplink_limit_bucket_size', relay_global_uplink_limit_bucket_size,
|
||||
'relay_overall_limit_bucket_size', relay_overall_limit_bucket_size)
|
||||
|
@ -85,4 +85,5 @@ alter table device_profile drop column abp_params;
|
||||
alter table device_profile drop column class_b_params;
|
||||
alter table device_profile drop column class_c_params;
|
||||
alter table device_profile drop column relay_params;
|
||||
alter table device_profile drop column app_layer_params;
|
||||
|
||||
|
@ -2,6 +2,7 @@ alter table device_profile add column abp_params text null;
|
||||
alter table device_profile add column class_b_params text null;
|
||||
alter table device_profile add column class_c_params text null;
|
||||
alter table device_profile add column relay_params text null;
|
||||
alter table device_profile add column app_layer_params text not null default '{}';
|
||||
|
||||
update device_profile
|
||||
set abp_params = json_object(
|
||||
@ -44,7 +45,7 @@ update device_profile
|
||||
'relay_notify_limit_reload_rate', relay_notify_limit_reload_rate,
|
||||
'relay_global_uplink_limit_reload_rate', relay_global_uplink_limit_reload_rate,
|
||||
'relay_overall_limit_reload_rate', relay_overall_limit_reload_rate,
|
||||
'relay_notify_limit_bucket_size', relay_join_req_limit_bucket_size,
|
||||
'relay_join_req_limit_bucket_size', relay_join_req_limit_bucket_size,
|
||||
'relay_notify_limit_bucket_size', relay_notify_limit_bucket_size,
|
||||
'relay_global_uplink_limit_bucket_size', relay_global_uplink_limit_bucket_size,
|
||||
'relay_overall_limit_bucket_size', relay_overall_limit_bucket_size)
|
||||
|
@ -47,6 +47,7 @@ pub struct DeviceProfile {
|
||||
pub class_b_params: Option<fields::ClassBParams>,
|
||||
pub class_c_params: Option<fields::ClassCParams>,
|
||||
pub relay_params: Option<fields::RelayParams>,
|
||||
pub app_layer_params: fields::AppLayerParams,
|
||||
}
|
||||
|
||||
impl DeviceProfile {
|
||||
@ -96,6 +97,7 @@ impl Default for DeviceProfile {
|
||||
class_b_params: None,
|
||||
class_c_params: None,
|
||||
relay_params: None,
|
||||
app_layer_params: fields::AppLayerParams::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,6 +210,7 @@ pub async fn update(dp: DeviceProfile) -> Result<DeviceProfile, Error> {
|
||||
device_profile::class_b_params.eq(&dp.class_b_params),
|
||||
device_profile::class_c_params.eq(&dp.class_c_params),
|
||||
device_profile::relay_params.eq(&dp.relay_params),
|
||||
device_profile::app_layer_params.eq(&dp.app_layer_params),
|
||||
))
|
||||
.get_result(&mut get_async_db_conn().await?)
|
||||
.await
|
||||
|
@ -234,3 +234,68 @@ mod ed_activation_mode {
|
||||
Ok(v)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Default, Debug, Clone, PartialEq, Eq, Deserialize, Serialize, AsExpression, FromSqlRow,
|
||||
)]
|
||||
#[cfg_attr(feature = "postgres", diesel(sql_type = Jsonb))]
|
||||
#[cfg_attr(feature = "sqlite", diesel(sql_type = Text))]
|
||||
pub struct AppLayerParams {
|
||||
pub ts003_version: Option<Ts003Version>,
|
||||
pub ts004_version: Option<Ts004Version>,
|
||||
pub ts005_version: Option<Ts005Version>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "postgres")]
|
||||
impl deserialize::FromSql<Jsonb, Pg> for AppLayerParams {
|
||||
fn from_sql(value: <Pg as Backend>::RawValue<'_>) -> deserialize::Result<Self> {
|
||||
let value = <serde_json::Value as deserialize::FromSql<Jsonb, Pg>>::from_sql(value)?;
|
||||
Ok(serde_json::from_value(value)?)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "postgres")]
|
||||
impl serialize::ToSql<Jsonb, Pg> for AppLayerParams {
|
||||
fn to_sql<'b>(&'b self, out: &mut serialize::Output<'b, '_, Pg>) -> serialize::Result {
|
||||
let value = serde_json::to_value(&self)?;
|
||||
<serde_json::Value as serialize::ToSql<Jsonb, Pg>>::to_sql(&value, &mut out.reborrow())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
impl deserialize::FromSql<Text, Sqlite> for AppLayerParams
|
||||
where
|
||||
*const str: deserialize::FromSql<Text, Sqlite>,
|
||||
{
|
||||
fn from_sql(value: <Sqlite as Backend>::RawValue<'_>) -> deserialize::Result<Self> {
|
||||
let s =
|
||||
<*const str as deserialize::FromSql<diesel::sql_types::Text, Sqlite>>::from_sql(value)?;
|
||||
Ok(serde_json::from_str(unsafe { &*s })?)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
impl serialize::ToSql<Text, Sqlite> for AppLayerParams {
|
||||
fn to_sql<'b>(&'b self, out: &mut serialize::Output<'b, '_, Sqlite>) -> serialize::Result {
|
||||
out.set_value(serde_json::to_string(&self)?);
|
||||
Ok(serialize::IsNull::No)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum Ts003Version {
|
||||
#[default]
|
||||
V100,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum Ts004Version {
|
||||
#[default]
|
||||
V100,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum Ts005Version {
|
||||
#[default]
|
||||
V100,
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ mod uuid;
|
||||
|
||||
pub use big_decimal::BigDecimal;
|
||||
pub use dev_nonces::DevNonces;
|
||||
pub use device_profile::{AbpParams, ClassBParams, ClassCParams, RelayParams};
|
||||
pub use device_profile::{AbpParams, AppLayerParams, ClassBParams, ClassCParams, RelayParams};
|
||||
pub use device_session::DeviceSession;
|
||||
pub use key_value::KeyValue;
|
||||
pub use measurements::*;
|
||||
|
@ -117,6 +117,7 @@ diesel::table! {
|
||||
class_b_params -> Nullable<Jsonb>,
|
||||
class_c_params -> Nullable<Jsonb>,
|
||||
relay_params -> Nullable<Jsonb>,
|
||||
app_layer_params -> Jsonb,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,7 @@ diesel::table! {
|
||||
class_b_params -> Nullable<Text>,
|
||||
class_c_params -> Nullable<Text>,
|
||||
relay_params -> Nullable<Text>,
|
||||
app_layer_params -> Text,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user