Skip to content

Commit

Permalink
Add new column Guid to AstarteFailedMessageEntry
Browse files Browse the repository at this point in the history
Add new column Guid. Column Guid is used for
storing message IDs. Message ID is the unique
identification for every successful send message
to the MQTT broker.

Signed-off-by: Osman Hadzic <osman.hadzic@secomind.com>
  • Loading branch information
osmanhadzic committed Apr 18, 2024
1 parent 50ce0b6 commit d0b51c4
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 2 deletions.
15 changes: 13 additions & 2 deletions AstarteDeviceSDKCSharp/Data/AstarteFailedMessageEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace AstarteDeviceSDKCSharp.Data
{
[Index(nameof(Guid), Name = "Index_Guid")]
public class AstarteFailedMessageEntry : IAstarteFailedMessage
{
[Key]
Expand All @@ -38,19 +40,24 @@ public class AstarteFailedMessageEntry : IAstarteFailedMessage
[Column("absolute_expiry")]
[Required]
public long AbsoluteExpiry { get; set; }
[Required]
[Column("guid")]
public Guid Guid { get; set; }


public AstarteFailedMessageEntry(int qos, byte[] payload, string topic)
public AstarteFailedMessageEntry(int qos, byte[] payload, string topic, Guid guid)
{
Guid = guid;
Qos = qos;
Payload = payload;
Topic = topic;
AbsoluteExpiry = 0;
}

public AstarteFailedMessageEntry(int qos, byte[] payload, string topic,
public AstarteFailedMessageEntry(int qos, byte[] payload, string topic, Guid guid,
int relativeExpiry)
{
Guid = guid;
Qos = qos;
Payload = payload;
Topic = topic;
Expand All @@ -77,5 +84,9 @@ public long GetExpiry()
return AbsoluteExpiry;
}

public Guid GetGuid()
{
return Guid;
}
}
}
2 changes: 2 additions & 0 deletions AstarteDeviceSDKCSharp/Data/IAstarteFailedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ public interface IAstarteFailedMessage
int GetQos();

long GetExpiry();

Guid GetGuid();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is part of Astarte.
#
# Copyright 2024 SECO Mind Srl
#
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This file is part of Astarte.
//
// Copyright 2024 SECO Mind Srl
//
// SPDX-License-Identifier: Apache-2.0
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AstarteDeviceSDKCSharp.Migrations
{
public partial class AddMessageGuidColumn : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "guid",
table: "AstarteFailedMessages",
type: "TEXT",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

migrationBuilder.CreateIndex(
name: "Index_Guid",
table: "AstarteFailedMessages",
column: "guid");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "Index_Guid",
table: "AstarteFailedMessages");

migrationBuilder.DropColumn(
name: "guid",
table: "AstarteFailedMessages");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("INTEGER")
.HasColumnName("absolute_expiry");

b.Property<Guid>("Guid")
.HasColumnType("TEXT")
.HasColumnName("guid");

b.Property<byte[]>("Payload")
.IsRequired()
.HasColumnType("BLOB");
Expand All @@ -40,6 +44,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.HasIndex(new[] { "Guid" }, "Index_Guid");

b.ToTable("AstarteFailedMessages");
});

Expand Down

0 comments on commit d0b51c4

Please sign in to comment.