Skip to content

Commit 0aba974

Browse files
MDI240 | remove eml_file_path column
1 parent 681f05a commit 0aba974

File tree

8 files changed

+21
-29
lines changed

8 files changed

+21
-29
lines changed

docker/mysql/migrations/001_create_emails_table.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS emails (
66
'CALLING-SENT-CALLBACK','CALLING-FAILED-CALLBACK',
77
'SENT-ACKNOWLEDGED','FAILED-ACKNOWLEDGED'
88
) NOT NULL,
9-
eml_file_path VARCHAR(500),
109
payload_file_path VARCHAR(500),
1110
reason TEXT,
1211
version INT NOT NULL DEFAULT 1,

docs/database.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
type Email struct {
66
Id string
77
Status string
8-
EmlFilePath string // Campo mantenuto per compatibilità, non usato
98
PayloadFilePath string
109
UpdatedAt string
1110
Reason string
@@ -27,7 +26,6 @@ CREATE TABLE IF NOT EXISTS emails (
2726
'CALLING-SENT-CALLBACK','CALLING-FAILED-CALLBACK',
2827
'SENT-ACKNOWLEDGED','FAILED-ACKNOWLEDGED'
2928
) NOT NULL,
30-
eml_file_path VARCHAR(500),
3129
payload_file_path VARCHAR(500),
3230
reason TEXT,
3331
version INT NOT NULL DEFAULT 1,
@@ -75,7 +73,7 @@ Le query di lettura utilizzano `FOR UPDATE SKIP LOCKED` per:
7573
- Migliorare il throughput in scenari con più processori concorrenti
7674

7775
```sql
78-
SELECT id, status, eml_file_path, payload_file_path, reason, version, updated_at
76+
SELECT id, status, payload_file_path, reason, version, updated_at
7977
FROM emails
8078
WHERE status = ?
8179
ORDER BY updated_at ASC

internal/outbox/outbox.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ var retryableErrNos = map[uint16]bool{
4444
type Email struct {
4545
Id string
4646
Status string
47-
EmlFilePath string
4847
PayloadFilePath string
4948
UpdatedAt string
5049
Reason string
@@ -133,7 +132,7 @@ func (o *Outbox) Query(ctx context.Context, status string, limit int) ([]Email,
133132
// - Rows currently locked by other transactions are skipped
134133
// - Reduces contention when multiple workers poll simultaneously
135134
query := `
136-
SELECT id, status, eml_file_path, payload_file_path, reason, version, updated_at
135+
SELECT id, status, payload_file_path, reason, version, updated_at
137136
FROM emails
138137
WHERE status = ?
139138
ORDER BY updated_at ASC
@@ -150,13 +149,12 @@ func (o *Outbox) Query(ctx context.Context, status string, limit int) ([]Email,
150149
var emails []Email
151150
for rows.Next() {
152151
var e Email
153-
var emlFilePath, payloadFilePath, reason sql.NullString
152+
var payloadFilePath, reason sql.NullString
154153
var updatedAt time.Time
155154

156155
err := rows.Scan(
157156
&e.Id,
158157
&e.Status,
159-
&emlFilePath,
160158
&payloadFilePath,
161159
&reason,
162160
&e.Version,
@@ -166,7 +164,6 @@ func (o *Outbox) Query(ctx context.Context, status string, limit int) ([]Email,
166164
return []Email{}, err
167165
}
168166

169-
e.EmlFilePath = emlFilePath.String
170167
e.PayloadFilePath = payloadFilePath.String
171168
e.Reason = reason.String
172169
e.UpdatedAt = updatedAt.Format(time.RFC3339)
@@ -288,13 +285,13 @@ func (o *Outbox) Requeue(ctx context.Context, id string) error {
288285
return err
289286
}
290287

291-
// Ready updates the email to READY status with the eml file path.
288+
// Ready updates the email to READY status.
292289
// Expected from status is INTAKING.
293290
// The operation is executed within a transaction with retry logic for transient errors.
294-
func (o *Outbox) Ready(ctx context.Context, id string, emlFilePath string) error {
291+
func (o *Outbox) Ready(ctx context.Context, id string) error {
295292
updateQuery := `
296293
UPDATE emails
297-
SET status = ?, eml_file_path = ?, version = version + 1
294+
SET status = ?, version = version + 1
298295
WHERE id = ? AND status = ?
299296
`
300297
historyQuery := `
@@ -305,7 +302,7 @@ func (o *Outbox) Ready(ctx context.Context, id string, emlFilePath string) error
305302
var err error
306303
for attempt := range maxAttempts {
307304
err = o.executeInTransaction(ctx, func(tx *sql.Tx) error {
308-
result, execErr := tx.ExecContext(ctx, updateQuery, StatusReady, emlFilePath, id, StatusIntaking)
305+
result, execErr := tx.ExecContext(ctx, updateQuery, StatusReady, id, StatusIntaking)
309306
if execErr != nil {
310307
return execErr
311308
}

internal/outbox/outbox_component_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ func TestMySQLOutboxReadyWorkflow(t *testing.T) {
114114
require.NoError(t, err)
115115
fixtures = append(fixtures, id)
116116

117-
// update to READY without eml file path
118-
err = sut.Ready(context.TODO(), id, "", nil)
117+
// update to READY
118+
err = sut.Ready(context.TODO(), id)
119119
require.NoError(t, err)
120120

121121
// verify status changed to READY
@@ -124,10 +124,9 @@ func TestMySQLOutboxReadyWorkflow(t *testing.T) {
124124
require.Len(t, res, 1)
125125
assert.Equal(t, id, res[0].Id)
126126
assert.Equal(t, StatusReady, res[0].Status)
127-
assert.Empty(t, res[0].EmlFilePath)
128127

129128
// trying to call Ready again should fail (status is now READY, not INTAKING)
130-
err = sut.Ready(context.TODO(), id, "", nil)
129+
err = sut.Ready(context.TODO(), id)
131130
assert.Error(t, err)
132131
assert.ErrorIs(t, err, ErrLockNotAcquired)
133132
}
@@ -194,7 +193,7 @@ func TestMySQLOutboxStateTransitions(t *testing.T) {
194193
assert.Equal(t, StatusIntaking, status)
195194

196195
// INTAKING -> READY (using Ready method)
197-
err = sut.Ready(context.TODO(), id, "", nil)
196+
err = sut.Ready(context.TODO(), id)
198197
require.NoError(t, err)
199198

200199
status, err = facade.GetEmailStatus(context.TODO(), id)

internal/outbox/outbox_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func TestQuery_WhenDatabaseHasRecords_ShouldReturnEmails(t *testing.T) {
2222

2323
now := time.Now()
2424

25-
rows := sqlmock.NewRows([]string{"id", "status", "eml_file_path", "payload_file_path", "reason", "version", "updated_at"}).
26-
AddRow("test-id-1", "READY", "", "/path/to/payload", "", 1, now).
27-
AddRow("test-id-2", "READY", "", "/path/to/payload2", "some reason", 2, now)
25+
rows := sqlmock.NewRows([]string{"id", "status", "payload_file_path", "reason", "version", "updated_at"}).
26+
AddRow("test-id-1", "READY", "/path/to/payload", "", 1, now).
27+
AddRow("test-id-2", "READY", "/path/to/payload2", "some reason", 2, now)
2828

29-
mock.ExpectQuery("SELECT id, status, eml_file_path, payload_file_path, reason, version, updated_at FROM emails").
29+
mock.ExpectQuery("SELECT id, status, payload_file_path, reason, version, updated_at FROM emails").
3030
WithArgs("READY", 25).
3131
WillReturnRows(rows)
3232

@@ -38,7 +38,6 @@ func TestQuery_WhenDatabaseHasRecords_ShouldReturnEmails(t *testing.T) {
3838
require.Len(t, emails, 2)
3939
assert.Equal(t, "test-id-1", emails[0].Id)
4040
assert.Equal(t, "READY", emails[0].Status)
41-
assert.Equal(t, "", emails[0].EmlFilePath)
4241
assert.Equal(t, "test-id-2", emails[1].Id)
4342

4443
assert.NoError(t, mock.ExpectationsWereMet())
@@ -70,7 +69,7 @@ func TestQuery_WhenDatabaseHasNoRecords_ShouldReturnEmptySlice(t *testing.T) {
7069
require.NoError(t, err)
7170
defer db.Close()
7271

73-
rows := sqlmock.NewRows([]string{"id", "status", "eml_file_path", "payload_file_path", "reason", "version", "updated_at"})
72+
rows := sqlmock.NewRows([]string{"id", "status", "payload_file_path", "reason", "version", "updated_at"})
7473

7574
mock.ExpectQuery("SELECT").
7675
WithArgs("READY", 10).
@@ -172,7 +171,7 @@ func TestReady_WhenUpdateSucceeds_ShouldReturnNoError(t *testing.T) {
172171

173172
sut := NewOutboxWithDB(db)
174173

175-
err = sut.Ready(context.TODO(), "test-id", "", nil)
174+
err = sut.Ready(context.TODO(), "test-id")
176175

177176
assert.NoError(t, err)
178177
assert.NoError(t, mock.ExpectationsWereMet())
@@ -193,7 +192,7 @@ func TestReady_WhenNoRowsAffected_ShouldReturnLockError(t *testing.T) {
193192

194193
sut := NewOutboxWithDB(db)
195194

196-
err = sut.Ready(context.TODO(), "test-id", "", nil)
195+
err = sut.Ready(context.TODO(), "test-id")
197196

198197
assert.Error(t, err)
199198
assert.ErrorIs(t, err, ErrLockNotAcquired)

internal/pipeline/intake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (p *IntakePipeline) Process(ctx context.Context) {
4949
return
5050
}
5151

52-
if err := p.outbox.Ready(context.Background(), email.Id, ""); err != nil {
52+
if err := p.outbox.Ready(context.Background(), email.Id); err != nil {
5353
subLogger.Error(fmt.Sprintf("failed to update status to READY: %v", err))
5454
p.handle(context.Background(), subLogger, email.Id, outbox.StatusInvalid, err.Error())
5555
} else {

internal/pipeline/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import (
88
type outboxService interface {
99
Query(ctx context.Context, status string, limit int) ([]outbox.Email, error)
1010
Update(ctx context.Context, id string, status string, errorReason string) error
11-
Ready(ctx context.Context, id string, emlFilePath string) error
11+
Ready(ctx context.Context, id string) error
1212
Requeue(ctx context.Context, id string) error
1313
}

internal/testutils/mocks/outbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (m *OutboxMock) Update(ctx context.Context, id string, status string, error
8787
return nil
8888
}
8989

90-
func (m *OutboxMock) Ready(ctx context.Context, id string, emlFilePath string) error {
90+
func (m *OutboxMock) Ready(ctx context.Context, id string) error {
9191
m.lastMethod = "ready"
9292
m.updateMethodCall++
9393
if m.updateMethodCall == m.updateMethodFailsCall {

0 commit comments

Comments
 (0)