feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -2,6 +2,7 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -30,11 +31,14 @@ func scanBroadcast(scanner interface{ Scan(...any) error }, b *Broadcast) error
|
||||
return scanner.Scan(&b.UUID, &b.DomainUUID, &b.Title, &b.Body, &b.Severity, &b.StartsAtMS, &b.EndsAtMS, &b.CreatedAtMS, &b.UpdatedAtMS)
|
||||
}
|
||||
|
||||
func (s *Store) ListActiveBroadcasts(ctx context.Context, domain string, nowMS int64) ([]Broadcast, error) {
|
||||
func (s *Store) ListActiveBroadcasts(ctx context.Context, domain string, nowMS int64) (_ []Broadcast, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("active broadcasts", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
if nowMS == 0 {
|
||||
nowMS = time.Now().UnixMilli()
|
||||
}
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT `+broadcastColumns+` FROM broadcasts WHERE domain_uuid=? AND (starts_at_ms=0 OR starts_at_ms<=?) AND (ends_at_ms=0 OR ends_at_ms>?) ORDER BY severity DESC,updated_at_ms DESC LIMIT 20`, domain, nowMS, nowMS)
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT `+broadcastColumns+` FROM broadcasts WHERE domain_uuid=`+s.sqlParam(1)+` AND (starts_at_ms=0 OR starts_at_ms<=`+s.sqlParam(2)+`) AND (ends_at_ms=0 OR ends_at_ms>`+s.sqlParam(3)+`) ORDER BY severity DESC,updated_at_ms DESC LIMIT 20`, domain, nowMS, nowMS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -49,8 +53,11 @@ func (s *Store) ListActiveBroadcasts(ctx context.Context, domain string, nowMS i
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
func (s *Store) ListBroadcasts(ctx context.Context, domain string) ([]Broadcast, error) {
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT `+broadcastColumns+` FROM broadcasts WHERE domain_uuid=? ORDER BY updated_at_ms DESC LIMIT 100`, domain)
|
||||
func (s *Store) ListBroadcasts(ctx context.Context, domain string) (_ []Broadcast, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("broadcast listing", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT `+broadcastColumns+` FROM broadcasts WHERE domain_uuid=`+s.sqlParam(1)+` ORDER BY updated_at_ms DESC LIMIT 100`, domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -65,7 +72,11 @@ func (s *Store) ListBroadcasts(ctx context.Context, domain string) ([]Broadcast,
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
func (s *Store) SaveBroadcast(b Broadcast) error {
|
||||
func (s *Store) SaveBroadcast(b Broadcast) (resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("broadcast save", resultErr) }()
|
||||
if s.ReadOnly {
|
||||
return ErrReadOnly
|
||||
}
|
||||
b.DomainUUID = strings.TrimSpace(b.DomainUUID)
|
||||
b.Title = strings.TrimSpace(b.Title)
|
||||
b.Body = strings.TrimSpace(b.Body)
|
||||
@@ -80,26 +91,55 @@ func (s *Store) SaveBroadcast(b Broadcast) error {
|
||||
b.CreatedAtMS = now
|
||||
}
|
||||
b.UpdatedAtMS = now
|
||||
_, err := s.DB.Exec(`INSERT INTO broadcasts(`+broadcastColumns+`) VALUES(?,?,?,?,?,?,?,?,?) ON CONFLICT(uuid) DO UPDATE SET title=excluded.title,body=excluded.body,severity=excluded.severity,starts_at_ms=excluded.starts_at_ms,ends_at_ms=excluded.ends_at_ms,updated_at_ms=excluded.updated_at_ms`, b.UUID, b.DomainUUID, b.Title, b.Body, b.Severity, b.StartsAtMS, b.EndsAtMS, b.CreatedAtMS, b.UpdatedAtMS)
|
||||
return err
|
||||
}
|
||||
func (s *Store) DeleteBroadcast(domain, id string) error {
|
||||
tx, err := s.DB.Begin()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, err = tx.Exec(`DELETE FROM notification_inbox WHERE domain_uuid=? AND event_uuid=? AND kind='broadcast'`, domain, id); err != nil {
|
||||
if err = s.lockTaskWriter(ctx, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = tx.Exec(`DELETE FROM broadcasts WHERE domain_uuid=? AND uuid=?`, domain, id); err != nil {
|
||||
result, err := tx.ExecContext(ctx, `INSERT INTO broadcasts(`+broadcastColumns+`) VALUES(`+s.sqlValues(9)+`) ON CONFLICT(uuid) DO UPDATE SET title=excluded.title,body=excluded.body,severity=excluded.severity,starts_at_ms=excluded.starts_at_ms,ends_at_ms=excluded.ends_at_ms,updated_at_ms=excluded.updated_at_ms WHERE broadcasts.domain_uuid=excluded.domain_uuid`, b.UUID, b.DomainUUID, b.Title, b.Body, b.Severity, b.StartsAtMS, b.EndsAtMS, b.CreatedAtMS, b.UpdatedAtMS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n != 1 {
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
func (s *Store) DeleteBroadcast(domain, id string) (resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("broadcast deletion", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if err = s.lockTaskWriter(ctx, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = tx.Exec(`DELETE FROM notification_inbox WHERE domain_uuid=`+s.sqlParam(1)+` AND event_uuid=`+s.sqlParam(2)+` AND kind='broadcast'`, domain, id); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = tx.Exec(`DELETE FROM broadcasts WHERE domain_uuid=`+s.sqlParam(1)+` AND uuid=`+s.sqlParam(2)+``, domain, id); err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) GetBroadcast(ctx context.Context, domain, id string) (Broadcast, error) {
|
||||
func (s *Store) GetBroadcast(ctx context.Context, domain, id string) (_ Broadcast, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("broadcast lookup", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
var b Broadcast
|
||||
err := scanBroadcast(s.DB.QueryRowContext(ctx, `SELECT `+broadcastColumns+` FROM broadcasts WHERE domain_uuid=? AND uuid=?`, domain, id), &b)
|
||||
err := scanBroadcast(s.DB.QueryRowContext(ctx, `SELECT `+broadcastColumns+` FROM broadcasts WHERE domain_uuid=`+s.sqlParam(1)+` AND uuid=`+s.sqlParam(2)+``, domain, id), &b)
|
||||
return b, err
|
||||
}
|
||||
Reference in new issue
Block a user