feat: initialize CollabTableServer with models, sync, and notification handling
Docker / Docker Build & Push (push) Successful in 10m21s
Lint / Lint (push) Failing after 14s
Tests / Go backend (push) Successful in 21s
Tests / Dashboard checks (push) Successful in 21s

- Add go.mod and go.sum for dependency management
- Implement models for List, Field, Item, ItemValue, SyncRequest, SyncResponse, and NotificationEvent
- Create notification handling functions including enqueueNotification and ignoreNotificationError
- Implement sync functionality to handle data synchronization between client and server
- Add web data handling and notification polling endpoints
- Include tests for timestamp normalization and sync logic
- Embed web assets for serving the frontend application
This commit is contained in:
Gabriel20xx committed 2026-08-03 18:07:40 +02:00
1 parent e12940fef0
commit cac2faae2e
41 files changed
+2535 -5502

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
package main
import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"time"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
)
type queryExecutor interface {
Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
}
func notificationID() string {
buffer := make([]byte, 16)
if _, err := rand.Read(buffer); err == nil {
return hex.EncodeToString(buffer)
}
return fmt.Sprintf("%d", time.Now().UnixNano())
}
func enqueueNotification(
ctx context.Context,
executor queryExecutor,
deviceID string,
eventType string,
entityType string,
entityID string,
listID string,
createdAt int64,
) error {
_, err := executor.Exec(ctx, `
INSERT INTO notifications
(id, deviceidorigin, eventtype, entitytype, entityid, listid, createdat)
VALUES ($1, $2, $3, $4, $5, $6, $7)
`, notificationID(), nullableString(deviceID), eventType, entityType, nullableString(entityID), nullableString(listID), createdAt)
return err
}
func nullableString(value string) any {
if value == "" {
return nil
}
return value
}
func ignoreNotificationError(err error) {
if err != nil {
// Notifications are an acceleration path for clients that poll. A failed
// notification must never roll back the data mutation that produced it.
fmt.Printf("[notifications] enqueue failed: %v\n", err)
}
}
func isNoRows(err error) bool {
return err == pgx.ErrNoRows
}