Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transferhistory updates #888

Merged
merged 63 commits into from
Feb 5, 2025
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d7ef0f2
new DB fields and shorter fields
Seifert69 Jan 8, 2025
41f3c96
added the fields Todd wanted
Seifert69 Jan 8, 2025
27a3bf6
Adding a public interface to TransferHistory
Seifert69 Jan 9, 2025
fe3a883
making public interface for the local tag index
Seifert69 Jan 9, 2025
7d1516c
Merge branch 'main' into newfields
Jan 9, 2025
eaf256f
starting process of saving data to history table instead of file
Jan 13, 2025
4e96a71
working on storgage
Jan 13, 2025
239ebe2
merged main
Jan 13, 2025
eb979bc
working on migration script
Jan 15, 2025
92eb933
renaming
Jan 16, 2025
314314f
working on summary
Jan 16, 2025
5f5c8ae
saving progress
Jan 17, 2025
7bde3f2
wip
Jan 17, 2025
84ebfd5
removed incorrect feature
Jan 18, 2025
1e2ae92
working on summary and tests
Jan 20, 2025
015e17f
wip
Jan 20, 2025
00a43d5
tests - wip
Jan 20, 2025
7337436
wip - test
Jan 20, 2025
c8433ec
tests wip
Jan 20, 2025
65d53dc
Merge branch 'main' into transferhistory-updates
Jan 20, 2025
d872ad8
changed for swagger
Jan 20, 2025
e01f190
upgraded from sql-lite generator and fixed exception
Jan 21, 2025
1614e92
wip
Jan 22, 2025
8985f09
tests -wip
Jan 23, 2025
752b5d6
tests wip
Jan 23, 2025
bcdbe49
Merge branch 'main' into transferhistory-updates
Jan 23, 2025
ec6620f
merged in main
Jan 23, 2025
82c89e9
Merge branch 'main' into transferhistory-updates
toddmitchell Jan 23, 2025
f7b39f5
working on tests
Jan 23, 2025
219b26f
added delay in test; thx seb for the research
Jan 24, 2025
51f9646
fixed ordering of db table per seb
Jan 24, 2025
af9cbcf
Merge branch 'main' into transferhistory-updates
toddmitchell Jan 24, 2025
f235bc0
Merge branch 'main' into transferhistory-updates
toddmitchell Jan 28, 2025
0db551f
fixed migration issues
Jan 28, 2025
cc06a6c
fixed migration structure issue
Jan 28, 2025
1f5b400
changed to support postress types
Jan 28, 2025
e963bcc
fixed table
Jan 28, 2025
801b345
addressing postgress issues
Jan 29, 2025
64727af
testing for postgress and sql support
Jan 29, 2025
d04a16e
fixed modified time in fileModified event when transfer history is up…
Jan 29, 2025
35e6259
Fix DB null portability
sebbarg Jan 30, 2025
22b3466
Adding UpdateTransferHistoryRecordAsync
Seifert69 Jan 30, 2025
46e33b9
Adding UpdateTransferHistoryRecordAsync
Seifert69 Jan 30, 2025
d62ac07
adding a reference to the CRUD file GetAsync
Seifert69 Jan 30, 2025
30855d0
adding the auto generated files and adjustments to the TransferHistor…
Seifert69 Jan 30, 2025
b318481
CRUD with INSERT et al
Seifert69 Jan 30, 2025
6945f14
updated table strucutre and refactored to kill extra class
Jan 30, 2025
3f36f12
Merge branch 'main' into transferhistory-updates
toddmitchell Jan 30, 2025
8de3366
fixed warning
Jan 30, 2025
cb15e71
fixes
Jan 30, 2025
711ce43
Merge branch 'main' into transferhistory-updates
toddmitchell Jan 31, 2025
94d11fd
Added tests for DriveTransferHistory - especially for the hand coded …
Seifert69 Jan 31, 2025
1e91160
Merge branch 'transferhistory-updates' of github.com:homebase-id/odin…
Seifert69 Jan 31, 2025
62536fe
trying insert for new outbox them with fallback to update
Jan 31, 2025
46e0b2c
Merge branch 'transferhistory-updates' of github.com:homebase-id/odin…
Jan 31, 2025
9dfd77e
added exception
Jan 31, 2025
f231c79
crossing changes
Seifert69 Jan 31, 2025
74580ea
Merge branch 'transferhistory-updates' of github.com:homebase-id/odin…
Seifert69 Jan 31, 2025
066c41a
remove local tag operations to a diff class
Jan 31, 2025
5ed746a
fixed migraiton table
Feb 3, 2025
b3562e6
Merge branch 'main' into transferhistory-updates
toddmitchell Feb 3, 2025
416459c
Merge branch 'main' into transferhistory-updates
toddmitchell Feb 4, 2025
7fcbb29
fixed bug for sending file between two auto-connected identities
Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
new DB fields and shorter fields
Seifert69 committed Jan 8, 2025
commit d7ef0f2e82299a1369ad124bc1b46508b936e48f
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.VisualBasic.FileIO;
using System.Xml;
using Odin.Core.Exceptions;
using Odin.Core.Storage.Database.Identity.Connection;
using Odin.Core.Storage.Database.Identity.Table;
@@ -19,6 +24,19 @@ public class MainIndexMeta(
TableDriveMainIndex driveMainIndex)
{
private readonly DatabaseType _databaseType = scopedConnectionFactory.DatabaseType;
private static readonly string selectOutputFields;

static MainIndexMeta()
{
// Initialize selectOutputFields statically
selectOutputFields = string.Join(",",
TableDriveMainIndex.GetColumnNames()
.Where(name => !name.Equals("identityId", StringComparison.OrdinalIgnoreCase)
&& !name.Equals("driveId", StringComparison.OrdinalIgnoreCase))
.Select(name => name.Equals("fileId", StringComparison.OrdinalIgnoreCase)
? "driveMainIndex.fileId"
: name));
}

public async Task<int> DeleteEntryAsync(Guid driveId, Guid fileId)
{
@@ -308,13 +326,13 @@ private string SharedWhereAnd(List<string> listWhere, IntRange requiredSecurityG
string leftJoin = SharedWhereAnd(listWhereAnd, requiredSecurityGroup, aclAnyOf, filetypesAnyOf, datatypesAnyOf, globalTransitIdAnyOf,
uniqueIdAnyOf, tagsAnyOf, archivalStatusAnyOf, senderidAnyOf, groupIdAnyOf, userdateSpan, tagsAllOf,
fileSystemType, driveId);

if (IsSet(fileStateAnyOf))
{
listWhereAnd.Add($"fileState IN ({IntList(fileStateAnyOf)})");
}

string selectOutputFields = "driveMainIndex.fileId, globalTransitId, fileState, requiredSecurityGroup, fileSystemType, userDate, fileType, dataType, archivalStatus, historyStatus, senderId, groupId, uniqueId, byteCount, hdrEncryptedKeyHeader, hdrVersionTag, hdrAppData, hdrReactionSummary, hdrServerData, hdrTransferHistory, hdrFileMetaData, hdrTmpDriveAlias, hdrTmpDriveType, created, modified";
// string selectOutputFields = "driveMainIndex.fileId, globalTransitId, fileState, requiredSecurityGroup, fileSystemType, userDate, fileType, dataType, archivalStatus, historyStatus, senderId, groupId, uniqueId, byteCount, hdrEncryptedKeyHeader, hdrVersionTag, hdrAppData, hdrLocalVersionTag,hdrLocalAppData,hdrReactionSummary, hdrServerData, hdrTransferHistory, hdrFileMetaData, hdrTmpDriveAlias, hdrTmpDriveType, created, modified";
// string selectOutputFields = "driveMainIndex.fileId, globalTransitId, fileState, requiredSecurityGroup, fileSystemType, userDate, fileType, dataType, archivalStatus, historyStatus, senderId, groupId, uniqueId, byteCount, hdrEncryptedKeyHeader, hdrVersionTag, hdrAppData, hdrReactionSummary, hdrServerData, hdrTransferHistory, hdrFileMetaData, hdrTmpDriveAlias, hdrTmpDriveType, created, modified";
/*if (fileIdSort)
selectOutputFields = "driveMainIndex.fileId";
else
@@ -332,7 +350,6 @@ private string SharedWhereAnd(List<string> listWhere, IntRange requiredSecurityG

// Read +1 more than requested to see if we're at the end of the dataset
string stm = $"SELECT DISTINCT {selectOutputFields} FROM driveMainIndex {leftJoin} WHERE " + string.Join(" AND ", listWhereAnd) + $" ORDER BY {order} LIMIT {noOfItems + 1}";

await using var cn = await scopedConnectionFactory.CreateScopedConnectionAsync();
await using var cmd = cn.CreateCommand();

@@ -578,7 +595,7 @@ private string SharedWhereAnd(List<string> listWhere, IntRange requiredSecurityG
uniqueIdAnyOf, tagsAnyOf, archivalStatusAnyOf, senderidAnyOf, groupIdAnyOf, userdateSpan, tagsAllOf,
fileSystemType, driveId);

string selectOutputFields = "driveMainIndex.fileId, globalTransitId, fileState, requiredSecurityGroup, fileSystemType, userDate, fileType, dataType, archivalStatus, historyStatus, senderId, groupId, uniqueId, byteCount, hdrEncryptedKeyHeader, hdrVersionTag, hdrAppData, hdrReactionSummary, hdrServerData, hdrTransferHistory, hdrFileMetaData, hdrTmpDriveAlias, hdrTmpDriveType, created, modified";
// string selectOutputFields = "driveMainIndex.fileId, globalTransitId, fileState, requiredSecurityGroup, fileSystemType, userDate, fileType, dataType, archivalStatus, historyStatus, senderId, groupId, uniqueId, byteCount, hdrEncryptedKeyHeader, hdrVersionTag, hdrAppData, hdrReactionSummary, hdrServerData, hdrTransferHistory, hdrFileMetaData, hdrTmpDriveAlias, hdrTmpDriveType, created, modified";
string stm = $"SELECT DISTINCT {selectOutputFields} FROM drivemainindex {leftJoin} WHERE " + string.Join(" AND ", listWhereAnd) + $" ORDER BY modified ASC LIMIT {noOfItems + 1}";
// string stm = $"SELECT DISTINCT driveMainIndex.fileid, modified FROM drivemainindex {leftJoin} WHERE " + string.Join(" AND ", listWhereAnd) + $" ORDER BY modified ASC LIMIT {noOfItems + 1}";

Original file line number Diff line number Diff line change
@@ -69,6 +69,16 @@ public byte[] data
_data = value;
}
}
internal byte[] dataNoLengthCheck
{
get {
return _data;
}
set {
if (value?.Length < 0) throw new Exception("Too short");
_data = value;
}
}
} // End of class AppGrantsRecord

public abstract class TableAppGrantsCRUD
@@ -288,7 +298,7 @@ protected virtual async Task<int> GetCountAsync()
}
}

public List<string> GetColumnNames()
public static List<string> GetColumnNames()
{
var sl = new List<string>();
sl.Add("identityId");
@@ -309,16 +319,11 @@ protected AppGrantsRecord ReadRecordFromReaderAll(DbDataReader rdr)
#pragma warning restore CS0168
var guid = new byte[16];
var item = new AppGrantsRecord();
item.identityId = rdr.IsDBNull(0) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);
item.odinHashId = rdr.IsDBNull(1) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[1]);
item.appId = rdr.IsDBNull(2) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[2]);
item.circleId = rdr.IsDBNull(3) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[3]);
item.data = rdr.IsDBNull(4) ?
null : (byte[])(rdr[4]);
item.identityId = rdr.IsDBNull(0) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);
item.odinHashId = rdr.IsDBNull(1) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[1]);
item.appId = rdr.IsDBNull(2) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[2]);
item.circleId = rdr.IsDBNull(3) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[3]);
item.dataNoLengthCheck = rdr.IsDBNull(4) ? null : (byte[])(rdr[4]);
if (item.data?.Length > 65535)
throw new Exception("Too much data in data...");
if (item.data?.Length < 0)
@@ -368,15 +373,9 @@ protected AppGrantsRecord ReadRecordFromReader0(DbDataReader rdr, Guid identityI
var item = new AppGrantsRecord();
item.identityId = identityId;
item.odinHashId = odinHashId;

item.appId = rdr.IsDBNull(0) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);

item.circleId = rdr.IsDBNull(1) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[1]);

item.data = rdr.IsDBNull(2) ?
null : (byte[])(rdr[2]);
item.appId = rdr.IsDBNull(0) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);
item.circleId = rdr.IsDBNull(1) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[1]);
item.dataNoLengthCheck = rdr.IsDBNull(2) ? null : (byte[])(rdr[2]);
if (item.data?.Length > 65535)
throw new Exception("Too much data in data...");
if (item.data?.Length < 0)
@@ -434,9 +433,7 @@ protected AppGrantsRecord ReadRecordFromReader1(DbDataReader rdr, Guid identityI
item.odinHashId = odinHashId;
item.appId = appId;
item.circleId = circleId;

item.data = rdr.IsDBNull(0) ?
null : (byte[])(rdr[0]);
item.dataNoLengthCheck = rdr.IsDBNull(0) ? null : (byte[])(rdr[0]);
if (item.data?.Length > 65535)
throw new Exception("Too much data in data...");
if (item.data?.Length < 0)
Original file line number Diff line number Diff line change
@@ -59,6 +59,16 @@ public string senderId
_senderId = value;
}
}
internal string senderIdNoLengthCheck
{
get {
return _senderId;
}
set {
if (value?.Length < 0) throw new Exception("Too short");
_senderId = value;
}
}
private UnixTimeUtc _timestamp;
public UnixTimeUtc timestamp
{
@@ -81,6 +91,16 @@ public byte[] data
_data = value;
}
}
internal byte[] dataNoLengthCheck
{
get {
return _data;
}
set {
if (value?.Length < 0) throw new Exception("Too short");
_data = value;
}
}
private UnixTimeUtcUnique _created;
public UnixTimeUtcUnique created
{
@@ -384,7 +404,7 @@ protected virtual async Task<int> GetCountAsync()
}
}

public List<string> GetColumnNames()
public static List<string> GetColumnNames()
{
var sl = new List<string>();
sl.Add("identityId");
@@ -408,26 +428,18 @@ protected AppNotificationsRecord ReadRecordFromReaderAll(DbDataReader rdr)
#pragma warning restore CS0168
var guid = new byte[16];
var item = new AppNotificationsRecord();
item.identityId = rdr.IsDBNull(0) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);
item.notificationId = rdr.IsDBNull(1) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[1]);
item.unread = rdr.IsDBNull(2) ?
throw new Exception("item is NULL, but set as NOT NULL") : (int)(long)rdr[2];
item.senderId = rdr.IsDBNull(3) ?
null : (string)rdr[3];
item.timestamp = rdr.IsDBNull(4) ?
throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtc((long)rdr[4]);
item.data = rdr.IsDBNull(5) ?
null : (byte[])(rdr[5]);
item.identityId = rdr.IsDBNull(0) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);
item.notificationId = rdr.IsDBNull(1) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[1]);
item.unread = rdr.IsDBNull(2) ? throw new Exception("item is NULL, but set as NOT NULL") : (int)(long)rdr[2];
item.senderIdNoLengthCheck = rdr.IsDBNull(3) ? null : (string)rdr[3];
item.timestamp = rdr.IsDBNull(4) ? throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtc((long)rdr[4]);
item.dataNoLengthCheck = rdr.IsDBNull(5) ? null : (byte[])(rdr[5]);
if (item.data?.Length > 65000)
throw new Exception("Too much data in data...");
if (item.data?.Length < 0)
throw new Exception("Too little data in data...");
item.created = rdr.IsDBNull(6) ?
throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtcUnique((long)rdr[6]);
item.modified = rdr.IsDBNull(7) ?
null : new UnixTimeUtcUnique((long)rdr[7]);
item.created = rdr.IsDBNull(6) ? throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtcUnique((long)rdr[6]);
item.modified = rdr.IsDBNull(7) ? null : new UnixTimeUtcUnique((long)rdr[7]);
return item;
}

@@ -465,28 +477,16 @@ protected AppNotificationsRecord ReadRecordFromReader0(DbDataReader rdr, Guid id
var item = new AppNotificationsRecord();
item.identityId = identityId;
item.notificationId = notificationId;

item.unread = rdr.IsDBNull(0) ?
throw new Exception("item is NULL, but set as NOT NULL") : (int)(long)rdr[0];

item.senderId = rdr.IsDBNull(1) ?
null : (string)rdr[1];

item.timestamp = rdr.IsDBNull(2) ?
throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtc((long)rdr[2]);

item.data = rdr.IsDBNull(3) ?
null : (byte[])(rdr[3]);
item.unread = rdr.IsDBNull(0) ? throw new Exception("item is NULL, but set as NOT NULL") : (int)(long)rdr[0];
item.senderIdNoLengthCheck = rdr.IsDBNull(1) ? null : (string)rdr[1];
item.timestamp = rdr.IsDBNull(2) ? throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtc((long)rdr[2]);
item.dataNoLengthCheck = rdr.IsDBNull(3) ? null : (byte[])(rdr[3]);
if (item.data?.Length > 65000)
throw new Exception("Too much data in data...");
if (item.data?.Length < 0)
throw new Exception("Too little data in data...");

item.created = rdr.IsDBNull(4) ?
throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtcUnique((long)rdr[4]);

item.modified = rdr.IsDBNull(5) ?
null : new UnixTimeUtcUnique((long)rdr[5]);
item.created = rdr.IsDBNull(4) ? throw new Exception("item is NULL, but set as NOT NULL") : new UnixTimeUtcUnique((long)rdr[4]);
item.modified = rdr.IsDBNull(5) ? null : new UnixTimeUtcUnique((long)rdr[5]);
return item;
}

Original file line number Diff line number Diff line change
@@ -40,6 +40,17 @@ public string circleName
_circleName = value;
}
}
internal string circleNameNoLengthCheck
{
get {
return _circleName;
}
set {
if (value == null) throw new Exception("Cannot be null");
if (value?.Length < 2) throw new Exception("Too short");
_circleName = value;
}
}
private Guid _circleId;
public Guid circleId
{
@@ -62,6 +73,16 @@ public byte[] data
_data = value;
}
}
internal byte[] dataNoLengthCheck
{
get {
return _data;
}
set {
if (value?.Length < 0) throw new Exception("Too short");
_data = value;
}
}
} // End of class CircleRecord

public abstract class TableCircleCRUD
@@ -256,7 +277,7 @@ protected virtual async Task<int> GetCountAsync()
}
}

public List<string> GetColumnNames()
public static List<string> GetColumnNames()
{
var sl = new List<string>();
sl.Add("identityId");
@@ -276,14 +297,10 @@ protected CircleRecord ReadRecordFromReaderAll(DbDataReader rdr)
#pragma warning restore CS0168
var guid = new byte[16];
var item = new CircleRecord();
item.identityId = rdr.IsDBNull(0) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);
item.circleName = rdr.IsDBNull(1) ?
throw new Exception("item is NULL, but set as NOT NULL") : (string)rdr[1];
item.circleId = rdr.IsDBNull(2) ?
throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[2]);
item.data = rdr.IsDBNull(3) ?
null : (byte[])(rdr[3]);
item.identityId = rdr.IsDBNull(0) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[0]);
item.circleNameNoLengthCheck = rdr.IsDBNull(1) ? throw new Exception("item is NULL, but set as NOT NULL") : (string)rdr[1];
item.circleId = rdr.IsDBNull(2) ? throw new Exception("item is NULL, but set as NOT NULL") : new Guid((byte[])rdr[2]);
item.dataNoLengthCheck = rdr.IsDBNull(3) ? null : (byte[])(rdr[3]);
if (item.data?.Length > 65000)
throw new Exception("Too much data in data...");
if (item.data?.Length < 0)
@@ -325,12 +342,8 @@ protected CircleRecord ReadRecordFromReader0(DbDataReader rdr, Guid identityId,G
var item = new CircleRecord();
item.identityId = identityId;
item.circleId = circleId;

item.circleName = rdr.IsDBNull(0) ?
throw new Exception("item is NULL, but set as NOT NULL") : (string)rdr[0];

item.data = rdr.IsDBNull(1) ?
null : (byte[])(rdr[1]);
item.circleNameNoLengthCheck = rdr.IsDBNull(0) ? throw new Exception("item is NULL, but set as NOT NULL") : (string)rdr[0];
item.dataNoLengthCheck = rdr.IsDBNull(1) ? null : (byte[])(rdr[1]);
if (item.data?.Length > 65000)
throw new Exception("Too much data in data...");
if (item.data?.Length < 0)
Loading