Skip to content

Commit

Permalink
fix migrations, sqls, dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
napalmpapalam committed Nov 24, 2023
1 parent a0ed7ec commit e111245
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM golang:1.20-alpine as buildbase

WORKDIR /go/src/github.com/rarimo/bdjuno
RUN apk add build-base
COPY vendor .
COPY . .
ENV GO111MODULE="on"
ENV CGO_ENABLED=1
Expand Down
14 changes: 8 additions & 6 deletions database/rarimocore.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,16 @@ func (db *Db) SaveConfirmations(confirmations []types.Confirmation) (err error)
var confirmationsParams []interface{}

for i, confirmation := range confirmations {
vi := i * 4
confirmationsQuery += fmt.Sprintf("($%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4)
vi := i * 6
confirmationsQuery += fmt.Sprintf("($%d, $%d, $%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4, vi+5, vi+6)

confirmationsParams = append(confirmationsParams,
confirmation.Root,
pq.StringArray(confirmation.Indexes),
confirmation.SignatureECDSA,
confirmation.Creator,
confirmation.Tx,
confirmation.Height,
)
}

Expand All @@ -500,13 +502,13 @@ func (db *Db) SaveRarimoCoreVotes(votes []types.RarimoCoreVote) (err error) {
return nil
}

query := `INSERT INTO vote (operation, validator, vote) VALUES `
query := `INSERT INTO vote (operation, validator, vote, tx, height) VALUES `
var queryParams []interface{}

for i, vote := range votes {
vi := i * 3
query += fmt.Sprintf("($%d, $%d, $%d),", vi+1, vi+2, vi+3)
queryParams = append(queryParams, vote.Operation, vote.Validator, vote.Vote)
vi := i * 5
query += fmt.Sprintf("($%d, $%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4, vi+5)
queryParams = append(queryParams, vote.Operation, vote.Validator, vote.Vote, vote.Tx, vote.Height)
}

query = strings.TrimSuffix(query, ",") // Remove trailing ","
Expand Down
4 changes: 2 additions & 2 deletions database/schema/12-tokenmanager.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- +migrate Up
CREATE TABLE networks
CREATE TABLE network
(
name TEXT NOT NULL PRIMARY KEY,
type INT NOT NULL,
Expand Down Expand Up @@ -49,4 +49,4 @@ DROP TABLE on_chain_item;
DROP TABLE item;
DROP TABLE collection_data;
DROP TABLE collection;
DROP TABLE networks;
DROP TABLE network;
10 changes: 8 additions & 2 deletions database/tokenmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (db *Db) SaveNetworks(networks []types.Network) (err error) {
return nil
}

stmt := `INSERT INTO networks (name, type, params) VALUES`
stmt := `INSERT INTO network (name, type, params) VALUES`
var params []interface{}

for i, network := range networks {
Expand All @@ -38,8 +38,14 @@ func (db *Db) SaveNetworks(networks []types.Network) (err error) {
stmt = strings.TrimSuffix(stmt, ",") // Remove trailing ","
stmt += ` ON CONFLICT (name) DO UPDATE
SET params = excluded.params
WHERE networks.name = excluded.name
WHERE network.name = excluded.name
`

_, err = db.SQL.Exec(stmt, params...)
if err != nil {
return fmt.Errorf("error while storing networks: %s", err)
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
table:
name: networks
name: network
schema: public
select_permissions:
- permission:
Expand Down
2 changes: 1 addition & 1 deletion hasura/metadata/databases/bdjuno/tables/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
- "!include public_collection_data.yaml"
- "!include public_on_chain_item.yaml"
- "!include public_seed.yaml"
- "!include public_networks.yaml"
- "!include public_network.yaml"
- "!include public_vote.yaml"
- "!include public_violation_report.yaml"
- "!include public_oraclemanager_params.yaml"
Expand Down

0 comments on commit e111245

Please sign in to comment.