Skip to content

Commit 985eabf

Browse files
authored
fix: ensure to run golangci-linter for eventstore/postgres (#60)
* fix: make sure linter runs for eventstore/postgres * fix: linter complaints * chore: update github actions to run on postgres
1 parent 548010a commit 985eabf

6 files changed

Lines changed: 23 additions & 9 deletions

File tree

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ jobs:
6161
uses: golangci/golangci-lint-action@v2
6262
with:
6363
version: latest
64+
- name: Run golangci-lint (postgres)
65+
uses: golangci/golangci-lint-action@v2
66+
with:
67+
version: latest
68+
working-directory: ./eventstore/postgres
69+
args: -c ../../.golangci.yml

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ run:
33
skip-dirs:
44
- .github
55
- resources
6+
- migrations # NOTE: this is relative to eventstore/postgres
67

78
linters-settings:
89
dupl:

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
PKG = github.com/get-eventually/go-eventually
21
GO_TEST_FLAGS := -race -v
2+
GOLANGCI_YML ?= $(shell find ~+ -name .golangci.yml)
3+
4+
.PHONY: run-linter
5+
run-linter:
6+
@find . -name "go.mod" | sed "s/\/go.mod//g" | xargs -I % bash -c 'echo -e "Checking: %"; cd %; golangci-lint run -c $(GOLANGCI_YML)'
37

48
.PHONY: postgres-tests
59
postgres-tests:

eventstore/postgres/migration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/get-eventually/go-eventually/eventstore/postgres/migrations"
1212
)
1313

14-
// RunMigration performs the migrations for the Postgres database.
14+
// RunMigrations performs the migrations for the Postgres database.
1515
func RunMigrations(dsn string) error {
1616
u, err := url.Parse(dsn)
1717
if err != nil {

eventstore/postgres/store.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"encoding/json"
77
"fmt"
88

9+
// Postgres driver for migrate.
10+
_ "github.com/golang-migrate/migrate/database/postgres"
11+
"github.com/lib/pq"
12+
913
"github.com/get-eventually/go-eventually"
1014
"github.com/get-eventually/go-eventually/eventstore"
1115
"github.com/get-eventually/go-eventually/eventstore/stream"
12-
"github.com/lib/pq"
13-
14-
_ "github.com/golang-migrate/migrate/database/postgres" // postgres driver for migrate
1516
)
1617

1718
var (
@@ -26,6 +27,7 @@ type EventStore struct {
2627
registry eventstore.Registry
2728
}
2829

30+
// NewEventStore creates a new EventStore using the database connection pool provided.
2931
func NewEventStore(db *sql.DB) EventStore {
3032
return EventStore{
3133
db: db,
@@ -59,28 +61,28 @@ func (st EventStore) Stream(
5961

6062
switch t := target.(type) {
6163
case stream.All:
64+
args = append(args, selectt.From)
6265
query = `SELECT * FROM events
6366
WHERE global_sequence_number >= $1
6467
ORDER BY global_sequence_number ASC`
65-
args = append(args, selectt.From)
6668

6769
case stream.ByType:
70+
args = append(args, selectt.From, string(t))
6871
query = `SELECT * FROM events
6972
WHERE global_sequence_number >= $1 AND stream_type = $2
7073
ORDER BY global_sequence_number ASC`
71-
args = append(args, selectt.From, string(t))
7274

7375
case stream.ByTypes:
76+
args = append(args, selectt.From, pq.Array(t))
7477
query = `SELECT * FROM events
7578
WHERE global_sequence_number >= $1 AND stream_type = ANY($2)
7679
ORDER BY global_sequence_number ASC`
77-
args = append(args, selectt.From, pq.Array(t))
7880

7981
case stream.ByID:
82+
args = append(args, selectt.From, t.Type, t.Name)
8083
query = `SELECT * FROM events
8184
WHERE "version" >= $1 AND stream_type = $2 AND stream_id = $3
8285
ORDER BY "version" ASC`
83-
args = append(args, selectt.From, t.Type, t.Name)
8486

8587
default:
8688
return fmt.Errorf("postgres.EventStore: unsupported stream target: %T", t)

eventstore/postgres/store_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func TestLatestSequenceNumber(t *testing.T) {
9797
}
9898

9999
ch := make(chan eventstore.Event, 1)
100+
100101
go func() {
101102
require.NoError(t, store.Stream(ctx, ch, stream.All{}, eventstore.SelectFromBeginning))
102103
}()

0 commit comments

Comments
 (0)