Skip to content

seabed-labs/drip-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drip-backend

Maintainability Test Coverage CI

Devnet Mainnet
Staging n/a n/a
Production Better Uptime Badge Better Uptime Badge

Deploy Process

Devnet Mainnet
Staging Merge to main n/a
Production Via Infra GH Action Via Infra GH Action

Setup

  • 1 setup git hooks
  • 2 install go 1.18
  • 3 install docker and docker-compose
  • 4 setup a .env file
  • 5 install golangci-lint

Start the Server

  • 6 start the database
  • 7 start the api and event server
    • This also runs db migrations

Tests

  • 8 run all tests
  • 9 If an interface is changed, the associated mocks need to be re-generated

API Docs

  • 10 if the api docs are updated, we need to update the api codegen'd files
  • API docs are viewable at http://localhost:8080/swagger.json.

Database

  • 6 spin up a local database via docker
  • 11 stop the local docker database

NOTE: TODO(mocha) do codegen in a dockerized db that is setup and destroyed automatically in the script.

Migrations

  • located in internal/database/psql/migrations
  • all migrations that are a number larger than what the db version is will be run automatically on startup or during codegen
  • 12 running the migrations will automatically increment the schema version in the db

NOTE: The 6database must be running prior to running this script.

Codegen

  • Database models are generated using the database schema via go-gorm/gen
  • Before generating the models, the 6database needs to be running
  • The 10codegen script will also run migrations if new migrations are detected
go run cmd/codegen/main.go

NOTE: The 6database must be running prior to running this script.

Process for Creating/Updating Database Models

  • create a migration file under internal/database/psql/migrations, and name it appropriately (ex. 2_new_migration.up.sql)
  • 10 Run the migration + codegen script

NOTE: The 6database must be running prior to running this script.

Manually backfill the DB with known data/addresses

  • 13 Backfilling is done via the backfill script
  • View the code to see how it is done

Footnotes

  1. Register git hooks git config --local core.hooksPath .githooks/

  2. Install go brew formula Verify with go version

  3. Install Docker/Docker-compose Docs

  4. Example .env

    
    # Devnet Staging
    ENV="STAGING"
    NETWORK="DEVNET"
    DRIP_PROGRAM_ID="F1NyoZsUhJzcpGyoEqpDNbUMKVvCnSXcCki1nN3ycAeo"
    # random wallet, this is the mint auth
    DRIP_BACKEND_WALLET="[141,241,173,131,255,186,170,216,65,246,24,196,173,94,39,225,161,108,251,102,177,20,166,223,13,69,103,38,242,107,72,194,177,170,44,204,179,183,235,4,231,51,88,169,156,153,132,247,235,166,41,123,87,219,139,204,95,1,176,98,72,90,51,82]"
    
    # Only for local testing, this is false on all deployed env's
    SHOULD_BYPASS_ADMIN_AUTH=true 
    
    # Test Channel
    DISCORD_WEBHOOK_ID=1021592812954857492
    DISCORD_ACCESS_TOKEN=qPeOyI4e4k6kYah44k9_PXFQDsuLO7lbHcazLrsKcvzqvrQh_lr1PK21kB3GZCSTv2Xg
    
    PORT="8080"
    PSQL_USER="dcaf"
    PSQL_PASS="drip"
    PSQL_DBNAME="drip"
    PSQL_PORT="5432"
    PSQL_HOST="localhost"
    PSQL_SSLMODE=disable
    OUTPUT=./internal/pkg/repository/models
    GOOGLE_KEY=""
    GOOGLE_SECRET=""
    
  5. Install golangci-lint for your operating system https://golangci-lint.run/usage/install

  6. Start the database via docker-compose docker-compose --file ./build/docker-compose.yaml --env-file ./.env up 2 3 4 5 6

  7. Start the api-server and event server go run main.go

  8. Run unit and integration tests go test ./... If you need to run just unit tests go test ./... -short To force the unit test to not use the embedded DB, set the following in .env SHOULD_USE_EMBEDDED_DB=false

  9. Update mock files ./scripts/create-mocks.sh

  10. Run migrations and codegen db models go run cmd/codegen/main.go 2 3

  11. Stop the database via docker-compose docker-compose --file ./build/docker-compose.yaml --env-file ./.env down

  12. Just run db migrations go run cmd/migrate/main.go

  13. Run the backfill data script go run cmd/backfill/main.go