Major schema refactoring: simplify ASN and prefix tracking
- Remove UUID primary keys from ASNs table, use ASN number as primary key - Update announcements table to reference ASN numbers directly - Rename asns.number column to asns.asn for consistency - Add prefix tracking to PrefixHandler to populate prefixes_v4/v6 tables - Add UpdatePrefixesBatch method for efficient batch updates - Update all database methods and models to use new schema - Fix all references in code to use ASN field instead of Number - Update test mocks to match new interfaces
This commit is contained in:
@@ -61,8 +61,7 @@ func (m *mockStore) GetOrCreateASN(number int, timestamp time.Time) (*database.A
|
||||
}
|
||||
|
||||
asn := &database.ASN{
|
||||
ID: uuid.New(),
|
||||
Number: number,
|
||||
ASN: number,
|
||||
FirstSeen: timestamp,
|
||||
LastSeen: timestamp,
|
||||
}
|
||||
@@ -72,6 +71,37 @@ func (m *mockStore) GetOrCreateASN(number int, timestamp time.Time) (*database.A
|
||||
return asn, nil
|
||||
}
|
||||
|
||||
// UpdatePrefixesBatch mock implementation
|
||||
func (m *mockStore) UpdatePrefixesBatch(prefixes map[string]time.Time) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
for prefix, timestamp := range prefixes {
|
||||
if p, exists := m.Prefixes[prefix]; exists {
|
||||
p.LastSeen = timestamp
|
||||
} else {
|
||||
const (
|
||||
ipVersionV4 = 4
|
||||
ipVersionV6 = 6
|
||||
)
|
||||
|
||||
ipVersion := ipVersionV4
|
||||
if strings.Contains(prefix, ":") {
|
||||
ipVersion = ipVersionV6
|
||||
}
|
||||
|
||||
m.Prefixes[prefix] = &database.Prefix{
|
||||
ID: uuid.New(),
|
||||
Prefix: prefix,
|
||||
IPVersion: ipVersion,
|
||||
FirstSeen: timestamp,
|
||||
LastSeen: timestamp,
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOrCreatePrefix mock implementation
|
||||
func (m *mockStore) GetOrCreatePrefix(prefix string, timestamp time.Time) (*database.Prefix, error) {
|
||||
m.mu.Lock()
|
||||
@@ -302,8 +332,7 @@ func (m *mockStore) GetOrCreateASNBatch(asns map[int]time.Time) error {
|
||||
for number, timestamp := range asns {
|
||||
if _, exists := m.ASNs[number]; !exists {
|
||||
m.ASNs[number] = &database.ASN{
|
||||
ID: uuid.New(),
|
||||
Number: number,
|
||||
ASN: number,
|
||||
FirstSeen: timestamp,
|
||||
LastSeen: timestamp,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user