Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions comms/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ FROM golang:alpine AS builder
ENV GO111MODULE=on
ENV CGO_ENABLED=0

RUN go install github.com/amacneil/dbmate@latest

WORKDIR /app

COPY go.mod go.sum ./
Expand All @@ -19,7 +17,6 @@ FROM alpine AS final

COPY --from=builder /go/bin/* /bin
COPY --from=builder /app/comms /bin/comms
COPY --from=builder /app/discovery/db/migrations /discovery/db/migrations

EXPOSE 4222
VOLUME ["/tmp"]
Expand Down
2 changes: 0 additions & 2 deletions comms/DockerfileFast
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ENV GOARCH=${GOARCH}
ENV GO111MODULE=on
ENV CGO_ENABLED=0

RUN go install github.com/amacneil/dbmate@latest

WORKDIR /app

Expand All @@ -28,7 +27,6 @@ FROM alpine AS final

COPY --from=builder /go/bin/* /bin

COPY ./discovery/db/migrations /discovery/db/migrations
COPY ./build/comms-amd64 /bin/comms

VOLUME ["/tmp"]
Expand Down
21 changes: 12 additions & 9 deletions comms/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT_HASH ?= $(shell git rev-parse --verify HEAD)

up:: down migrate
up:: down
audius-compose up --comms comms-test

down::
Expand All @@ -15,11 +15,17 @@ fmt::
test::
docker logs -f comms-test

migrate::
audius-compose up db && \
DATABASE_URL="postgresql://postgres:postgres@localhost:5454/audius_discovery?sslmode=disable" \
dbmate --wait --no-dump-schema --migrations-dir ./discovery/db/migrations up
(docker exec -it audius-protocol-db-1 psql -U postgres -c "create database comms_test WITH TEMPLATE audius_discovery" || true)


steve.test::
docker compose -f docker-compose.test.yml up -d

audius_db_url="postgresql://postgres:password@localhost:25432/postgres?sslmode=disable" \
go run main.go discovery-migrations

audius_delegate_private_key="c82ad757622db5a148089e0a8fc1741cefa8677ab56a2ac9e38dac905c5ad7c7" \
audius_db_url="postgresql://postgres:password@localhost:25432/postgres?sslmode=disable" \
go test ./... -count=1


# formerly build.fast but uses qemu - slow
Expand All @@ -36,9 +42,6 @@ build.push.fast::
docker push audius/comms:a1
docker push audius/comms:${GIT_HASH}

tools::
CGO_ENABLED=0 go install github.com/amacneil/dbmate@latest
go install github.com/rakyll/hey@latest

quicktype::
cp ../libs/src/sdk/api/chats/serverTypes.ts discovery/schema/schema.ts
Expand Down
9 changes: 0 additions & 9 deletions comms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ You need:
Verify setup:

* Ensure you have `~/go/bin` in your path
* Run `make tools`
* verify `dbmate -h` works

### Run + test

Expand All @@ -24,13 +22,6 @@ Verify setup:

Re-run make after code changes

### Migrations

Use [dbmate](https://github.com/amacneil/dbmate):

* `cd discovery && dbmate new create_cool_table`
* edit migration file
* running `make` will run migration

### Typings

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

44 changes: 0 additions & 44 deletions comms/discovery/db/migrations/20221202144236_create_chat.sql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions comms/discovery/db/migrations/20230224160015_chat_indexes.sql

This file was deleted.

8 changes: 0 additions & 8 deletions comms/discovery/db/migrations/20230316193251_pubkey_table.sql

This file was deleted.

17 changes: 0 additions & 17 deletions comms/discovery/db/migrations/20230328011841_rpc_relayed_by.sql

This file was deleted.

13 changes: 0 additions & 13 deletions comms/discovery/db/migrations/20230328185322_rpc_applied_at.sql

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions comms/discovery/db/migrations/20230329192212_rpc_cursor.sql

This file was deleted.

8 changes: 0 additions & 8 deletions comms/discovery/db/migrations/20230605185932_chat_ban.sql

This file was deleted.

18 changes: 12 additions & 6 deletions comms/discovery/db/run_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ package db

import (
"fmt"
"os"
"os/exec"
)

func RunMigrations() error {
out, err := exec.Command("dbmate",
"--no-dump-schema",
"--migrations-dir", "./discovery/db/migrations",
"--url", MustGetAudiusDbUrl(),
"up").CombinedOutput()
fmt.Println("dbmate: ", string(out))
cmd := exec.Command("sh", "pg_migrate.sh")

// n.b. this won't work in docker-land
cmd.Dir = "../discovery-provider/ddl"

cmd.Env = append(os.Environ(),
"DB_URL="+MustGetAudiusDbUrl(),
)

out, err := cmd.CombinedOutput()
fmt.Println("pg_migrate.sh: ", string(out))
return err
}
7 changes: 0 additions & 7 deletions comms/discovery/discovery_main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package discovery

import (
"log"
"os"
"strings"

Expand Down Expand Up @@ -85,12 +84,6 @@ func DiscoveryMain() {
return nil

})
g.Go(func() error {
return db.RunMigrations()
})
if err := g.Wait(); err != nil {
log.Fatal(err)
}

// Start server
port := os.Getenv("PORT")
Expand Down
4 changes: 2 additions & 2 deletions comms/discovery/rpcz/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (proc *RPCProcessor) Apply(rpcLog *schema.RpcLog) error {
if err != nil {
return err
}
err = chatSetPermissions(tx, userId, params.Permit)
err = chatSetPermissions(tx, userId, params.Permit, messageTs)
if err != nil {
return err
}
Expand Down Expand Up @@ -300,7 +300,7 @@ func (proc *RPCProcessor) Apply(rpcLog *schema.RpcLog) error {
if err != nil {
return err
}
err = chatUnblock(tx, userId, int32(unblockedUserId))
err = chatUnblock(tx, userId, int32(unblockedUserId), messageTs)
if err != nil {
return err
}
Expand Down
Loading