Skip to content

Commit

Permalink
feat(node): add run migrations to node startup
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Jul 11, 2024
1 parent 66ed1db commit aa762a3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/cartesi-rollups-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
Expand All @@ -13,6 +14,9 @@ import (

"github.com/cartesi/rollups-node/internal/node"
"github.com/cartesi/rollups-node/internal/node/config"
. "github.com/cartesi/rollups-node/internal/node/model"
"github.com/cartesi/rollups-node/internal/repository"
"github.com/ethereum/go-ethereum/common"
"github.com/lmittmann/tint"
"github.com/mattn/go-isatty"
)
Expand Down Expand Up @@ -43,6 +47,26 @@ func main() {
slog.SetDefault(logger)
slog.Info("Starting the Cartesi Rollups Node", "version", buildVersion, "config", config)

// setup database
nodePersistentConfig := NodePersistentConfig{
DefaultBlock: DefaultBlockStatusFinalized,
InputBoxDeploymentBlock: uint64(config.ContractsInputBoxDeploymentBlockNumber),
InputBoxAddress: common.HexToAddress(config.ContractsInputBoxAddress),
ChainId: config.BlockchainID,
IConsensusAddress: common.HexToAddress(config.ContractsIConsensusAddress),
}

repository.RunMigrations(fmt.Sprintf("%v?sslmode=disable", config.PostgresEndpoint.Value))
database, err := repository.Connect(ctx, config.PostgresEndpoint.Value)
if err != nil {
slog.Error("Node couldn't connect to the database", "error", err)
}
err = database.InsertNodeConfig(ctx, &nodePersistentConfig)
if err != nil {
slog.Error("Node couldn't insert database config", "error", err)
}
database.Close()

// create the node supervisor
supervisor, err := node.Setup(ctx, config, "")
if err != nil {
Expand Down

0 comments on commit aa762a3

Please sign in to comment.