Skip to content

Commit 06f5911

Browse files
committed
Update payload codec migration.
1 parent 72e3b9e commit 06f5911

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

main.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,27 @@ func migrateDeviceProfiles() {
548548
panic(err)
549549
}
550550

551+
codecScript := ""
552+
if asDP.PayloadDecoderScript != "" {
553+
codecScript = fmt.Sprintf(`
554+
// v3 to v4 compatibility wrapper
555+
function decodeUplink(input) {
556+
return {
557+
object: Decode(input.fPort, input.bytes, input.variables)
558+
};
559+
}
560+
561+
function encodeDownlink(input) {
562+
return {
563+
data: Encode(input.fPort, input.data, input.variables)
564+
};
565+
}
566+
567+
%s
568+
569+
%s`, asDP.PayloadDecoderScript, asDP.PayloadEncoderScript)
570+
}
571+
551572
_, err = csDB.Exec(`
552573
insert into device_profile (
553574
id,
@@ -560,8 +581,7 @@ func migrateDeviceProfiles() {
560581
reg_params_revision,
561582
adr_algorithm_id,
562583
payload_codec_runtime,
563-
payload_encoder_config,
564-
payload_decoder_config,
584+
payload_codec_script,
565585
uplink_interval,
566586
supports_otaa,
567587
supports_class_b,
@@ -576,7 +596,8 @@ func migrateDeviceProfiles() {
576596
abp_rx2_dr,
577597
abp_rx2_freq,
578598
tags,
579-
device_status_req_interval
599+
device_status_req_interval,
600+
flush_queue_on_activate
580601
) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27)`,
581602
nsDP.ID,
582603
intToUUID(asDP.OrganizationID),
@@ -588,8 +609,7 @@ func migrateDeviceProfiles() {
588609
nsDP.RegParamsRevision,
589610
nsDP.ADRAlgorithmID,
590611
asDP.PayloadCodec,
591-
asDP.PayloadEncoderScript,
592-
asDP.PayloadDecoderScript,
612+
codecScript,
593613
asDP.UplinkInterval/time.Second,
594614
nsDP.SupportsJoin,
595615
nsDP.SupportsClassB,
@@ -604,7 +624,8 @@ func migrateDeviceProfiles() {
604624
nsDP.RXDataRate2,
605625
nsDP.RXFreq2,
606626
hstoreToJSON(asDP.Tags),
607-
0,
627+
1,
628+
true,
608629
)
609630
if err != nil {
610631
panic(err)

0 commit comments

Comments
 (0)