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
@@ -21,6 +21,9 @@ type TaskBlock struct {
|
||||
}
|
||||
|
||||
func (s *Store) ensureTaskBlocksSchema() error {
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
return s.ensurePostgreSQLTaskProductivity(context.Background())
|
||||
}
|
||||
_, err := s.DB.Exec(`CREATE TABLE IF NOT EXISTS organizer_time_blocks(domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,uuid TEXT NOT NULL,task_uuid TEXT NOT NULL,calendar_uuid TEXT NOT NULL,event_uid TEXT NOT NULL,start TEXT NOT NULL,end TEXT NOT NULL,state TEXT NOT NULL,created_at_ms INTEGER NOT NULL,PRIMARY KEY(domain_uuid,uuid)); CREATE INDEX IF NOT EXISTS organizer_time_blocks_live ON organizer_time_blocks(domain_uuid,owner_uuid,task_uuid,created_at_ms,uuid) WHERE state!='unlinked'`)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -35,7 +38,7 @@ func (s *Store) ensureTaskBlocksSchema() error {
|
||||
return err
|
||||
}
|
||||
|
||||
const taskBlockColumns = `uuid,task_uuid,calendar_uuid,event_uid,start,end,state,title`
|
||||
const taskBlockColumns = `uuid,task_uuid,calendar_uuid,event_uid,start,"end",state,title`
|
||||
|
||||
func scanTaskBlock(row interface{ Scan(...any) error }) (TaskBlock, error) {
|
||||
var b TaskBlock
|
||||
@@ -54,7 +57,10 @@ func scanTaskBlock(row interface{ Scan(...any) error }) (TaskBlock, error) {
|
||||
|
||||
// Reserve before touching canonical calendar files. This durable intent bridges
|
||||
// the two commit domains; the caller can safely retry using the same UUID.
|
||||
func (s *Store) ReserveTaskBlock(ctx context.Context, domain, actor string, b TaskBlock, version int64) (TaskBlock, error) {
|
||||
func (s *Store) ReserveTaskBlock(ctx context.Context, domain, actor string, b TaskBlock, version int64) (result0 TaskBlock, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("organizer repository", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
for _, id := range []string{b.UUID, b.TaskUUID, b.CalendarUUID} {
|
||||
if _, err := uuid.Parse(id); err != nil {
|
||||
return b, ErrTaskInvalid
|
||||
@@ -71,13 +77,16 @@ func (s *Store) ReserveTaskBlock(ctx context.Context, domain, actor string, b Ta
|
||||
return b, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=? AND principal_uuid=?`, domain, actor); err != nil {
|
||||
if err = s.lockTaskWriter(ctx, tx); err != nil {
|
||||
return b, err
|
||||
}
|
||||
if err = taskActor(ctx, tx, domain, actor, true); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=`+s.sqlParam(1)+` AND principal_uuid=`+s.sqlParam(2)+``, domain, actor); err != nil {
|
||||
return b, err
|
||||
}
|
||||
enabled, err := taskReminderExtensionEnabled(ctx, tx, domain)
|
||||
if err = s.taskActor(ctx, tx, domain, actor, true); err != nil {
|
||||
return b, err
|
||||
}
|
||||
enabled, err := s.taskReminderExtensionEnabled(ctx, tx, domain)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
@@ -85,18 +94,18 @@ func (s *Store) ReserveTaskBlock(ctx context.Context, domain, actor string, b Ta
|
||||
return b, ErrAccessDenied
|
||||
}
|
||||
var current int64
|
||||
err = tx.QueryRowContext(ctx, `SELECT version,title FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=? AND kind='task' AND archived=0 AND status NOT IN ('done','cancelled')`, domain, actor, b.TaskUUID).Scan(¤t, &b.Title)
|
||||
err = tx.QueryRowContext(ctx, `SELECT version,title FROM organizer_items WHERE domain_uuid=`+s.sqlParam(1)+` AND owner_uuid=`+s.sqlParam(2)+` AND uuid=`+s.sqlParam(3)+` AND kind='task' AND archived=0 AND status NOT IN ('done','cancelled')`, domain, actor, b.TaskUUID).Scan(¤t, &b.Title)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
old, err := scanTaskBlock(tx.QueryRowContext(ctx, `SELECT `+taskBlockColumns+` FROM organizer_time_blocks WHERE domain_uuid=? AND owner_uuid=? AND uuid=?`, domain, actor, b.UUID))
|
||||
old, err := scanTaskBlock(tx.QueryRowContext(ctx, `SELECT `+taskBlockColumns+` FROM organizer_time_blocks WHERE domain_uuid=`+s.sqlParam(1)+` AND owner_uuid=`+s.sqlParam(2)+` AND uuid=`+s.sqlParam(3)+``, domain, actor, b.UUID))
|
||||
if err == nil {
|
||||
if old.TaskUUID != b.TaskUUID || old.CalendarUUID != b.CalendarUUID || !old.Start.Equal(b.Start) || !old.End.Equal(b.End) || old.State == "unlinked" {
|
||||
return b, ErrTaskConflict
|
||||
}
|
||||
if old.Title == "" && old.State == "pending" {
|
||||
old.Title = b.Title
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE organizer_time_blocks SET title=? WHERE domain_uuid=? AND uuid=?`, old.Title, domain, old.UUID); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE organizer_time_blocks SET title=`+s.sqlParam(1)+` WHERE domain_uuid=`+s.sqlParam(2)+` AND uuid=`+s.sqlParam(3)+``, old.Title, domain, old.UUID); err != nil {
|
||||
return b, err
|
||||
}
|
||||
}
|
||||
@@ -109,14 +118,14 @@ func (s *Store) ReserveTaskBlock(ctx context.Context, domain, actor string, b Ta
|
||||
return b, ErrTaskConflict
|
||||
}
|
||||
var count int
|
||||
if err = tx.QueryRowContext(ctx, `SELECT count(*) FROM organizer_time_blocks WHERE domain_uuid=? AND owner_uuid=? AND task_uuid=? AND state!='unlinked'`, domain, actor, b.TaskUUID).Scan(&count); err != nil {
|
||||
if err = tx.QueryRowContext(ctx, `SELECT count(*) FROM organizer_time_blocks WHERE domain_uuid=`+s.sqlParam(1)+` AND owner_uuid=`+s.sqlParam(2)+` AND task_uuid=`+s.sqlParam(3)+` AND state!='unlinked'`, domain, actor, b.TaskUUID).Scan(&count); err != nil {
|
||||
return b, err
|
||||
}
|
||||
if count >= 100 {
|
||||
return b, ErrTaskInvalid
|
||||
}
|
||||
b.State = "pending"
|
||||
res, err := tx.ExecContext(ctx, `INSERT OR IGNORE INTO organizer_time_blocks(domain_uuid,owner_uuid,uuid,task_uuid,calendar_uuid,event_uid,start,end,state,created_at_ms,title) VALUES(?,?,?,?,?,?,?,?,?,?,?)`, domain, actor, b.UUID, b.TaskUUID, b.CalendarUUID, b.EventUID, b.Start.Format(time.RFC3339), b.End.Format(time.RFC3339), b.State, time.Now().UnixMilli(), b.Title)
|
||||
res, err := tx.ExecContext(ctx, `INSERT INTO organizer_time_blocks(domain_uuid,owner_uuid,uuid,task_uuid,calendar_uuid,event_uid,start,"end",state,created_at_ms,title) VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,`+s.sqlParam(6)+`,`+s.sqlParam(7)+`,`+s.sqlParam(8)+`,`+s.sqlParam(9)+`,`+s.sqlParam(10)+`,`+s.sqlParam(11)+`) ON CONFLICT DO NOTHING`, domain, actor, b.UUID, b.TaskUUID, b.CalendarUUID, b.EventUID, b.Start.Format(time.RFC3339), b.End.Format(time.RFC3339), b.State, time.Now().UnixMilli(), b.Title)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
@@ -126,11 +135,12 @@ func (s *Store) ReserveTaskBlock(ctx context.Context, domain, actor string, b Ta
|
||||
return b, tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) TaskBlocks(ctx context.Context, domain, actor, task string) ([]TaskBlock, error) {
|
||||
func (s *Store) TaskBlocks(ctx context.Context, domain, actor, task string) (result0 []TaskBlock, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("organizer repository", resultErr) }()
|
||||
if _, err := s.GetTask(ctx, domain, actor, task); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT `+taskBlockColumns+` FROM organizer_time_blocks WHERE domain_uuid=? AND owner_uuid=? AND task_uuid=? AND state!='unlinked' ORDER BY created_at_ms,uuid LIMIT 100`, domain, actor, task)
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT `+taskBlockColumns+` FROM organizer_time_blocks WHERE domain_uuid=`+s.sqlParam(1)+` AND owner_uuid=`+s.sqlParam(2)+` AND task_uuid=`+s.sqlParam(3)+` AND state!='unlinked' ORDER BY created_at_ms,uuid LIMIT 100`, domain, actor, task)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -146,7 +156,10 @@ func (s *Store) TaskBlocks(ctx context.Context, domain, actor, task string) ([]T
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) SetTaskBlockState(ctx context.Context, domain, actor, id, state string) error {
|
||||
func (s *Store) SetTaskBlockState(ctx context.Context, domain, actor, id, state string) (resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("organizer repository", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
if state != "active" && state != "unlinked" {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
@@ -155,20 +168,23 @@ func (s *Store) SetTaskBlockState(ctx context.Context, domain, actor, id, state
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=? AND principal_uuid=?`, domain, actor); err != nil {
|
||||
if err = s.lockTaskWriter(ctx, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = taskActor(ctx, tx, domain, actor, true); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=`+s.sqlParam(1)+` AND principal_uuid=`+s.sqlParam(2)+``, domain, actor); err != nil {
|
||||
return err
|
||||
}
|
||||
enabled, err := taskReminderExtensionEnabled(ctx, tx, domain)
|
||||
if err = s.taskActor(ctx, tx, domain, actor, true); err != nil {
|
||||
return err
|
||||
}
|
||||
enabled, err := s.taskReminderExtensionEnabled(ctx, tx, domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !enabled {
|
||||
return ErrAccessDenied
|
||||
}
|
||||
res, err := tx.ExecContext(ctx, `UPDATE organizer_time_blocks SET state=? WHERE domain_uuid=? AND owner_uuid=? AND uuid=? AND (state!='unlinked' OR ?='unlinked')`, state, domain, actor, id, state)
|
||||
res, err := tx.ExecContext(ctx, `UPDATE organizer_time_blocks SET state=`+s.sqlParam(1)+` WHERE domain_uuid=`+s.sqlParam(2)+` AND owner_uuid=`+s.sqlParam(3)+` AND uuid=`+s.sqlParam(4)+` AND (state!='unlinked' OR `+s.sqlParam(5)+`='unlinked')`, state, domain, actor, id, state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -178,11 +194,12 @@ func (s *Store) SetTaskBlockState(ctx context.Context, domain, actor, id, state
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) GetTaskBlock(ctx context.Context, domain, actor, id string) (TaskBlock, error) {
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
func (s *Store) GetTaskBlock(ctx context.Context, domain, actor, id string) (result0 TaskBlock, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("organizer repository", resultErr) }()
|
||||
if err := s.taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
return TaskBlock{}, err
|
||||
}
|
||||
b, err := scanTaskBlock(s.DB.QueryRowContext(ctx, `SELECT `+taskBlockColumns+` FROM organizer_time_blocks WHERE domain_uuid=? AND owner_uuid=? AND uuid=? AND state!='unlinked'`, domain, actor, id))
|
||||
b, err := scanTaskBlock(s.DB.QueryRowContext(ctx, `SELECT `+taskBlockColumns+` FROM organizer_time_blocks WHERE domain_uuid=`+s.sqlParam(1)+` AND owner_uuid=`+s.sqlParam(2)+` AND uuid=`+s.sqlParam(3)+` AND state!='unlinked'`, domain, actor, id))
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user