202508041737_postgres_amount_bigint.go raw

   1  package migrations
   2  
   3  import (
   4  	_ "embed"
   5  
   6  	"github.com/go-gormigrate/gormigrate/v2"
   7  	"gorm.io/gorm"
   8  )
   9  
  10  // NOTE: This was actually 2025-07-08
  11  var _202508041737_postgres_amount_bigint = &gormigrate.Migration{
  12  	ID: "202508041737_postgres_amount_bigint",
  13  	Migrate: func(db *gorm.DB) error {
  14  
  15  		// sqlite works fine but postgres integers are only 4 bytes
  16  		// amounts are in msats (= max ~2.1M sats)
  17  		if db.Dialector.Name() != "postgres" {
  18  			return nil
  19  		}
  20  
  21  		if err := db.Exec(`ALTER TABLE transactions
  22  ALTER COLUMN amount_msat TYPE bigint;`).Error; err != nil {
  23  			return err
  24  		}
  25  
  26  		return nil
  27  	},
  28  	Rollback: func(tx *gorm.DB) error {
  29  		return nil
  30  	},
  31  }
  32