Skip to content

Commit

Permalink
Replace snapshot status started -> in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
eminano committed Oct 15, 2024
1 parent 6ce4b6e commit 8849ad3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type Snapshot struct {
type Status string

const (
StatusRequested = Status("requested")
StatusStarted = Status("started")
StatusCompleted = Status("completed")
StatusRequested = Status("requested")
StatusInProgress = Status("in progress")
StatusCompleted = Status("completed")
)

func (s *Snapshot) IsValid() bool {
Expand All @@ -27,6 +27,6 @@ func (s *Snapshot) MarkCompleted(err error) {
s.Error = err
}

func (s *Snapshot) MarkStarted() {
s.Status = StatusStarted
func (s *Snapshot) MarkInProgress() {
s.Status = StatusInProgress
}
2 changes: 1 addition & 1 deletion pkg/snapshot/store/postgres/pg_snapshot_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *Store) createTable(ctx context.Context) error {
identity_column_names TEXT[],
created_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE,
status TEXT CHECK (status IN ('requested', 'started', 'completed')),
status TEXT CHECK (status IN ('requested', 'in progress', 'completed')),
error TEXT )`, snapshotsTable())
_, err := s.conn.Exec(ctx, createQuery)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions pkg/snapshot/store/postgres/pg_snapshot_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestStore_UpdateSnapshotRequest(t *testing.T) {
SchemaName: "test-schema",
TableName: "test-table",
IdentityColumnNames: []string{"id"},
Status: snapshot.StatusStarted,
Status: snapshot.StatusInProgress,
}

errTest := errors.New("oh noes")
Expand All @@ -98,7 +98,7 @@ func TestStore_UpdateSnapshotRequest(t *testing.T) {
ExecFn: func(ctx context.Context, _ uint, s string, a ...any) (postgres.CommandTag, error) {
wantQuery := fmt.Sprintf(`UPDATE %s SET status = '%s', error = '%s', updated_at = 'now()'
WHERE schema_name = '%s' and table_name = '%s' and status != 'completed'`,
snapshotsTable(), snapshot.StatusStarted, "", testSnapshot.SchemaName, testSnapshot.TableName)
snapshotsTable(), snapshot.StatusInProgress, "", testSnapshot.SchemaName, testSnapshot.TableName)
require.Equal(t, wantQuery, s)
require.Empty(t, a)
return postgres.CommandTag{}, nil
Expand All @@ -114,7 +114,7 @@ func TestStore_UpdateSnapshotRequest(t *testing.T) {
ExecFn: func(ctx context.Context, _ uint, s string, a ...any) (postgres.CommandTag, error) {
wantQuery := fmt.Sprintf(`UPDATE %s SET status = '%s', error = '%s', updated_at = 'now()'
WHERE schema_name = '%s' and table_name = '%s' and status != 'completed'`,
snapshotsTable(), snapshot.StatusStarted, errTest.Error(), testSnapshot.SchemaName, testSnapshot.TableName)
snapshotsTable(), snapshot.StatusInProgress, errTest.Error(), testSnapshot.SchemaName, testSnapshot.TableName)
require.Equal(t, wantQuery, s)
require.Empty(t, a)
return postgres.CommandTag{}, nil
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestStore_GetSnapshotRequests(t *testing.T) {
SchemaName: "test-schema",
TableName: "test-table",
IdentityColumnNames: []string{"id"},
Status: snapshot.StatusStarted,
Status: snapshot.StatusInProgress,
}

errTest := errors.New("oh noes")
Expand All @@ -179,7 +179,7 @@ func TestStore_GetSnapshotRequests(t *testing.T) {
querier: &postgresmocks.Querier{
QueryFn: func(ctx context.Context, query string, args ...any) (postgres.Rows, error) {
wantQuery := fmt.Sprintf(`SELECT schema_name,table_name,identity_column_names,status FROM %s
WHERE status = '%s' ORDER BY req_id ASC LIMIT %d`, snapshotsTable(), snapshot.StatusStarted, queryLimit)
WHERE status = '%s' ORDER BY req_id ASC LIMIT %d`, snapshotsTable(), snapshot.StatusInProgress, queryLimit)
require.Equal(t, wantQuery, query)
return &postgresmocks.Rows{
CloseFn: func() {},
Expand All @@ -196,7 +196,7 @@ func TestStore_GetSnapshotRequests(t *testing.T) {
querier: &postgresmocks.Querier{
QueryFn: func(ctx context.Context, query string, args ...any) (postgres.Rows, error) {
wantQuery := fmt.Sprintf(`SELECT schema_name,table_name,identity_column_names,status FROM %s
WHERE status = '%s' ORDER BY req_id ASC LIMIT %d`, snapshotsTable(), snapshot.StatusStarted, queryLimit)
WHERE status = '%s' ORDER BY req_id ASC LIMIT %d`, snapshotsTable(), snapshot.StatusInProgress, queryLimit)
require.Equal(t, wantQuery, query)
return &postgresmocks.Rows{
CloseFn: func() {},
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestStore_GetSnapshotRequests(t *testing.T) {
querier: &postgresmocks.Querier{
QueryFn: func(ctx context.Context, query string, args ...any) (postgres.Rows, error) {
wantQuery := fmt.Sprintf(`SELECT schema_name,table_name,identity_column_names,status FROM %s
WHERE status = '%s' ORDER BY req_id ASC LIMIT %d`, snapshotsTable(), snapshot.StatusStarted, queryLimit)
WHERE status = '%s' ORDER BY req_id ASC LIMIT %d`, snapshotsTable(), snapshot.StatusInProgress, queryLimit)
require.Equal(t, wantQuery, query)
return &postgresmocks.Rows{
CloseFn: func() {},
Expand All @@ -270,7 +270,7 @@ func TestStore_GetSnapshotRequests(t *testing.T) {
store := &Store{
conn: tc.querier,
}
snapshots, err := store.GetSnapshotRequests(context.Background(), snapshot.StatusStarted)
snapshots, err := store.GetSnapshotRequests(context.Background(), snapshot.StatusInProgress)
require.ErrorIs(t, err, tc.wantErr)
require.Equal(t, tc.wantSnapshots, snapshots)
})
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestStore_createTable(t *testing.T) {
identity_column_names TEXT[],
created_at TIMESTAMP WITH TIME ZONE,
updated_at TIMESTAMP WITH TIME ZONE,
status TEXT CHECK (status IN ('requested', 'started', 'completed')),
status TEXT CHECK (status IN ('requested', 'in progress', 'completed')),
error TEXT )`, snapshotsTable())
require.Equal(t, wantQuery, s)
require.Empty(t, a)
Expand Down

0 comments on commit 8849ad3

Please sign in to comment.